PHP - Help With Update Table Script
OK I have no idea why this will not update the table but here is the code I wrote. I just can't see it
Code: [Select] <?php //CONNECT TO DATABASE include("sharons_dbinfo.inc.php"); mysql_connect(localhost,$user,$password); mysql_select_db($database) or die( "Unable to select database"); //OPEN THE ZIP FILE $handle = gzopen('Newegg_com-Daily_Deals_Feed.txt.gz', 'r'); //READ THE WHOLE FILE LINE BY LINE while (!gzeof($handle)) { $buffer = gzgets($handle, 4096); $buffer = str_replace("'" , "" , $buffer); $buffer = str_replace("\"" , "" , $buffer); $data = explode(",", $buffer); //SKIP THE FIRST LINE OF COLUMN NAMES if ($data[4] == "NAME"){} else{ //PUT THIS IN TO MAKE SURE IT WAS LOOKING FOR THE RIGHT RECORD print "Looking for: ". $data['4'] . " to update with new date " . $data['3']."<br>"; $item_name = $data['4']; //QUERY THE TABLE FOR PRODUCT NAME FROM ZIP FILE $query = ("SELECT * FROM `computer_memory` WHERE `NAME` = '$item_name'"); $results = mysql_query($query) or die(mysql_error()."<br /><br />".$query); $result = mysql_fetch_array($results); $num=mysql_numrows($results); //IF THE NAME EXISTS PROCEED TO UPDATE THE RECORD WITH THE NEW INFORMATION if ($num >0) { //UPDATE TABLE WITH THE NEW INFORMATION $update = ("UPDATE `computer_memory` SET `PROGRAMNAME`= '$data[0]', `PROGRAMURL`= '$data[1]', `CATALOGNAME`= '$data[2]', `LASTUPDATED`= '$data[3]', `NAME`= '$data[4]', `KEYWORDS`= '$data[5]', `DESCRIPTION`= '$data[6]', `SKU`= '$data[7]', `MANUFACTURER`= '$data[8]', `MANUFACTURERID`= '$data[9]', `UPC`= '$data[10]', `ISBN`= '$data[11]', `CURRENCY`= '$data[12]', `SALEPRICE`= '$data[13]', `PRICE`= '$data[14]', `RETAILPRICE`= '$data[15]', `FROMPRICE`= '$data[16]', `BUYURL`= '$data[17]', `IMPRESSIONURL`= '$data[18]', `IMAGEURL`= '$data[19]', `ADVERTISERCATEGORY`= '$data[20]', `THIRDPARTYID`= '$data[21]', `THIRDPARTYCATEGORY`= '$data[22]', `AUTHOR`= '$data[23]', `ARTIST`= '$data[24]', `TITLE`= '$data[25]', `PUBLISHER`= '$data[26]', `LABEL`= '$data[27]', `FORMAT`= '$data[28]', `SPECIAL`= '$data[29]', `GIFT`= '$data[30]', `PROMOTIONALTEXT`= '$data[31]', `STARTDATE`= '$data[32]', `ENDDATE`= '$data[33]', `OFFLINE`= '$data[34]', `ONLINE`= '$data[35]', `INSTOCK`= '$data[36]', `CONDITION`= '$data[37]', `WARRANTY`= '$data[38]', `STANDARDSHIPPINGCOST`= '$data[39]' WHERE `ID`= '$id'"); mysql_query($update) or die(mysql_error()."<br /><br />".$update); //if ($update){print "UPDATED ".$result['ID'];} }else{ //IF THE NAME DID NOT EXIST INSERT A NEW RECORD INTO THE TABLE $import="INSERT into computer_memory (`ID`,`PROGRAMNAME`,`PROGRAMURL`,`CATALOGNAME`,`LASTUPDATED`,`NAME`,`KEYWORDS`,`DESCRIPTION`,`SKU`,`MANUFACTURER`,`MANUFACTURERID`,`UPC`,`ISBN`,`CURRENCY`,`SALEPRICE`,`PRICE`,`RETAILPRICE`,`FROMPRICE`,`BUYURL`,`IMPRESSIONURL`,`IMAGEURL`,`ADVERTISERCATEGORY`,`THIRDPARTYID`,`THIRDPARTYCATEGORY`,`AUTHOR`,`ARTIST`,`TITLE`,`PUBLISHER`,`LABEL`,`FORMAT`,`SPECIAL`,`GIFT`,`PROMOTIONALTEXT`,`STARTDATE`,`ENDDATE`,`OFFLINE`,`ONLINE`,`INSTOCK`,`CONDITION`,`WARRANTY`,`STANDARDSHIPPINGCOST`) values('','$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[9]','$data[10]','$data[11]','$data[12]','$data[13]','$data[14]','$data[15]','$data[16]','$data[17]','$data[18]','$data[19]','$data[20]','$data[21]','$data[22]','$data[23]','$data[24]','$data[25]','$data[26]','$data[27]','$data[28]','$data[29]','$data[30]','$data[31]','$data[32]','$data[33]','$data[34]','$data[35]','$data[36]','$data[37]','$data[38]','$data[39]')"; mysql_query($import) or die(mysql_error()); } } } gzclose($handle); ?> I hope someone can see what I can't Thanks everyone Similar TutorialsCan anyone post a generic update function to update mysql table. The manual approach: update $tablename set $column1='a', $column2='b' where $id=$value; Good morning. I am looking fo some help with an update script to update all rows in a table. This is what I have for a form and all looks well. form.php <?php // run the query and put the results in an array variable called $result $result = mysql_query("SELECT * FROM table ORDER BY 'id', 'title', 'text', 'number'"); print "<form method='post' action='update.php'> <table width='100%' border='0' cellspacing='1' cellpadding='1'><tr> <td align='center'><strong>ID</strong></td> <td align='center'><strong>Title</strong></td> <td align='center'><strong>text</strong></td> <td align='center'><strong>Number</strong></td> </tr>\n"; // start a loop to print all of the courses with their book information // the mysql_fetch_array function puts each record into an array. each time it is called, it moves the array counter up until there are no more records left while ($Update = mysql_fetch_array($result)) { // start displaying the info; the most important part is to make the name an array (notice bookinfo[$i]) print "<td align='center'><p>{$Update['id']}</p></td>\n"; print "<td align='center'><input type='text' name='title' value='{$Update['title']}' /></td>"; print "<td align='center'><input type='text' size='40' name='text' value='{$Update['text']}' /></td>\n"; print "<td align='center'><input type='text' size='40' name='number' value='{$Update['number']}' /></td>\n"; print "</tr>\n"; // add 1 to the count, close the loop, close the form, and the mysql connection } print "<tr> <td colspan='4' align='center'><input type='submit' value='submit' />"; print "</td> </tr> </table> </td> </tr> </form> </table>"; print "</tr>\n"; ?><br /><br /> My question is. How do I update this info into the database with the proper info. ie. Update.php? I'm new to PHP and I was able to figure out how to populate data from my database into my text fields. I am trying to add the update information to the same php file; however, I am now receiving errors within the data I was able to populate,
Notice: Undefined variable: stmt in C:\xampp\htdocs\Cust_App\update.php on line 47 and errors with the Update statement
Notice: Undefined variable: stmtupdate in C:\xampp\htdocs\Cust_App\update.php on line 96 I had defined the customerID variable above in the code, but it isn't being captured from here. I tried setting up this query like the one which gathered the data, but I'm off by a little bit. I would like the option to be able to update all fields. Any help is appreciated. I'm trying to learn as I may get asked to update other forms in the future. (new boss asks a lot) <?php require_once('database.php'); ?> <!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"> <!-- the head section --> <head> <title>My Guitar Shop</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <!-- the body section --> <body> <div id="page"> <div id="header"> <h1>SportsPro Technical Support</h1> <p>Sports management software for the sports enthusiast.</p></h1> </div> <div id="main"> <h1>View/Update Customer</h1> <form action="update.php" method="get" > <?php if(isset($_GET['customerID'])) { $customerID = filter_input(INPUT_GET, 'customerID', FILTER_SANITIZE_NUMBER_INT); $sql = "SELECT * FROM customers WHERE customerID =$customerID "; $stmt = $db->query($sql); } ?> <div id="content"> <!-- display a table of products --> <h2>Customers</h2> <form method = "edit"> <?php foreach ($stmt as $cust) { ?> <div> <label>First Name</label> <input type="text" name="name" class ="form-control" value ="<?php echo $cust['firstName']; ?>"> </div><br> <div> <label>Last Name</label> <input type="text" name="name" class ="form-control" value ="<?php echo $cust['lastName']; ?>"> </div><br> <div> <label>Address</label> <input type="text" name="address" class ="form-control" value ="<?php echo $cust['address']; ?>"> </div><br> <div> <label>City</label> <input type="text" name="city" class ="form-control" value ="<?php echo $cust['city']; ?>"> </div><br> <div> <label>State</label> <input type="text" name="state" class ="form-control" value ="<?php echo $cust['state']; ?>"> </div><br> <div> <label>Country</label> <input type="text" name="countryCode" class ="form-control" value ="<?php echo $cust['countryCode']; ?>"> </div><br> <div> <label>Zip Code</label> <input type="text" name="postalCode" class ="form-control" value ="<?php echo $cust['postalCode']; ?>"> </div><br> <div> <label>Email </label> <input type="text" name="email" class ="form-control" value ="<?php echo $cust['email']; ?>"> </div><br> <div> <label>Phone Number </label> <input type="text" name="phone" class ="form-control" value ="<?php echo $cust['phone']; ?>"> </div><br> <div> <label>Password </label> <input type="text" name="password" class ="form-control" value ="<?php echo $cust['password']; ?>"> </div><br> <div> <?php } ?> <input type="Submit" name="Update_Data" value="Update Data"></input> <?php $sql2 = "UPDATE customers SET firstName = ". $stmtupdate['firstName']." WHERE customerID =$customerID "; $stmtupdate = $db->query($sql2); ?> </div> </div> <div id="footer"> <p> © <?php echo date("Y"); ?> SportsPro, Inc. </p> </div> </div><!-- end page --> </body> </html>
Hi i have this upload script which works fine it uploads image to a specified folder and sends the the details to the database. but now i am trying to instead make a modify script which is Update set so i tried to change insert to update but didnt work can someone help me out please this my insert image script which works fine but want to change to modify instead Code: [Select] <?php mysql_connect("localhost", "root", "") or die(mysql_error()) ; mysql_select_db("upload") or die(mysql_error()) ; // my file the name of the input area on the form type is the extension of the file //echo $_FILES["myfile"]["type"]; //myfile is the name of the input area on the form $name = $_FILES["image"] ["name"]; // name of the file $type = $_FILES["image"]["type"]; //type of the file $size = $_FILES["image"]["size"]; //the size of the file $temp = $_FILES["image"]["tmp_name"];//temporary file location when click upload it temporary stores on the computer and gives it a temporary name $error =array(); // this an empty array where you can then call on all of the error messages $allowed_exts = array('jpg', 'jpeg', 'png', 'gif'); // array with the following extension name values $image_type = array('image/jpg', 'image/jpeg', 'image/png', 'image/gif'); // array with the following image type values $location = 'images/'; //location of the file or directory where the file will be stored $appendic_name = "news".$name;//this append the word [news] before the name so the image would be news[nameofimage].gif // substr counts the number of carachters and then you the specify how how many you letters you want to cut off from the beginning of the word example drivers.jpg it would cut off dri, and would display vers.jpg //echo $extension = substr($name, 3); //using both substr and strpos, strpos it will delete anything before the dot in this case it finds the dot on the $name file deletes and + 1 says read after the last letter you delete because you want to display the letters after the dot. if remove the +1 it will display .gif which what we want is just gif $extension = strtolower(substr($name, strpos ($name, '.') +1));//strlower turn the extension non capital in case extension is capital example JPG will strtolower will make jpg // another way of doing is with explode // $image_ext strtolower(end(explode('.',$name))); will explode from where you want in this case from the dot adn end will display from the end after the explode $myfile = $_POST["myfile"]; if (isset($image)) // if you choose a file name do the if bellow { // if extension is not equal to any of the variables in the array $allowed_exts error appears if(in_array($extension, $allowed_exts) === false ) { $error[] = 'Extension not allowed! gif, jpg, jpeg, png only<br />'; // if no errror read next if line } // if file type is not equal to any of the variables in array $image_type error appears if(in_array($type, $image_type) === false) { $error[] = 'Type of file not allowed! only images allowed<br />'; } // if file bigger than the number bellow error message if($size > 2097152) { $error[] = 'File size must be under 2MB!'; } // check if folder exist in the server if(!file_exists ($location)) { $error[] = 'No directory ' . $location. ' on the server Please create a folder ' .$location; } } // if no error found do the move upload function if (empty($error)){ if (move_uploaded_file($temp, $location .$appendic_name)) { // insert data into database first are the field name teh values are the variables you want to insert into those fields appendic is the new name of the image mysql_query("INSERT INTO image (myfile ,image) VALUES ('$myfile', '$appendic_name')") ; exit(); } } else { foreach ($error as $error) { echo $error; } } //echo $type; ?> Hello I have three tables User diysmps usergroup usergroupid is common in the three tables. diysmps is joined on usergroup, so running this sql SELECT diysmps.name, diysmps.email, diysmps.sumbit, diysmps.message, diysmps.ID, usergroup.title FROM diysmps INNER JOIN usergroup ON diysmps.usergroupid = usergroup.usergroupid ORDER BY diysmps.ID DESC see results i get in picture attached. the result (PENDIN REGISTRATION) is what i need to be updated WHEN the user register to the forums. when the user register to the forums, an account with his EMAIL will be created into the (USER) table. So, I need to look out for the email FROM (diysmps TABLE) into the user table _search user table for email from diysmps table_ and if found to update the USERGROUPID in (diysmps TABLE) withe the USERGROUPID from (USER) table (related to the email searched) so, when user registers, status from PENDING REGISTRATION to REGISTERED will be shown I know it looks complex for me, but thats how i can describe Thanks all Hi
i've got a script to migrate some tables.
This is most of it.. just missing the db connection (not needed here)
$link = mysql_connect($host,$user,$pass) or die(mysql_error()); mysql_selectdb($db,$link) or die(mysql_error()); $ag_forums_to_kunena_categories = array(); mysql_query("TRUNCATE bzhv8_kunena_messages"); mysql_query("TRUNCATE bzhv8_kunena_messages_text"); $sql = " SELECT p.id AS messages_id, u.name AS messages_name, a.jos_id AS messages_userid, p.message AS messages_text_message, p.posted AS messages_time, p.edited AS messages_modified_time, p.edited_by AS messages_modified_by, p.topic_id AS messages_thread, t.forum_id AS messages_catid FROM jos_agora_posts AS p LEFT JOIN jos_agora_users AS a ON a.username = p.poster LEFT JOIN jos_agora_topics AS t ON t.id = p.topic_id LEFT JOIN bzhv8_users AS u ON u.id = a.jos_id ORDER BY p.id ASC "; $res = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_object($res)) { echo $row->messages_id; //echo "<br />"; //echo $row->messages_name; //echo "<br />"; //echo $row->messages_userid; //echo "<br />"; //echo $row->messages_text_message; //echo "<br />"; //echo $row->messages_time; //echo "<br />"; //echo $row->messages_modified_time; //echo "<br />"; //echo $row->messages_modified_by; //echo "<br />"; //echo $row->messages_thread; //echo "<br />"; //echo $row->messages_catid; //echo "<br />"; //if($row->messages_userid == '') //echo "userid er nul"; //{ // $row->messages_userid = 0; //} $cat_id = $ag_forums_to_kunena_categories[$row->messages_catid]; if ($cat_id != 0) { echo $cat_id; echo "kategori id"; echo "<br />"; echo "lige før den skal indsætte"; $sql = "INSERT INTO `bzhv8_kunena_messages` VALUES (".$row->messages_id.", 0, ".$row->messages_thread.", ".$cat_id.", '".$row->messages_name."', ".$row->messages_userid.", '', '', ".$row->messages_time.", NULL, 0, 0, 0, 0, 0, 0, 0, 0, '')"; echo "her bør den køre sql(1)"; $sql2 = "INSERT INTO `bzhv8_kunena_messages_text` VALUES (".$row->messages_id.", '".mysql_escape_string($row->messages_text_message)."')"; echo $sql; echo "lige efter anden insert echo sql"; echo "<br />"; echo $sql2; echo "<br />"; echo "her skulle den vise anden insert"; mysql_query($sql) or die(mysql_error()); mysql_query($sql2) or die(mysql_error()); } else { } } mysql_close();But something is not working.. first.. ignore the echo's of course.. just me trying to debug.. same with the else statement... from what I can tell.. and my php knowledge is non-existant.. this part: $cat_id = $ag_forums_to_kunena_categories[$row->messages_catid]; it what's causing the problem.. it appears that the $cat_id is not getting any data.. if copy the sql line and run it against my database via phpmyadmin then it works as it should.. but well.. something isn't right.. there are some other stuff in the script that does the same as the above.. but with different tables and they work just fine.. example: mysql_query("TRUNCATE bzhv8_kunena_topics"); $sql = " SELECT t.id AS topic_id, t.poster AS topic_poster, t.subject AS topic_subject, t.posted AS topic_first_post_time, t.last_post AS topic_last_post_time, t.last_post_id AS topic_last_post_id, t.last_poster AS topic_last_poster, t.num_views AS topic_hits, t.num_replies AS topic_posts, t.closed AS topic_locked, t.sticky AS topic_hold, t.moved_to AS topic_moved_id, t.forum_id AS topic_category_id, t.question AS topic_poll_id, p.id AS topic_first_post_id, p.posted AS topic_first_post_time, a.jos_id AS topic_first_post_userid, p.message AS topic_first_post_message FROM jos_agora_topics AS t LEFT JOIN jos_agora_users AS a ON a.username = t.poster LEFT JOIN jos_agora_posts AS p ON t.posted = p.posted ORDER BY t.id ASC "; $res = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_object($res)) { echo $row->topic_id; echo "<br />"; if($row->topic_first_post_userid == '') { $row->topic_first_post_userid = 0; } $cat_id = $ag_forums_to_kunena_categories[$row->topic_category_id]; echo $cat_id; echo "<br />"; $sql = "INSERT INTO `bzhv8_kunena_topics` VALUES (".$row->topic_id.", ".$cat_id.", '".mysql_escape_string($row->topic_subject)."', 0, ".$row->topic_locked.", ".$row->topic_hold.", 0, ".$row->topic_posts.", ".$row->topic_hits.", 0, 0, 0, ".$row->topic_first_post_id.", ".$row->topic_first_post_time.", ".$row->topic_first_post_userid.", '".mysql_escape_string($row->topic_first_post_message)."', NULL, ".$row->topic_last_post_id.", ".$row->topic_last_post_time.", 0, NULL, NULL, '')"; echo $sql; echo "<br />"; mysql_query($sql) or die(mysql_error()); }the above works fine.. Can someone take a look and give a hint or 2.. or just point at whatever the solution is :-) I plan to be releasing some scripts and will update the version of the script on my website. Users will be able to download the script and run it on there website. The latest version will be checked by checking my website and compared with the version of the user's script to see if its out of date. I can't get it to work correctly. On http://www.phpfusionmods.com/updates/check.php I have the latest version set to 1.4. In the script the version is set at 1.3 so its obviously out of date. However, its showing that its up to date. Please offer your support. My script is below. <?php $version = "1.3"; function new_version() { $url = "http://www.phpfusionmods.com/updates/check.php"; $url_p = @parse_url($url); $host = $url_p['host']; $port = isset($url_p['port']) ? $url_p['port'] : 80; $fp = @fsockopen($url_p['host'], $port, $errno, $errstr, 5); if (!$fp) return false; @fputs($fp, 'GET ' . $url_p['path'] . ' HTTP/1.1' . chr(10)); @fputs($fp, 'HOST: ' . $url_p['host'] . chr(10)); @fputs($fp, 'Connection: close' . chr(10) . chr(10)); $response = @fgets($fp, 1024); $content = @fread($fp, 1024); $content = preg_replace("#(.*?)text/plain(.*?)$#is", "$2", $content); @fclose($fp); if (preg_match("#404#", $response)) return "Timeout"; else return trim(str_replace("X-Pad: avoid browser bug", "", $content)); } $newversion = str_replace("X-Pad: avoid browser bug", "", new_version()); $new_version = $newversion != "Timeout" && intval(str_replace(".", "", $newversion)) > intval(str_replace(".", "", $version)) ? true : false; if ($new_version) { echo "Download the latest version <a href='http://www.phpfusionmods.com/' target='_blank'>here</a>. <b>v" . str_replace("X-Pad: avoid browser bug", "", $newversion) . "</b>"; } elseif ($newversion == "Timeout") { echo "PHPFusionMods.com has timed out. Check for updates <a href='http://www.phpfusionmods.com/' target='_blank'>here</a>."; } else { echo ("You have the latest version"); } ?> Having trouble with this upload script, it grabs and displays the content from the database fine. It won't however update the database although the code is throwing up no errors; this is the script that displays the content Code: [Select] ############### Code <?php include("includes/connection.php"); $sql="SELECT * FROM mot"; $result=mysql_query($sql); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td> <table width="400" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="4"><strong>List data from mysql </strong> </td> </tr> <tr> <td align="center"><strong>Name</strong></td> <td align="center"><strong>Lastname</strong></td> <td align="center"><strong>Update</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><? echo $rows['header']; ?></td> <td><? echo $rows['content']; ?></td> // link to update.php and send value of id <td align="center"><a href="update_content.php?id=<? echo $rows['id']; ?>">update</a></td> </tr> <?php } ?> </table> </td> </tr> </table> this next bit of code is the code that user updates the content; Code: [Select] <?php include("includes/connection.php"); $id=$_GET['id']; $sql="SELECT * FROM mot WHERE id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <form name="form1" method="post" action="update_ac.php"> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td> </td> <td colspan="3"><strong>Update data in mysql</strong> </td> </tr> <tr> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> </tr> <tr> <td align="center"> </td> <td align="center"><strong>Name</strong></td> <td align="center"><strong>Lastname</strong></td> </tr> <tr> <td> </td> <td align="center"><input name="name" type="text" id="name" value="<? echo $rows['header']; ?>"></td> <td align="center"><input name="lastname" type="text" id="lastname" value="<? echo $rows['content']; ?>" size="15"></td> </tr> <tr> <td> </td> <td><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>"></td> <td align="center"><input type="submit" name="Submit" value="Submit"></td> <td> </td> </tr> </table> </td> </form> </tr> </table> this final bit is the update code for the database which isnt working but not throwing up any errors Code: [Select] <?php include("includes/connection.php"); if(isset($_POST['update'])){ $id = $_GET['id']; $header = $_POST['header']; $content = $_POST['content']; $sql="UPDATE mot SET header = '$header', content = '$content' WHERE id='$id'"; $result=mysql_query($sql); if($result){ echo "Successful"; echo "<BR>"; echo "<a href='mot_edit.php'> View result</a>"; } else { echo "ERROR"; } } ?> Any help would be much appreciated Please could some1 just point out why this php code is not updating the my-sql db? It displays the content of the db but does not update accordingly.. Code: [Select] <?php include("cn.php"); //$username=$_GET['username']; if (!@$_SESSION['username']){ header("location:Not_Logged.php"); } if (isset($_POST['update'])) { $update=$_GET['update'];} else {$update=0;} if ($update = "1") { $username=$_GET['username']; $id=$_GET['id']; $username=$_POST['username']; $password=$_POST['password']; $select="select * from users where username='$_SESSION[username]'"; $rs_cat=mysqli_query($con,$select); $row=mysqli_fetch_array($rs_cat); $username=$row['username']; $password=$row['password']; $update="UPDATE users SET username='$username', password='$password' where id='$id'"; $ur=mysqli_query($con,$update) or die (mysql_error()); } ?> <!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>UPDATE</title> </head> <body> <?php //echo $_SESSION['username'];?> <table align="center" > <form name="login" action="" method="post"/> <tr> <td> <th scope="col"><strong>UPDATE</strong></th> </td> </tr> <tr> <td> USERNAME <th scope="col"><input name="username" type="text" value="<?php echo ("$row[username]");?>"/></th> </td> </tr> <tr> <td> PASSWORD <th scope="col"><input name="password" type="password" value="<?php echo ("$row[password]");?>" /></th> </td> </tr> <tr> <td> <th scope="col"><input name="update" type="submit" value="UPDATE" /></th> </td> </tr> <tr> <td> <th scope="col"><input name="id" type="hidden" value="<?php echo $row[id];?>" /></th> </td> </form> </table> </body> </html> Any sharp locator would be appreciated... I have a script to let the user update their password, when I submit it i get a 500 error and I'm not sure. Here is the code: If (isset($_POST['update-password'])) { //This makes sure they did not leave any fields blank if (!$_POST['oldpw'] || !$_POST['pass'] || !$_POST['pass2'] ) { $error="<span style="; $error .="color:red"; $error .=">"; $error .= "You did not complete all of the required fields"; $error .="</span>"; setcookie('Errors', $error, time()+20); header('Location /useredit.php'); exit; } // checks if the password is correct $pass = md5($_POST['pass']); if (!get_magic_quotes_gpc()) { $pass = addslashes($pass); } $check = mysql_real_escape_string("SELECT * FROM YBK_Login WHERE pass = '{$pass}'"); mysql_query($check) or die( 'Query string: ' . $check . '<br />Produced an error: ' . mysql_error() . '<br />' ); // this makes sure both passwords entered match if ($_POST['pass'] != $_POST['pass2']) { $error="<span style="; $error .="color:red"; $error .=">"; $error .= 'Your passwords did not match.'; $error .="</span>"; setcookie('Errors', $error, time()+20); header('Location: /useredit.php'); exit; } // here we encrypt the password and add slashes if needed $_POST['pass'] = md5($_POST['pass']); if (!get_magic_quotes_gpc()) { $_POST['pass'] = addslashes($_POST['pass']); $_POST['pass2'] = addslashes($_POST['pass2']); } // now we insert it into the database mysql_real_escape_string($insert = "UPDATE `YBK_Login` SET `pass` = '{$_POST['pass']}', `HR` = '{$_POST['pass2']}', `comment` = '{$_POST['oldpw']}' WHERE `ID` = {$_COOKIE['UID_WatsonN']}"); mysql_query($insert) or die( 'Query string: ' . $insert . '<br />Produced an error: ' . mysql_error() . '<br />' ); $error="<span style="; $error .="color:green"; $error .=">"; $error .= "<p>Thank you, your password has been updated.</p>"; $error .="</span>"; setcookie('Errors', $error, time()+20); header('Location: /useredit.php'); exit; } I am attempting to update selected records using '$row[' elements in where clauses. I recieve message 'Record Updated but when I check data base it hasn't changed. CODE: $query = "SELECT cr_num, cr_ci_num, cr_dte, cr_flag, ci_desc, ci_authority, ce_name, ce_email, ce_phone_ext FROM c_record, c_info, c_employee WHERE cr_num = ce_num AND cr_ci_num = ci_num AND cr_dte > '{$dte60}' and cr_dte <= '{$dte90}' AND cr_flag = '00'"; $result = mysqli_query($dbc, $query) or die('ERROR querying database'); while($row = mysqli_fetch_array($result)) { $query = "UPDATE c_record SET cr_flag = '90' WHERE cr_num = '{$row[cr_num]}' AND cr_ci_num = '{$row[cr_ci_num]}'" or die('ERROR UPDATE'); echo 'Update succesfull'; echo "<br />\n" Hello Code Gents, I get so stretched breaking point when a trusted resuable code refuses to perform: Here's it Code: [Select] <?php require_once("includes/start_session.php"); require_once("includes/cn.php"); $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $username=$_GET[$_SESSION['username']]; require_once("includes/nav_menu.php"); ///updates $msg=""; $aid=$_GET['aid']; $staff_id=$_GET['staff_id']; $come="select * from staff_payrolls where staff_id='$staff_id'"; $q1=mysqli_query($dbc,$come); $row=mysqli_fetch_array($q1); $aid = $row['aid']; $staff_id = $row['staff_id']; $basic = $row['basic']; $rent = $row['rent']; $pension = $row['pension']; $union = $row['union']; $tax = $row['tax']; $net = $row['net']; $gross = $row['gross']; if (isset($_POST['submit'])) { $renti=$basic*0.5; $pensioni=$basic*0.05; $unioni=$basic*0.03; $taxi=$basic*0.02; $neti=$basic+$rent; $grossi=$basic+$rent+$pension+$tax; // Grab the profile data from the POST //$staff_id = mysqli_real_escape_string($dbc, trim($_POST['staff_id'])); $basic = mysqli_real_escape_string($dbc, trim($_POST['basic'])); $rent = mysqli_real_escape_string($dbc, trim($_POST['rent'])); $union = mysqli_real_escape_string($dbc, trim($_POST['union'])); $pension = mysqli_real_escape_string($dbc, trim($_POST['pension'])); $tax = mysqli_real_escape_string($dbc, trim($_POST['tax'])); $net = mysqli_real_escape_string($dbc, trim($_POST['net'])); $gross = mysqli_real_escape_string($dbc, trim($_POST['gross'])); $error=false; if (!$error) { if (!empty($aid)) { //UPDATE `ak`.`staff_payrolls` SET `basic` = '' WHERE `staff_payrolls`.`aid` =1; $sql= "UPDATE `ak`.`staff_payrolls` SET `basic` ='$_POST[basic]', `rent`='$renti',`pension`='$pensioni',`union`='$unioni',`tax`='$taxi',`net` ='$neti',`gross` ='$grossi',`salary_date`=SYSDATE() where `staff_payrolls`.`aid` ='$aid'"; mysqli_query($dbc, $sql); } } // End of check for form submission } ?> <p><strong>Welcome to BODE COSMETICS PAYROLL MANAGEMENT SYSTEM.</strong></p> <p><?php echo("Welcome $_SESSION[username]. You can start by the top-pane Navigation") ;?> <p><?php //echo $err ; if (@mysqli_query($dbc, $sql)) { echo 'Record Updated';} $query = "SELECT * FROM staff_payrolls WHERE aid = '$aid'"; $data = mysqli_query($dbc, $query); $row = mysqli_fetch_array($data); $staff_id = $row['staff_id']; $basic = $row['basic']; $rent = $row['rent']; $pension = $row['pension']; $union = $row['union']; $tax = $row['tax']; $net = $row['net']; $gross = $row['gross']; ?> <table> <form name="login" method="post" action=""> <tr> <td> <th scope="col"><strong>STAFF UPDATE AREA</strong></th> </td> </tr> <tr> <td> STAFF ID <th scope="col"><input name="staff_id" type="text" value="<?php echo $row['staff_id']; ?>" disabled="disabled" /></th> </td> </tr> <tr> <td> BASIC SALARY<th scope="col"><input name="basic" type="text" value="<?php echo $row['basic']; ?>" /></th> </td> </tr> <tr> <td> RENT <th scope="col"><input name="rent" type="text" value="<?php echo $rent; ?>" /></th> </td> </tr> <tr> <td> PENSION <th scope="col"><input name="pension" type="text" value="<?php echo $pension; ?>" /></th> </td> </tr> <tr> <td> UNION <th scope="col"><input name="union" type="text" value="<?php echo $union; ?>" /></th> </td> </tr> <tr> <td> TAX <th scope="col"><input name="tax" type="text" value="<?php echo $tax; ?>" /></th> </td> </tr> <tr> <td> NET <th scope="col"><input name="net" type="text" value="<?php echo $net; ?>" /></th> </td> </tr> <tr> <td> GROSS <th scope="col"><input name="gross" type="text" value="<?php echo $gross; ?>" /></th> </td> </tr> <tr> <td> <th scope="col"><input name="submit" type="submit" value="Update_Salary" /></th> </td> </tr> </form> </table> </p> </div> <div class="footer"></div> </div> <div class="post"> <div class="header"> <?php require_once("includes/footer.php");?> The funny thing now is that when I press the submit button, nothing happens. Except for the display of what is in the database. Hi, Im just in the middle of creating an update script for my mysql database but don't know why it's not working. p.s. I'm a little new to PHP, but know quite a bit, it's probably something really small.. *facepalm* Here's the script: the form (update.php) <? // Connect to the database $link = mysql_connect('###', '###', '###'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('###', $link); $id = $_GET['id']; // Ask the database for the information from the links table $query="SELECT * FROM orders WHERE id='$id'"; $result = mysql_query("SELECT * FROM orders"); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $name=mysql_result($result,$i,"Name"); $location=mysql_result($result,$i,"Location"); $fault=mysql_result($result,$i,"Fault"); ?> <form action="updated.php" method="post"> <input type="hidden" name="ud_id" value="<? echo "$id";?>"> Name: <input type="text" name="ud_name" value="<? echo "$name"?>"><br> Location: <input type="text" name="ud_location" value="<? echo "$location"?>"><br> Fault: <input type="text" name="ud_fault" value="<? echo "$fault"?>"><br> <input type="Submit" value="Update"> </form> <? ++$i; } ?> ------------------------------------------------------ (processor) updated.php <?php // Connect to the database $link = mysql_connect('###', '###', '###'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('###', $link); $query="UPDATE orders SET Name='" . $_POST['ud_name'] . "', Location='" . $_POST['ud_location'] . "', Fault='" . $_POST['ud_fault'] . "' WHERE $id='" . $_POST['ud_id'] . "'"; echo $query; $checkresult = mysql_query($query); if ($checkresult) echo '<p>update query succeeded'; else echo '<p>update query failed'; mysql_close(); ?> ------------------------------------------------------ Every time I want to update, it comes up with: UPDATE orders SET Name='TEST', Location='TEST', fault='jbjh' WHERE ='' update query failed Any help would be appreciated. Hello, Ive got a fairly successful website and im looking at cloning it, I want to set up a cron to check the main site if there are any new posts and if there are insert it into the DB. Ive got them on 2 separate hosts so i don't want to just read from the DB increase the main site goes down and brings the whole 2nd site down. What would be the easiest way to do it? Not looking for people to give code, Just their suggestions. Cheers hey forum people can you help me on one problem so i have script what should update mysql table by username Code: [Select] UPDATE data SET username='$name' WHERE value1='$value1' AND value2='$value2' AND value3='$value3' AND value4='$value4' AND value5='$value5'any ideas ? I'm pretty inexperienced with coding and trying to get a row of a MySQL database to update when a form is submitted, but can't seem to get it to work. Here's what I have... Code: [Select] if($_POST['action'] == 'update'){ //update $rename = $_POST['rename']; $uid = $_POST['rowid']; mysql_query("UPDATE `master` SET `name` = '$rename' WHERE `id` = '$uid'"); } Then the form... Code: [Select] <?php $result = mysql_query("SELECT * FROM `master`"); if(mysql_num_rows($result)){ while ($row = mysql_fetch_array($result)){ ?> <td><?php echo $row['name']; ?></a></td> <td><input type="text" size="5px" name="rename" value="" /></td> <td><input type="hidden" name="rename" value="<?php echo $row['name']; ?>" /><input type="hidden" name="rowid" value="<?php echo $row['id']; ?>" /><input type="hidden" name="action" value="update" /><input type="submit" value="Update" /></td> </tr> <?php } } ?> Can anyone give me some hints as to why this won't work? Thaks! I have made a thread earlier but i did not get any help. changeapp.php Code: [Select] <form method="post" name="memberadd" action="change_app_complete.php"> <label>Name:</label> <select name="member"> <?php $con = mysql_connect("host","user","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database",$con); $sqlquery="SELECT * FROM `application` Order By Name"; $result=mysql_query($sqlquery,$con); while($row=mysql_fetch_array($result)) { echo "<option value='".$row['ID']."'>".$row['Name']." (".$row['Status'].")</option>"; } ?> </select> <br> <label>Status:</label> <select name="Status"> <option value="PENDING">PENDING</option> <option value="ACCEPTED">ACCEPTED</option> <option value="DENIED">DENIED</option> <br> <input type="submit" value="submit" /> </form> change_app_complete.php Code: [Select] <?php $status=$_POST['Status']; $member=$_POST['Name']; $con = mysql_connect("host","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database",$con); $sql="UPDATE application SET Status = '$status' WHERE Name= '$member'"; if(mysql_query($sql,$con) or die(mysql_error())) { echo 'Status Changed.<br /><a href="../applications.php">Return To Members List</a>'; } else { die('Could not submit: ' . mysql_error()); } mysql_close($con); ?> This does not return any errors and does not change the Status... ---- I can not do this : $sql = mysql_query("UPDATE myMembers SET email_activated='1' WHERE id='$id' AND password='$hashpass'"); ---- i get this: $msgToUser = "<br /><br /><h3><strong><font color=red>Your account could not be activated!</font></strong><h3><br /> <br /> Please email site administrator and request manual activation. "; thanks guys ok so here is whats going on i have this small little php to update one thing in a table but it's not updating the mysql_error is 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 'check=1 WHERE id='21'' at line 1 what is the prob because i spent a hour on this and cant git it? here is the php Code: [Select] <?php include '../config.php'; $id = $_GET['del']; mysql_query("UPDATE call_list SET check=1 WHERE id='$id'")or die(mysql_error()); header("Location: index.php"); ?> I am moving my website to a new Service Provider. The script I use for multiple updating worked on the older server but not on the new one. It shows the information but does not update the records. Any help would be greatly appreciated. Old Server : PHP 5.2.11 MYSQL: 5.0.92-community New Server : PHP 5.2.17 MYSQL: 5.1.47-community Script: <?php include("head.php"); $host="localhost"; // Host name $username="xxxxxxx"; // Mysql username $password="xxxxxxx"; // Mysql password $db_name="xxxxxxx"; // Database name $tbl_name="xxxxxxx"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name limit 20"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <title>PowerMan South Africa</title> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <META HTTP-EQUIV="Expires" CONTENT="-1"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="style.css" type="text/css" media="screen" /> <style type="text/css" media="screen,projection"> @import url(calendar.css); </style> </head> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>ID</strong></td> <td align="center"><strong>Company</strong></td> <td align="center"><strong>contact</strong></td> <td align="center"><strong>Email</strong></td> <td align="center"><strong>Telephone</strong></td> <td align="center"><strong>Type</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td> <td align="center"><input name="company[]" type="text" id="company" value="<? echo $rows['company']; ?>"></td> <td align="center"><input name="contact[]" type="text" id="contact" value="<? echo $rows['contact']; ?>"></td> <td align="center"><input name="email[]" type="text" id="email" value="<? echo $rows['email']; ?>"></td> <td align="center"><input name="telephone[]" type="text" id="telephone" value="<? echo $rows['telephone']; ?>"></td> <td align="center"><input name="type[]" type="text" id="type" value="<? echo $rows['type']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE $tbl_name SET company='$company[$i]', contact='$contact[$i]', email='$email[$i]',type='$type[$i]', telephone='$telephone[$i]' WHERE id='$id[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:update_multiple.php"); echo "<meta http-equiv=Refresh content=0;url=update_multiple.php>"; } mysql_close(); ?> |