Mikesag Posted March 9, 2013 Share Posted March 9, 2013 (edited) Been racking my brains for 11 hours now trying to figure out why this script is not updating my 3 values to mysql can be viewed here http://xrb.me/softwareconnect/list_records.php // listrecords.php ''**************************************************************** <?php $hostname="private"; // Host name $username="dbmikesecure"; // Mysql username $password="private"; // Mysql password $database="dbmikesecure"; // Database name $tbl_name="Data"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $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>Data List </strong> </td> </tr> <tr> <td align="center"><strong>Word1</strong></td> <td align="center"><strong>Word2</strong></td> <td align="center"><strong>Word3</strong></td> <td align="center"><strong>Update</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><? echo $rows['word1']; ?></td> <td><? echo $rows['word2']; ?></td> <td><? echo $rows['word3']; ?></td> // link to update.php and send value of id <td align="center"><a href="update.php?Id=<? echo $rows['Id']; ?>">update</a></td> </tr> <?php } ?> </table> </td> </tr> </table> <?php mysql_close(); ?> // update.php ''**************************************************************** <?php $hostname="private"; // Host name $username="dbmikesecure"; // Mysql username $password="private"; // Mysql password $database="dbmikesecure"; // Database name $tbl_name="Data"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // get value of id that sent from address bar $id=$_GET['id']; // Retrieve data from database $sql="SELECT * FROM $tbl_name 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</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>Word1</strong></td> <td align="center"><strong>Word2</strong></td> <td align="center"><strong>Word3</strong></td> </tr> <tr> <td> </td> <td align="center"><input name="word1" type="text" id="word1" value="<? echo $rows['word1']; ?>"></td> <td align="center"><input name="word2" type="text" id="word2" value="<? echo $rows['word2']; ?>" size="15"></td> <td><input name="word3" type="text" id="word3" value="<? echo $rows['word3']; ?>" 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> <? // close connection mysql_close(); ?> // update_ac.php ''**************************************************************** <?php $hostname="private"; // Host name $username="dbmikesecure"; // Mysql username $password="private"; // Mysql password $database="dbmikesecure"; // Database name $tbl_name="Data"; // Table name // Connect to the database mysql_connect($hostname, $username, $password) OR DIE("Unable to connect"); mysql_select_db("$database") or die("Unable to select database"); $query="UPDATE Date SET word1='" . $_POST['word1'] . "', word2='" . $_POST['word2'] . "', word3='" . $_POST['word3'] . "' WHERE id='" . $_POST['$Id'] . "'"; $checkresult = mysql_query($query); if ($checkresult) echo 'update query succeeded'; else echo 'update query failed'; mysql_close(); ?> Edited March 16, 2013 by fenway code tags Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 9, 2013 Share Posted March 9, 2013 (edited) 1. Please use code tags so we can read the code better. 2. You're not checking for mysql errors. See my signature. 3. Don't use user input without sanitizing it. 4. Don't put quotes around variables in PHP, or numbers in MySQL 5. Date is a reserved word, you should pick a different name for your table or use ` around it. Edited March 9, 2013 by Jessica Quote Link to comment Share on other sites More sharing options...
Mikesag Posted March 10, 2013 Author Share Posted March 10, 2013 (edited) if i change the query to this $query="UPDATE `Data` SET `word1`='$word1' WHERE `id`=1"; in update_ac.php then its does not update the value but if i put this without the $ sign, at least it places the actual word,, (word1), lol,, in the database,, $query="UPDATE `Data` SET `word1`='word1' WHERE `id`=1"; so i think the problem is that the update.php page is not sending the update_ac.php page the value ? can you check this for me,, ive been trying to send the value on my side but cant seem to do it,, Edited March 10, 2013 by Mikesag Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 10, 2013 Share Posted March 10, 2013 Sounds like the variable isn't defined. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted March 11, 2013 Share Posted March 11, 2013 Have you checked if your variables contain values? The var_dump() function can help there: http://php.net/var_dump Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.