Mikesag Posted March 9, 2013 Share Posted March 9, 2013 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(); ?> Link to comment https://forums.phpfreaks.com/topic/275448-really-need-help-on-php-form-to-update-3-mysql-values/ Share on other sites More sharing options...
Jessica Posted March 9, 2013 Share Posted March 9, 2013 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. Link to comment https://forums.phpfreaks.com/topic/275448-really-need-help-on-php-form-to-update-3-mysql-values/#findComment-1417764 Share on other sites More sharing options...
Mikesag Posted March 10, 2013 Author Share Posted March 10, 2013 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,, Link to comment https://forums.phpfreaks.com/topic/275448-really-need-help-on-php-form-to-update-3-mysql-values/#findComment-1417766 Share on other sites More sharing options...
Jessica Posted March 10, 2013 Share Posted March 10, 2013 Sounds like the variable isn't defined. Link to comment https://forums.phpfreaks.com/topic/275448-really-need-help-on-php-form-to-update-3-mysql-values/#findComment-1417770 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 Link to comment https://forums.phpfreaks.com/topic/275448-really-need-help-on-php-form-to-update-3-mysql-values/#findComment-1417945 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.