PHP - Function Not Working At Right Position
Hi,
I have 2 pages, config.php and category.php config.php is Code: [Select] class CategoryWork { public $form = ""; public $error = ""; public $add_form = "<br /><p><strong>Add New Category</strong></p><form id=\"form1\" name=\"form1\" method=\"post\" action=\"category.php?action=add\"> <table width=\"550\" height=\"170\" border=\"0\"> <tr> <td width=\"153\">Name :</td> <td colspan=\"2\"><label for=\"cat_name\"></label> <input name=\"cat_name\" type=\"text\" id=\"cat_name\" size=\"50\" maxlength=\"50\" /></td> </tr> <tr> <td>Slug :</td> <td colspan=\"2\"><label for=\"cat_slug\"></label> <input name=\"cat_slug\" type=\"text\" id=\"cat_slug\" size=\"50\" maxlength=\"50\" /></td> </tr> <tr> <td>Description</td> <td colspan=\"2\"><label for=\"cat_desc\"></label> <textarea name=\"cat_desc\" id=\"cat_desc\" cols=\"48\" rows=\"10\"></textarea></td> </tr> <tr> <td> </td> <td width=\"97\"><input type=\"submit\" name=\"button\" id=\"button\" value=\"Submit\" /></td> <td width=\"286\"><input type=\"reset\" name=\"button2\" id=\"button2\" value=\"Reset\" /></td> </tr> <tr> <td> </td> <td colspan=\"2\"></td> </tr> </table> </form>"; public $edit_form1_first = "<br /><p><strong>Edit Category</strong></p><form id=\"form1\" name=\"form1\" method=\"post\" action=\"category.php?action=edit\"> <table width=\"454\" height=\"79\" border=\"0\"> <tr> <td width=\"110\">Category :</td> <td width=\"334\"><label for=\"select\"></label> <select name=\"select_cat\" id=\"select\">"; public $edit_form1_last = "</select> </td> </tr> <tr> <td> </td> <td><input type=\"submit\" name=\"button\" id=\"button\" value=\"Submit\" /></td> </tr> </table> </form>"; public $invalid_get_error = "<br /><br /><p><font color=\"#990000\"><strong><em>ERROR : Invalid Option.</em></strong></font></p>"; public function CheckAction($action){ if(!isset($action)) { header("Location:dashboard.php"); } else { $action = $action; if($action == "add") { $this->form = NULL; $this->form = $this->add_form; } else if ($action == "edit") { $this->form = NULL; $this->form = $this->GenerateDropDown(); } else if ($action == "del") { $this->form = "del"; } else { $this->form = $this->invalid_get_error; } // if else .. else if ends here }// if else ends here } // Function CheckAction ends public function ValidateAddForm($name, $slug, $desc){ if(isset($name) || isset($slug) || isset($desc)) { if($name == NULL || $slug == NULL || $desc == NULL) { $this->error = "<br /><br /><p><font color=\"#990000\"><strong><em>ERROR : All 3 fields are required.</em></strong></font></p>"; } else { // Data Insert in database $name = $name; $slug = $slug; $desc = $desc; $check_category_query = "SELECT * FROM category where slug = '$slug'"; $check_category_result = mysql_query($check_category_query); $check_category_count = mysql_num_rows($check_category_result); if($check_category_count == 1) { $this->error = "<br /><br /><p><font color=\"#990000\"><strong><em>ERROR : Slug Already exists.</em></strong></font></p>"; } else if ($check_category_count == 0) { // Do insertion in database $categoryinsert_query = "INSERT INTO category (name, slug, description) VALUES ('$name', '$slug', '$desc')"; $categoryinsert_result = mysql_query($categoryinsert_query); $this->error = "<br /><br /><font color=\"#009900\"><p><em><strong>Success, Category added.</strong></em></p></font>"; } } } } // function ends here public function GenerateDropDown(){ $dropdown_query = "SELECT * FROM category ORDER BY name"; $dropdown_result = mysql_query($dropdown_query); echo $this->edit_form1_first; while($row = mysql_fetch_array($dropdown_result)) { echo "<option value=".$row['id'].">".$row['name']."</option>"; } echo $this->edit_form1_last; } // end of GenerateDropDown function } Here is the code of category.php page Code: [Select] <?php include('config.php'); $system = new SystemAdmin; $categorywork = new CategoryWork; $system->ValidateToken($_COOKIE['token']); $categorywork->CheckAction($_GET['action']); $categorywork->ValidateAddForm($_POST['cat_name'], $_POST['cat_slug'], $_POST['cat_desc']); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Welcome <?php echo $system->username; ?></title> <?php echo $system->metalines; ?> <?php echo $system->slug_javascript; ?> </head> <body> <h1>Welcome <?php echo $system->username; ?>,</h1> <?php echo $system->mainmenu; ?> <?php echo $system->spryfunctions; ?> <?php echo $categorywork->error; ?> <?php echo $categorywork->form; ?> </body> </html> Problem is that when I go to /category.php?action=edit, it shows dropdown at the top of page and not at the position of <?php echo $categorywork->form; ?> I have attached a screenshot, please go through it. How can I solve this ? Second problem is how can I hide undefined index notice ? Similar TutorialsHi all , in my scripts I have a drop list and its <option> values are retrieved from sql database , and once I choose any value from the drop list the value will shown in a textbox . It's functioning well in firefox and opera except IE , is there any way to solve this problem? Code: [Select] <html> <head> <title>Untitled</title> </head> <body> <form name="theform" onsubmit="CheckForm()"> <?php $query="SELECT DISTINCT Custgroup FROM UserAddedRecord"; $result = mysql_query ($query); ?> <select name="myOptions" onchange="document.theform.showValue.value=this.value" > <? while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option >$nt[Custgroup]</option>"; } ?> <input type="text" name="showValue"><br> </form> </body> </html> Thanks for every reply . I am trying to make a ban function and i have the users id being passed through the URL and i can't seem to get it working.
<?php require 'connect.php'; include 'header.php'; error_reporting(E_ALL | E_NOTICE); session_start(); $ban = "SELECT id FROM $tbl_name WHERE id={$_GET['id']} AND active='$active'"; $banres = $con->query($ban); $row = $con->fetch_assoc($banres); $active = $row['active']; if($banres) { $active_update = "UPDATE $tbl_name SET active=0"; } ?> hello. On my function page I have this function. function GetClub($clubs) { $qFindClub = "SELECT * FROM clubs WHERE memberID = '$clubs'"; $rFindClub = mysql_query($qFindClub); $Club = mysql_fetch_array($rFindClub); return $Club; } now when I feed it the variable $myID. If I try to echo say the club name $Clubs = GetClub($myID); echo $Clubs['name']; Nothing happens as its not working properly. Can anybody see what I have done wrong? I have this code on my user registration form Code: [Select] <?php $flg = ""; $error = ""; if (isset($HTTP_GET_VARS["flg"])) $flg = $HTTP_GET_VARS["flg"]; switch ($flg) { case "yellow": $error = "<br><font class=\"txt12_red\">That Email Address already exists in our Database.<br>Please Select Another.<BR></font>"; break; case "red": $error = "<br><font class=\"txt12_red\">Please fill out all the required fields.<br>Please Try Again.<BR></font>"; break; case "blue": $error = "<br><font class=\"txt12_red\">Your Session has Expired.<br>Please Login Again.</font><BR>"; break; case "pink": $error = "<br><font class=\"txt12_red\"><BR>The Special Code you entered is not valid.<br>Please Try Again or Leave that field blank. </font><BR>"; break; case "white": $error = "<br><font class=\"txt12_red\"><BR>The fields are too long for our Database.<br>Please correct your data via this form.</font> <BR>"; break; default: $error = ""; } ?> and the registered form / page I have this validation and function Code: [Select] <?php // check to see if these variables have been set... if ((!isset($_SESSION["fname"])) || (!isset($_SESSION["lname"])) || (!isset($_SESSION["email"])) || (!isset($_SESSION["phone"])) || (!isset($_SESSION["city"])) || (!isset($_SESSION["status"])) || (!isset($_SESSION["province"]))) { resendToForm("?flg=red"); } // form variables must have something in them... if ($_SESSION['fname'] == "" || $_SESSION['lname'] == "" || $_SESSION['email'] == "" || $_SESSION['phone'] == "" || $_SESSION['city'] == "" || $_SESSION['status'] == "" || $_SESSION['province'] == "") { resendToForm("?flg=red"); } // make sure fields are within the proper range... if (strlen($_SESSION['fname']) > 35 || strlen($_SESSION['lname']) > 35 || strlen($_SESSION['email']) > 35 || strlen($_SESSION['phone']) > 35 || strlen($_SESSION['city']) > 35 || strlen($_SESSION['status']) > 35 || strlen($_SESSION['province']) > 35 || strlen($_SESSION['password']) > 30) { resendToForm("?flg=white"); } function resendToForm($flags) { reset ($_POST); // store variables in session... while (list ($key, $val) = each ($_POST)) { $_SESSION[$key] = $val; } // go back to the form... //echo $flags; header("Location: ./registration_form.php".$flags); exit; } ?> The validation is working as it goes back to user registration form, the problem is it's not displaying the error on Code: [Select] <?php echo $error; ?> What seems to be the problem? anyone? I am still new to programming PHP and this is the first time I am creating a function. Here is where I pull the function (scroll down to commented area) <table width="250" border="0" cellpadding="2" cellspacing="0"> <tr> <td width="145"><strong>Province:</strong></td> <td colspan="2" align="right"><? echo $prov ?></td> </tr> <tr> <td><strong>Postal:</strong></td> <td colspan="2" align="right"><? echo $postal ?></td> </tr> <tr> <td><strong>Lbs:</strong></td> <td colspan="2" align="right"><? echo $lbs ?></td> </tr> <tr> <td colspan="3"> </td> </tr> </table> <img src="/images/carriers/canpar.png" border="0"/> <table width="250" border="0" cellpadding="2" cellspacing="0"> <?php if ($debugmode == 'on') { ?> <tr> <td><strong>Cost:</strong></td> <td width="14" align="right"><strong>$</strong></td> <td width="71" align="right"><? echo number_format($dzone, 2, '.', '') ?></td> </tr> <?php if ($cp_markup != "") { ?><tr> <td><strong>Markup:</strong></td> <td align="right"><strong>$</strong></td> <td align="right"><? echo number_format($cp_mark, 2, '.', '') ?></td> </tr><?php } ?> <? $price = ( number_format($cp_mark, 2, '.', '') +number_format($dzone, 2, '.', '') ); } Else { ?> <tr> <td><strong>Price:</strong></td> <td align="right"><strong>$</strong></td> <td align="right"><? $price = ( number_format($cp_mark, 2, '.', '') +number_format($dzone, 2, '.', '') ); echo number_format($price, 2, '.', ''); ?></td> </tr> <? } ?> <?php if ($cp_fuelcharge != "") { ?><tr> <td><strong>Fuel Charge:</strong></td> <td align="right"><strong>$</strong></td> <td align="right"><? echo number_format($cp_fuelcharge, 2, '.', '') ?></td> </tr><?php } ?> <?php taxcalc(); //Here is the function pull echo $taxrow; // this is supposed to be defined in the function ?> <tr> <td class="priceresults"><strong>Total:</strong></td> <td align="right"class="priceresults"><strong>$</strong></td> <td align="right"class="priceresults"><?php $total = ( number_format($price, 2, '.', '') + number_format($tax, 2, '.', '') ); echo number_format($total, 2, '.', ''); ?></td> </tr> </table> Here is my taxcalc() function: function taxcalc() { if ($prov == "AB") { $gst = '5%'; $gstcalc = '0.05'; $tax = $price * $gstcalc; $taxrow = "<tr><td>GST ($gst):</td><td align='right'><strong>$</strong></td><td>" . number_format($tax, 2, '.', '') . "</td></tr>"; } if ($prov == "BC") { $hst = '12%'; $hstcalc = '0.12'; $tax = $price * $hstcalc; $taxrow = "<tr><td>HST ($hst):</td><td align='right'><strong>$</strong></td><td>" . number_format($tax, 2, '.', '') . "</td></tr>"; } if ($prov == "MB") { $gst = '5%'; $pst = '7%'; $gstcalc = '0.05'; $pstcalc = '0.07'; $gtax = $price * $gstcalc; $ptax = $price * $pstcalc; $tax = $gtax + $ptax; $taxrow = "<tr><td>GST ($gst):</td><td align='right'><strong>$</strong></td><td>" . number_format($gtax, 2, '.', '') . "</td></tr><tr><td>PST ($pst):</td><td align='right'><strong>$</strong></td><td>" . number_format($ptax, 2, '.', '') . "</td></tr>"; } if ($prov == "ON") { $hst = '13%'; $hstcalc = '0.13'; $tax = $price * $hstcalc; $taxrow = "<tr><td>HST ($hst):</td><td align='right'><strong>$</strong></td><td>" . number_format($tax, 2, '.', '') . "</td></tr>"; } if ($prov == "NB") { $hst = '13%'; $hstcalc = '0.13'; $tax = $price * $hstcalc; $taxrow = "<tr><td>HST ($hst):</td><td align='right'><strong>$</strong></td><td>" . number_format($tax, 2, '.', '') . "</td></tr>"; } if ($prov == "NL") { $hst = '13%'; $hstcalc = '0.13'; $tax = $price * $hstcalc; $taxrow = "<tr><td>HST ($hst):</td><td align='right'><strong>$</strong></td><td>" . number_format($tax, 2, '.', '') . "</td></tr>"; } if ($prov == "NS") { $hst = '15%'; $hstcalc = '0.15'; $tax = $price * $hstcalc; $taxrow = "<tr><td>HST ($hst):</td><td align='right'><strong>$</strong></td><td>" . number_format($tax, 2, '.', '') . "</td></tr>"; } if ($prov == "NT") { $gst = '5%'; $gstcalc = '0.05'; $tax = $price * $gstcalc; $taxrow = "<tr><td>GST ($gst):</td><td align='right'><strong>$</strong></td><td>" . number_format($tax, 2, '.', '') . "</td></tr>"; } if ($prov == "NU") { $gst = '5%'; $gstcalc = '0.05'; $tax = $price * $gstcalc; $taxrow = "<tr><td>GST ($gst):</td><td align='right'><strong>$</strong></td><td>" . number_format($tax, 2, '.', '') . "</td></tr>"; } if ($prov == "PE") { $gst = '5%'; $pst = '10%'; $gstcalc = '0.05'; $pstcalc = '0.10'; $gtax = $price * $gstcalc; $ptax = $price * $pstcalc; $tax = $gtax + $ptax; $taxrow = "<tr><td>GST ($gst):</td><td align='right'><strong>$</strong></td><td>" . number_format($gtax, 2, '.', '') . "</td></tr><tr><td>PST ($pst):</td><td align='right'><strong>$</strong></td><td>" . number_format($ptax, 2, '.', '') . "</td></tr>"; } if ($prov == "QC") { $gst = '5%'; $pst = '7.5%'; $gstcalc = '0.05'; $pstcalc = '0.075'; $gtax = $price * $gstcalc; $ptax = ($price + $gtax) * $pstcalc; $tax = $gtax + $ptax; $taxrow = "<tr><td>GST ($gst):</td><td align='right'><strong>$</strong></td><td>" . number_format($gtax, 2, '.', '') . "</td></tr><tr><td>PST ($pst):</td><td align='right'><strong>$</strong></td><td>" . number_format($ptax, 2, '.', '') . "</td></tr>"; } if ($prov == "SK") { $gst = '5%'; $pst = '5%'; $gstcalc = '0.05'; $pstcalc = '0.05'; $gtax = $price * $gstcalc; $ptax = $price * $pstcalc; $tax = $gtax + $ptax; $taxrow = "<tr><td>GST ($gst):</td><td align='right'><strong>$</strong></td><td>" . number_format($gtax, 2, '.', '') . "</td></tr><tr><td>PST ($pst):</td><td align='right'><strong>$</strong></td><td>" . number_format($ptax, 2, '.', '') . "</td></tr>"; } if ($prov == "YT") { $gst = '5%'; $gstcalc = '0.05'; $tax = $price * $gstcalc; $taxrow = "<tr><td>GST ($gst):</td><td align='right'><strong>$</strong></td><td>" . number_format($tax, 2, '.', '') . "</td></tr>"; } } I am not getting any errors, just nothing is showing up. My results show up as: Code: [Select] Province: ON Postal: K2C Lbs: 25 Cost: $ 22.57 Markup: $ 0.00 Fuel Charge: $ 5.00 Total: $ 22.57 After Fuel Charge should be my taxes but they do not show up deleting works, but can't seem to get the add to work???? any ideas Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Search User</title> <link href="stylesheet1.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery-1.4.3.js"></script> <script type="text/javascript" src="jquery.json-2.2.js"></script> <style type="text/css"> body { font-size:12px; font-family:Arial, Helvetica, sans-serif; } form { display:block; width:260px; } form .input{ width:120px; float:right; } form label { display:block; width:260px; clear:both; } form textarea { display:block; width:260px; } </style> <script type="text/javascript"> // alert("document loaded 1"); // $(document).ready(function(){ //$("#projectid").html("1"); // alert("document loaded 1"); function userlistgenerate(){ var data = { "operation" : "userlist", "users": [ { "userid" : "usr_id"}, ] // end of sales array } //alert("geldi 2"); //var dataString = JSON.(data); var dataString = $.toJSON(data); //alert("geldi 3"); // alert(dataString); $.post('UserSearchPBT.php', { data: dataString}, userlistResult, "text"); $("#selectedUserName").html(""); // $("selectedUserName").hide("fast"); } function userlistResult(res) { var obj = $.evalJSON(res); //alert(obj.ResultData); //$("#sales1Lastname").html("Lastname of sales[1]: " +obj.sales[0].lastname); $("#userlist").html(obj.ResultData); $("#selectedUserName").html(""); //$("selectedUserName").hide("fast"); } function UserSearchChoose(userid,username ,name,surname,email,phone,mobphone,isactive){ $("#userid").val(userid); $("#username").val(username); $("#name").val(name); $("#surname").val(surname); $("#email").val(email); $("#phone").val(phone); $("#mobphone").val(mobphone); $("#isuseractive").val(isactive); $("#useradd").hide("fast"); } function usersearch() { $("#useradd").show(); var name=$("#name").attr("value"); var surname=$("#surname").attr("value"); var data = { "operation" : "usersearch", "user": [ { "name" : name, "surname" : surname } ] // end of sales array } var dataString = $.toJSON(data); $.post('UserSearchPBT.php', { data: dataString}, usersearchResult, "text"); } function usersearchResult(res) { var obj = $.evalJSON(res); $("#userlist").html(obj.ResultData); } function userdelete() { var useridval = $("#userid").attr("value"); alert (useridval); var data = { "operation" : "teamdelete", "userid" : useridval } var dataString = $.toJSON(data); $.post('UserSearchPBT.php', { data: dataString}, userdeleteResult, "text"); } function userdeleteResult(res) { var obj = $.evalJSON(res); $("#successfailmessage").html(obj.SuccFailMessage); userlistgenerate(); } function useradd() { //alert ("team add a geliyor"); var userId = $("#userid").attr("value"); var username = $("#username").attr("value"); var usersurname = $("#surname").attr("value"); var useremail = $("#useremail").attr("value"); var userphone = $("#userphone").attr("value"); var usermob = $("#usermob").attr("value"); var useractive = $("#useractive").attr("value"); // alert ("--".projectId."-".userId."-".rolId."--"); var data = { "operation" : "useradd", "userId" : userId, "username" : username, "useremail" : useremail, "userphone" : userphone, "usermob" : usermob, "useractive" : useractive, "recuser" : 1 } var dataString = $.toJSON(data); $.post('UserSearchPBT.php', { data: dataString}, userdeleteResult, "text"); alert ("user add a geliyor ajax bitti"); } </script> </head> <body> <form id="iletisim"> <div id="formdiv"> <table><tr> <td><span id="successfailmessage"></span></td> <tr><td><span id="userlist"></span> </td></tr> <tr><td><span id="selectedUserName"></span></td></tr> <tr><td><label for="name">User Name<input class="input" name="username" id="username" type="text" value="" /></label></td></tr> <tr><td><label for="name">Name<input class="input" name="name" id="name" type="text" value="" /></label></td></tr> <tr><td><label for="surname">Surname<input class="input" name="surname" id="surname" type="text" value="" /></label><tr> <tr><td><label for="email">Email<input class="input" name="email" id="email" type="text" value="" /></label><tr> <tr><td><label for="phone">Phone<input class="input" name="phone" id="phone" type="text" value="" /></label><tr> <tr><td><label for="phone">Mobile Phone<input class="input" name="mobphone" id="mobphone" type="text" value="" /></label><tr> <tr><td><label for="phone">Is User Active(Y/N)<input class="input" name="isuseractive" id="isuseractive" type="text" value="" /></label></td></tr> <tr><td><a href='#' onclick="javascript:usersearch();">Search User</a> </td></tr><tr> <tr><td><a href='#' id="useradd" onclick="javascript:useradd();">Add</a> </td></tr><tr> <tr><td><a href='#' id="userdelete" onclick="javascript:userdelete();">Delete</a> </td></tr><tr> <tr><td><a href='#' id="userupdate" onclick="javascript:userupdate();">Update</a> </td></tr><tr> </table> <input type="hidden" id = "userid" value="" name="userid" /> </div> </form> </body> </html> Code: [Select] This is the function I wrote function getParagraph($myfile) { while (!feof($myfile)){ $data = fgets($myfile); $paragraph = explode("\n", $data); } return $paragraph; } When I print the array, it's empty. while ($paragraph = getParagraph($file)){ print_r($paragraph); } Prints to my webpage as: Array ( => ) The file is NOT empty, and it is formated by line breaks so I don't know what's not working. Hello I have a general php insert function that I want to use to insert data into tables regulary, the problem is, each time I use it it creates a new row in the table instead of using certain columns to add information to, here is the function, can you tell me why does it insert a new row each time I use it?
class Query{ function add($table,$cols,$vals){ include 'conx.php'; $query = " INSERT INTO $table($cols) VALUES('$vals'); "; $res = mysqli_query($con,$query) ; if($res){ echo "Inserted value"; }else{ echo "Did not insert value"; } } } im trying to return the highest value in my table from the season_id column this is the code i have: Code: [Select] $test = mysql_query("SELECT * FROM `$show` WHERE [season_id]=(SELECT Max([season_id]) FROM `$show`)"); please advise? Whenever try to use the PHP mail function on my local server it also fails but then when I upload my scripts to my webspace they work fine. I think there must be something wrong with my php.ini file. Below I have copied the mail function section of my php.ini file. [mail function] ; For Win32 only. SMTP = localhost smtp_port = 25 ; For Win32 only. ;sendmail_from = me@example.com ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). sendmail_path = sendmail -t -i ; Force the addition of the specified parameters to be passed as extra parameters ; to the sendmail binary. These parameters will always replace the value of ; the 5th parameter to mail(), even in safe mode. ;mail.force_extra_parameters = Thanks for any help. I thought this was pretty straight forward, but it is not working. Titlecase is supposed to capitalize the first letter of every with except for certain words in $smallarr. Instead, it capitalizes every word. What's wrong here? //==================================================== function crTitlecase($s) /* Capitalize every word in a sentence except certain small words. */ { //Keep $smallarr in alpha order! //Do not capitalize these words. $smallarr=array('a','above','and','an','at','by','for','if'); $smallarr=array($smallarr,'into','is','it','of','off'); $smallarr=array($smallarr,'on','or','over','the','to'); $smallarr=array($smallarr,'with','without'); //$smallarr=($smallarr,); $t=strtolower($s); //First change all ltrs to lowercase. $words = explode(' ', $t); foreach ($words as $mykey => $word) { //if ((!$mykey) or (!in_array($word, $smallarr)) ) if ( (!in_array($word, $smallarr)) ) { $s='mykey='.$mykey.', word='.$words[$mykey]; crDebug($s); $words[$mykey] = ucwords($word); } } $newtitle = implode(' ', $words); return $newtitle; } I'm rewriting my aplication to work with mysqli and one function that I have created is not working anymore. I don't know why connection to db is not working anymore. It worked on mysql.
Can you see what is the problem?
function zamjena_broja($kataloski_broj){ global $conn_mysqli; $kataloski_broj_data = array(); //Traženje zamjenskog broja $upit_zamjena = "SELECT pocetni_broj, zamjenski_broj, glavni_broj FROM zamjene_brojeva WHERE glavni_broj = '$kataloski_broj' OR pocetni_broj = '$kataloski_broj'"; $rezultat_zamjena = mysqli_query($conn_mysqli, $upit_zamjena) or die (mysqli_error($conn_mysqli)); while($row = mysqli_fetch_array($rezultat_zamjena)){ $kataloski_broj_data[] = $row["zamjenski_broj"]; $kataloski_broj_data[] = $row["pocetni_broj"]; } $kataloski_broj = array_map("unserialize", array_unique(array_map("serialize", $kataloski_broj_data))); //var_dump($kataloski_broj); return $kataloski_broj; }My connection: <?php //Veza na bazu - mysqli protokol $DBServer = 'localhost'; // e.g 'localhost' or '192.168.1.100' $DBUser = 'xxxx'; $DBPass = 'xxxx'; $DBName = 'xxxdb'; $conn_mysqli = new mysqli($DBServer, $DBUser, $DBPass, $DBName); global $conn_mysqli; // check connection if ($conn_mysqli->connect_error) { trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR); } ?> Hello all, so I created an insert function and it seems no matter what I try that it won't add values using the query function inside a table from the respective variables, I would like to know why is this happening? Here is the code can you tell me why it doesn't insert anything in the database? It shows no errors when it runs but then again when I check the tables they're empty!
function insert(){ $user = $_POST['user']; $pass = md5($_POST['pass']); $priv = "User"; $mail = $_POST['mail']; $avatar = $_FILES['avatar']['name']; $date="now()"; $submit = $_POST['submit']; $query = "INSERT INTO user(user,pass,priv,mail,avatar,date) VALUES(`$user`,`$pass`,`$priv`,`$mail`,`$avatar`,`$date`);"; if($submit){ $res = mysqli_query($con,$query) or die(mysqli_error($con)); } } Here's the code with the function that won't work! Code: [Select] $itemsRaw = explode(" ", $player['inventory']); foreach ($itemsRaw as $inv){ $contents = explode("-", $inv); if(strlen($contents[0]) > 0 && strlen($contents[1]) > 0 && $contents[1] > 0) echo getItemName($contents[0]) . " (" . number_format($contents[1]) . ")<br />"; } Here's my function: Code: [Select] function getItemName($id_raw){ $id = $id_raw - 1; $q = $db->query("SELECT * FROM items WHERE id = $id") or die(mysql_error()); $f = $db->fetch_assoc($q); return $f['name']; } It stops the page when it gets to that point and won't load anything else and the function doesn't even work with it :/ What's wrong with it? If anything.. Hi, I'm making an RSS feed http://dev.subverb.net/mixes_rss.php and as you see the date('r', $row['date']) function is not converting it. I've echo'd $row['date'] into the description to show what format the date is in (just mysql datetime. Am I missing something? Thanks I have a class built for an INSERT query but it is passing two sets of records into the database rather than one. Code: [Select] class DatabaseInsert { function DatabaseConnectionRequire() { include("../scrips/php/database.connection.class.php"); include("../scrips/php/database.settings.php"); include("../scrips/php/database.connection.class.invoke.php"); } function ArticleInsert($values,$fields,$table) { $values_imploded = implode(" ",$values); $fields_imploded = implode(" ",$fields); $i = "INSERT INTO $table ($fields_imploded) VALUES ($values_imploded)"; mysql_query($i) or die(mysql_error()); if (!mysql_query($i)) { echo "Sorry, something whent wrong there..."; } else { echo "<strong><p style='color:green;'>Content added sucessfully!!!</p></strong>"; } } } Hello, The mail function works on my one website but it won't on my other site. On the site that it won't work on, I'm trying to email the contents of the cart. I tested it out and it diplays the contents of the cart properly if I echo $email. I don't get any errors on the site, it seems to process but I don't receive any emails. here is my code for process.php: Code: [Select] <?php session_start(); error_reporting(E_ALL); ini_set('display_errors','1'); require_once("connect.php"); ?> <?php $check=$_POST['check']; /* code that outputs the cart contents and totals up the cart */ $cartOutput=""; $total="0"; // start the foreach loop to go through each item in the cart array $i=0; foreach($_SESSION["cart_array"] as $each_item) { $item_id=$each_item['id']; $prod_id=$each_item['product_id']; // distiguish between a regular item and a gift box switch ($prod_id) { // if it is a gift box case "12": // Get product name and price $sql=mysql_query("SELECT products.productPrice, products.productName FROM products WHERE productId='$prod_id' LIMIT 1"); while ($row=mysql_fetch_array($sql)) { $product_name=$row["productName"]; $price=$row["productPrice"]; } $subtotal=$price*$each_item['quantity']; $total=$subtotal + $total; if(isset ($_SESSION["cart_array"] )) { // dynamic checkout button assembly // dynamic cart item display $cartOutput.="<tr align=center> <td width=5%><font face=arial color='#999999'>".substr($each_item['id'],0,7)."</font></td> <td width=25%><font face=arial color='#999999'>".$product_name."</font></td> <td width=40% valign=center><font face=arial color='#999999'>Wrap my products in a Gift Box</font></td> <td valign=center width=5%><font face=arial color='#999999'>".$each_item['quantity']." </td> <td width=5%><font color='#999999'>$".$price.".00</font></td> <td width=10%><font color='#999999'>$".$subtotal.".00</font></td> </tr> <tr> <td colspan=6><hr size=1 width=50% color='#CBB659'/></td></tr>"; } // end if statement to see if cart is empty break; // if it is a Reed Diffuser Bottle case "17": // Get product name and price $sql=mysql_query("SELECT products.productPrice, products.productName, products.productDesc FROM products WHERE productId='$prod_id' LIMIT 1"); while ($row=mysql_fetch_array($sql)) { $product_name=$row["productName"]; $price=$row["productPrice"]; $desc=$row['productDesc']; } $subtotal=$price*$each_item['quantity']; $total=$subtotal + $total; if(isset ($_SESSION["cart_array"] )) { // dynamic checkout button assembly // dynamic cart item display $cartOutput.="<tr align=center> <td width=5%><font face=arial color='#999999'>".substr($each_item['id'],0,7)."</font></td> <td width=25%><font face=arial color='#999999'>".$product_name."</font></td> <td width=40% valign=center><font face=arial color='#999999'>".$desc."</font></td> <td valign=center width=5%><font face=arial color='#999999'>".$each_item['quantity']."</td> <td width=5%><font face=arial color='#999999'>$".$price.".00</font></td> <td width=10%><font face=arial color='#999999'>$".$subtotal.".00</font></td> </tr> <tr> <td colspan=6><hr size=1 width=50% color='#CBB659'/></td></tr>"; } // end if statement to see if cart is empty break; // if it is a salve case "3": $salveId=substr($each_item['id'],2,4); $prodId=substr($each_item['id'],0,1); // Get product name and price $sql=mysql_query("SELECT * FROM salves WHERE productId='$salveId' LIMIT 1"); while ($row=mysql_fetch_array($sql)) { $scent=$row['productName']; } $sql=mysql_query("SELECT * FROM products WHERE productId='$prodId' LIMIT 1"); while ($row=mysql_fetch_array($sql)) { $price=$row['productPrice']; $product_name=$row['productName']; } if(isset ($_SESSION["cart_array"] )) { $subtotal=$price*$each_item['quantity']; $total=$subtotal + $total; // dynamic cart item display $cartOutput.="<tr align=center> <td width=5%><font face=arial color='#999999'>".$each_item['id']."</font></td> <td width=25%><font face=arial color='#999999'>".$product_name."</font></td> <td width=40%><font face=arial color='#999999'>".$scent."</font></td> <td valign=center width=5%><font face=arial color='#999999'>".$each_item['quantity']." </td> <td width=5%><font face=arial color='#999999'>$".$price.".00</font></td> <td width=10%><font face=arial color='#999999'>$".$subtotal.".00</font></td> </tr></form> <tr> <td colspan=6><hr size=1 width=50% color='#CBB659'/></td></tr>"; } // end if statement to see if cart is empty break; // if it is not a gift box or sale/clearance item default : $scent=substr($each_item['scent'],0,4); // Get product name and price $sql=mysql_query("SELECT products.productPrice, products.productName FROM products WHERE productId='$prod_id' LIMIT 1"); while ($row=mysql_fetch_array($sql)) { $product_name=$row["productName"]; $price=$row["productPrice"]; } // get scent for regular product $sql2=mysql_query("SELECT productscents.scentName FROM productscents WHERE scentId='$scent' LIMIT 1"); while ($row2=mysql_fetch_array($sql2)) { $scent=$row2['scentName']; } $subtotal=$price*$each_item['quantity']; $total=$subtotal + $total; if(isset ($_SESSION["cart_array"] )) { // dynamic cart item display $cartOutput.="<tr align=center> <td width=5%><font face=arial color='#999999'>".substr($each_item['id'],0,7)."</font></td> <td width=25%><font face=arial color='#999999'>".$product_name."</font></td> <td width=40%><font face=arial color='#999999'>".$scent."</font></td> <td valign=center width=5%><font face=arial color='#999999'>".$each_item['quantity']."</td> <td width=5%><font face=arial color='#999999'>$".$price.".00</font></td> <td width=10%><font face=arial color='#999999'>$".$subtotal.".00</font></td> </tr></form> <tr> <td colspan=6><hr size=1 width=50% color='#CBB659'/></td></tr>"; } // end if statement to see if cart is empty break; } // end switch } // end foreach that goes through each item in the cart /* Code that generates the email */ $ans=$_SESSION['check']; $check=$_POST['check']; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // customer information $firstName = strip_tags($_POST['firstName']); $lastName = strip_tags($_POST['lastName']); $address = strip_tags($_POST['address']); $city = strip_tags($_POST['city']); $prov = strip_tags($_POST['prov']); $postalCode = strip_tags(strtoupper($_POST['postal'])); $emailAddress = strip_tags($_POST['email']); $payment = $_POST['payment']; $ship = $_POST['shipping']; // email subject $subject= "Online Order Request"; // email address the form will be submitted to $myemail="orders@coppercreekbathandbody.ca"; if ($firstName!="" && $lastName!="" && $address!="" && $city!="" && $prov!="" && $postalCode!="" && $emailAddress!="" && $ans==$check) { $email="<html><center> <table border=0 width=100% cellspacing=0 cellpadding=5 style='background:#1d1d1d' > <tr> <td colspan=6><center><h2><font color=#999999>$subject</font></h2></center></td> </tr> <tr valign=center > <td colspan=6 align=center valign=center><font face=arial color=#999999> $firstName $lastName<br> $address<br> $city, $prov $postalCode<br> $emailAddress </font><br><br> </td> </tr> <tr align=center style='background: #333'> <td width=8%><font face=arial color=#999999>Item #</font></td> <td width=25%><font face=arial color=#999999>Product</font></td> <td width=40%><font face=arial color=#999999>Description</font></td> <td width=4%><font face=arial color=#999999>Quantity</font></td> <td width=4%><font face=arial color=#999999>Price</font></td> <td width=10%><font face=arial color=#999999>Total Cost</font></td> </tr> <tr><font face=arial> $cartOutput </font></tr> <tr style='background: #333'> <td colspan=5 align=right><font face=arial color=#999999>Total Price:</font></td> <td align=center><font face=arial color=#999999>$".$total.".00 </font></td> </tr> <tr> <td colspan=4 align=right valign=center> <font face=arial color=#999999>Payment Method: </font> </td> <td colspan=2 align=right valign=center> <font face=arial color=#999999>$payment</font> </td> </tr> <tr> <td colspan=4 align=right valign=center> <font face=arial color=#999999>Shipping: </font> </td> <td colspan=2 align=right valign=center> <font face=arial color=#999999>$ship</font> </td> </tr> </table></center></body></html>"; mail($myemail, $subject, $email, $headers); unset($_SESSION['check']); header("location: success.php"); } else { unset($_SESSION['check']); } customerInformation.php Code: [Select] <?php session_start(); error_reporting(E_ALL); ini_set('display_errors','1'); require_once("connect.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <script type="text/javascript" src="./js/functions.js"></script> <link rel="stylesheet" type="text/css" href="./css/navigationStyles.css"/> <script language=javascript type=text/javascript> function stopRKey(evt) { var evt = (evt) ? evt : ((event) ? event : null); var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if ((evt.keyCode == 13) && (node.type=="text")) { return false; } } document.onkeypress = stopRKey; </script> </head> <body> <div id='wrapper'> <div id='main'> <table border=0 width=70% cellspacing=10 cellpadding=5 id=table> <tr> <td colspan=6> <center><img src="./images/customerInfoLogo.gif"><br> <table border=0 width=90%> <tr> <td width=33% align=right> <a href='index.php'>HOME</a> </td> <td width=34%></td> <td width=33% align=left> <a href='cart.php'>VIEW CART</a> </td> </tr> </table> <br><br> </center> </td> </tr> <tr> <td colspan=6 align=center valign=center> <form action="process.php" name='order' method="post" onsubmit="document.getElementById('button').disabled=true; document.getElementById('button').value='Submitting, please wait...';"> <!-- REQUEST ORDER TABLE --> <table width=90% border=0 cellspacing=5 cellpadding=5> <!-- CLIENT NAME --> <tr valign=center> <td width=50% align=right> First Name: </td> <td width=50% align=left> <input type=text maxlength=40 width=40px class=contactBox id=firstName name="firstName" onBlur="validate(this.id);"> </td> </tr> <tr valign=center> <td width=50% align=right> Last Name: </td> <td width=50% align=left> <input type=text maxlength=40 width=40px onBlur='validate(this.id);' class=contactBox id=lastName name="lastName"> </td> </tr> <!-- ADDRESS --> <tr valign=center> <td width=50% align=right> Address: </td> <td width=50% align=left> <input type=text width=40px id=address class=contactBox name="address" onBlur='validate(this.id);'> </td> </tr> <!-- CITY --> <tr valign=center> <td width=50% align=right> City: </td> <td width=50% align=left> <input type=text width=40px id=city class=contactBox name="city" onBlur='validate(this.id);'> </td> </tr> <!-- Province --> <tr valign=center> <td width=50% align=right> Province: </td> <td width=50% align=left> <select name="prov"> <option value="AB">Alberta</option> <option value="BC">British Columbia</option> <option value="MB">Manitoba</option> <option value="NB">New Brunswick</option> <option value="NL">Newfoundland & Labrador</option> <option value="NT">Northwest Territories</option> <option value="NS">Nova Scotia</option> <option value="NU">Nunavut</option> <option value="ON">Ontario</option> <option value="PE">Prince Edward Island</option> <option value="QC">Quebec</option> <option value="SK" selected>Saskatchewan</option> <option value="YT">Yukon</option> </select> </td> </tr> <!-- POSTAL CODE --> <tr valign=center> <td width=50% align=right> Postal Code: </td> <td width=50% align=left> <input type=text width=40px id=postal class=contactBox name="postal" maxlength=7'> </td> </tr> <!-- EMAIL ADDRESS --> <tr valign=center> <td width=50% align=right> Email: </td> <td width=50% align=left> <input type=text width=60px id=email class=contactBox name="email" onBlur='validateEmail(this.id);'> </td> </tr> <!-- PAYMENT TYPE --> <tr valign=center> <td width=50% align=right> Payment Type: </td> <td width=50% align=left> <select name="payment"> <option value="Email Money Transfer" selected>Email Money Transfer</option> <option value="Cash">Cash</option> <option value="Money Order">Money Order</option> </select> </td> </tr> <!-- SHIPPING --> <tr valign=center> <td width=50% align=right> Need your order shipped: </td> <td width=50% align=left> <select name="shipping"> <option value="Don't Ship" selected>Don't Ship</option> <option value="Ship Order">Ship Order</option> </select> </td> </tr> <tr> <td colspan=2> <img src='captcha.php'> <input type='text' class=cap size=4 width=3 maxlength=4 onKeyPress='return check_qty(event);' name='check'> </td> </tr> <tr> <td colspan=2 valign=top> <input type=submit value='SEND ORDER' class='updateButton' id=button> <input type=reset value='CANCEL ORDER' class='updateButton' id=button onClick="location.href='home.php'"> </td> </tr> </table> </form> </td> </tr> </table> </div> <div id="sidebar" > <?php require ("menu.html"); ?> </div> </div> </body> </html> I have no idea what is happening. It should be displaying an html formatted email. Any help is greatly appreciated. For some reason the !isset() function doesnt seem to work i cant find out why hope you guys will be able to help Here is the html code for the form where the user enters the data Code: [Select] <div id="contact_form"> <h2>On Site SEO Signup Form</h2> <form method="post" name="contact" action="http://www.techbreeze.in/freeseo.php"> <label for="uname">Name:</label> <input name="uname" type="text" class="required input_field" id="uname" /> <div class="cleaner h10"></div> <label for="email">Email:</label> <input type="text" class="validate-email required input_field" name="email" id="email" /> <div class="cleaner h10"></div> <label for="website">Website:</label> <input type="text" class="required input_field" id="website" name="website"/> <div class="cleaner h10"></div> <label for="ftp">Your FTP Login URL:</label> <input type="text" class="required input_field" id="url" name="url" /> <div class="cleaner h10"></div> <label for="username">Your FTP Username:</label> <input type="text" class="required input_field" id="user" name="user" /> <div class="cleaner h10"></div> <label for="password">Your FTP Password:</label> <input type="password" class="required input_field" id="pass" name="pass"/> <div class="cleaner h10"></div> <input type="submit" value="Send" id="submit" name="submit" class="submit_btn float_l" /> <input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_r" /> </form> </div> And here is the code for the .php file where the !isset() function is used Code: [Select] <?php // validation expected data exists if( !isset($_POST['uname'])) { die ('We are sorry, but all the fields are necessary you cant leave the "Name" field empty!'); } if( !isset($_POST['pass'])) { die ('We are sorry, but all the fields are necessary you cant leave the "Password" field empty!'); } if( !isset($_POST['email'])) { die ('We are sorry, but all the fields are necessary you cant leave the "Email" field empty!'); } if( !isset($_POST['website'])) { die ('We are sorry, but all the fields are necessary you cant leave the "Website" field empty!'); } if( !isset($_POST['url'])) { die ('We are sorry, but all the fields are necessary you cant leave the "FTP URL" field empty!'); } if( !isset($_POST['user'])) { die ('We are sorry, but all the fields are necessary you cant leave the "Username" field empty!'); Thanks in advance Hello Everyone I`m new to PHP, therefore I would really appreciate any help with this code. The error message I get: SQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where cid=B' at line 1 This is the function, I`m trying to use: function update_student_course($sid, $cid, $grade, $comments) { $esc_sid = mysql_real_escape_string($sid, $this->conn); $esc_cid = mysql_real_escape_string($cid, $this->conn); $esc_grade = mysql_real_escape_string($grade, $this->conn); $esc_comments = mysql_real_escape_string($comments, $this->conn); $sql = "UPDATE studentcourses set grade='{$esc_grade}', comments='{$esc_comments}' where sid={$esc_sid} and cid={$esc_cid}"; $result = mysql_query($sql, $this->conn); if (!$result) die("SQL Error: " . mysql_error()); else { $numofrows = mysql_affected_rows($this->conn); return $numofrows; } } And this would be the code: <?php $db1 = new student_course(); $db1->openDB(); $sql = "SELECT sid FROM STUDENTS"; $result1 = $db1->getResult($sql); $sql = "SELECT cid FROM COURSES"; $result2 = $db1->getResult($sql); if (!$_POST) { //page loads for the first time ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> Choose student ID: <select name = "sid"> <?php while ($row = mysql_fetch_array($result1)) echo "<option value='{$row['sid']}'>{$row['sid']}</option>"; ?> </select><br/> Choose course ID: <select name = "cid"> <?php while ($row = mysql_fetch_array($result2)) echo "<option value ='{$row['cid']}'>{$row['cid']} </option>"; ?> </select><br/> Enter grade to update: <input type="text" name="cid" /><br /> Enter new comment: <input type="text" name="cname" /><br /> <input type="submit" value="Update" /> </form> <?php } //end if else { $sid = $_POST['sid']; $cid = $_POST['cid']; $grade = $_POST['grade']; $comment = $_POST['comment']; $db1 = new student_course(); $db1->openDB(); $numofrows = $db1->update_student_course($sid, $cid, $grade, $comment); echo "Success. Number of rows affected: <strong>{$numofrows}<strong>"; $db1->closeDB(); } ?> Any idea, what am I doing wrong??? Server version: 5.1.41 Thank you very much in advance, for taking the time and reading it!!! layman Im new to php and Im working on a script that I purchased. I'm getting this error when I try to setup my script. I did some research and understand that I "eregi" is old code and not being used anymore. So I tried to use preg_match but I'm stuck. If anyone can look at the code and help with some notes. I would like to understand what im doing wrong not just a fix. Deprecated: Function eregi() Code: [Select] if (eregi($file,$_SERVER["HTTP_ACCEPT_LANGUAGE"]) && !$use_lang) $use_lang = $file; This is what I get when using preg_match. preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash Code: [Select] if (preg_match($file,$_SERVER["HTTP_ACCEPT_LANGUAGE"]) && !$use_lang) $use_lang = $file; |