I'm trying to update existing data in a table, and can't quite seem to figure it out. Not at all sure what I'm doing wrong, and even less sure if the syntax remains the same in PHP4 as it would on the MySQL command line, but when I submit a form it won't update the data.
I've got the first script, update.php, pull the existing data from the database, calling it by the auto incrementing id, and that part works fine. It basically prints out the existing data in form boxes, allowing me to edit the data that is present. The contents of that script are as follows :
<?
$site = localhost;
$username = user;
$dbName = dbname;
if($id) {
mysql_connect($site, $username);
$result = mysql($dbName, "SELECT * from headlines where (id='$id')");
$num = mysql_numrows($result);
$i = 0;
while ($i < $num) :
$id = mysql_result($result,$i,"id");
$author2 = mysql_result($result,$i,"author");
$date = mysql_result($result,$i,"date");
$section2 = mysql_result($result,$i,"section");
$title2 = mysql_result($result,$i,"title");
$image = mysql_result($result,$i,"image");
$content2 = mysql_result($result,$i,"content");
print "<FORM ACTION='update2.php' METHOD='POST'>";
print "<TABLE BORDER='0'>";
print "<TR>";
print "<TD valign='top'>Story:</TD>";
print "<TD>";
print "<TEXTAREA NAME='content'";
print "SIZE='90'";
print "COLS='85'";
print "ROWS='25'";
print ">$content2</TEXTAREA></TD>";
print "</TR>";
print "<TR>";
print "<TD>Author:</TD>";
print "<TD>";
print "<SELECT NAME='author' SIZE=1>";
print "<OPTION VALUE='<A HREF=mailto:email1@domain.com>admin1</A>'>admin1";
print "<OPTION VALUE='<A HREF=mailto:email2@domain.com>admin2</A>'>admin2";
print "<OPTION VALUE='<A HREF=mailto:email3@domain.com>admin3</A>'>admin3";
print "<OPTION VALUE='<A HREF=mailto:email4@domain.com>admin4</A>'>admin4";
print "</SELECT>";
print "</TD>";
print "</TR>";
print "<TR>";
print "<TD>Title:</TD>";
print "<TD><INPUT TYPE 'text' NAME='title' SIZE='50' MAXLENGTH='50' VALUE='$title2'></TD>";
print "</TR>";
print "<TR>";
print "<TD>Section:</TD>";
print "<TD>";
print "<SELECT NAME='section' SIZE=1>";
print "<OPTION VALUE='headline'>Headline";
print "<OPTION VALUE='subject1'>subject1";
print "<OPTION VALUE='subject2'>subject2";
print "<OPTION VALUE='subject3'>subject3";
print "</SELECT>";
print "</TD>";
print "</TR>";
print "<TR>";
print "<TD> </TD>";
print "<TD><INPUT TYPE='submit' VALUE='Submit'></TD>";
print "</TR>";
print "</TABLE>";
print "</FORM>";
$i++;
endwhile;
};
?>
The second script, should be taking the new data, and updating the existing data with the new data that is entered. Its contents are as follows:
<?
$site = localhost;
$username = username;
$dbName = dbname;
$datestamp = (date(" F dS, Y"));
mysql_connect($site, $username);
MYSQL($dbName, "update headlines set title='$title',author='$author',section='$section',content='$content' where id=$id)");
print "Your information has been updated,<BR>";
mysql_close();
?>
This works properly on another set of forms, where I can enter the data into an empty form, hit submit, and the second script will INSERT that information into a database, and is properly called by another page. No problem, but for whatever reason, this just doesn't work. When I try the "update headlines set ..." part on the MySQL command line, it works perfectly, and I am able to modify the existing data. If anyone can help, it'll be much appreciated.
Thanks,
Barry