johnbruce Posted April 18, 2007 Share Posted April 18, 2007 I have written a simple script to allow a user to search for a record in a mysql database which returns it in a html form. What i'm trying to get the form to do is allow the user to edit the record in the form and update it live. I have the following code in my update.php page; <? $username="t; $password=""; $database="; mysql_connect(localhost,$username,$password); mysql_query("UPDATE gosscustomers SET title = '$ud_title' WHERE id = '$ud_id' "); mysql_query($query); mysql_close(); ?> <html> <style type="text/css"> <!-- .style3 { font-size: large; font-weight: bold; } --> </style> <body> <table width="1230" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td height="83" colspan="4" valign="top"><p><strong><br /> <br /> </strong>The following record has been successfully changed in the Goss database: <br /> <br /> </p></td> <td width="734"> </td> </tr> <tr> <td width="160" height="20" valign="top"><strong>Title:</strong></td> <td width="189" valign="top"><? Print $ud_title; ?> </td> <td width="46" valign="top"><strong>ID:</strong></td> <td width="101" valign="top"><? Print $ud_id; ?></td> <td> </td> </tr> <tr> <td height="20" valign="top"><strong>First Name:</strong></td> <td valign="top"><? Print $ud_first_name; ?></td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td height="20" valign="top"><strong>Surname:</strong></td> <td valign="top"><? Print $ud_surname; ?></td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td height="20" valign="top"><strong>Company:</strong></td> <td valign="top"><? Print $ud_company; ?></td> <td></td> <td></td> <td></td> </tr> <tr> <td height="20" valign="top"><strong>Address Line 1: </strong></td> <td valign="top"><? Print $ud_address_1; ?></td> <td></td> <td></td> <td></td> </tr> <tr> <td height="20" valign="top"><strong>Address Line 2: </strong></td> <td valign="top"><? Print $ud_address_2; ?></td> <td></td> <td></td> <td></td> </tr> <tr> <td height="20" valign="top"><strong>Address Line 3: </strong></td> <td valign="top"><? Print $ud_address_3; ?></td> <td></td> <td></td> <td></td> </tr> <tr> <td height="20" valign="top"><strong>Postcode:</strong></td> <td valign="top"><? Print $ud_postcode; ?></td> <td></td> <td></td> <td></td> </tr> <tr> <td height="20" valign="top"><strong>Country:</strong></td> <td valign="top"><? Print $ud_country; ?></td> <td></td> <td></td> <td></td> </tr> <tr> <td height="20" valign="top"><strong>Email Address: </strong></td> <td valign="top"><? Print $ud_email_address; ?></td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td height="83"></td> <td></td> <td></td> <td></td> <td></td> </tr> </table> </body> </html> The code is writng the edit values to this page as when i use Print "$ud_title;" it prints the edited title from the form, but for some reason it's not writing these values back to the database. Any ideas??? Link to comment https://forums.phpfreaks.com/topic/47532-solved-not-writing-back-to-mysql-database/ Share on other sites More sharing options...
johnbruce Posted April 18, 2007 Author Share Posted April 18, 2007 Figured it out, i missed out the; @mysql_select_db($database) or die( "Unable to select database"); Can't believe none of the guys on here spotted that ??? Link to comment https://forums.phpfreaks.com/topic/47532-solved-not-writing-back-to-mysql-database/#findComment-232024 Share on other sites More sharing options...
shaymol Posted April 18, 2007 Share Posted April 18, 2007 Hi jonbruce following may be happen with your code : 1. your mysql_connect first param must be under quote (ex : mysql_connet('host',$ursr,$paswd)) 2. make sure that you are getting the $ud_id correctly 3. you can run the query in mysql manually as it works on there or not 4. if it works well there than it will work here also , otherwise you can modify your query with the following : mysql_query("UPDATE gosscustomers SET title = '$ud_title' WHERE id = $ud_id "); Thanks Shaymol Link to comment https://forums.phpfreaks.com/topic/47532-solved-not-writing-back-to-mysql-database/#findComment-232029 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.