shotokan Posted December 7, 2007 Share Posted December 7, 2007 Hi, I'm very new to PHP and I've run into a problem that I'm hoping someone here can help me with. I'm creating a simple message board. My problem occurs when I try to edit postings. In the PHP I've got: $sql ="UPDATE $table_name SET posttitle ='{$_POST[posttitle]}', postername ='{$_POST[postername]}', posteremail ='{$_POST[posteremail]}', posttxt ='{$_POST[posttxt]}', WHERE postid ='{$_POST[postid]}'"; I tested this on the MySQL command line and it works fine. I can't get it working, however, in my php file. I'd greatly appreciate any help! In the HTML part I'm echoing variables: <p>The following information was successfully updated in <? echo "$table_name"; ?></p> <p>Name:</br> <? echo "$_POST[postername]"; ?></p> <p>E-Mail:<BR> <? echo "$_POST[posteremail]"; ?></p> <p>Post Title:<BR> <? echo "$_POST[posttitle]"; ?></p> <p>Post Text:<BR> <? echo "$_POST[posttxt]"; ?></p> Thanks, Kathleen Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted December 7, 2007 Share Posted December 7, 2007 Are you actually running the query? <?php $sql ="UPDATE $table_name SET posttitle ='{$_POST[posttitle]}', postername ='{$_POST[postername]}', posteremail ='{$_POST[posteremail]}', posttxt ='{$_POST[posttxt]}', WHERE postid ='{$_POST[postid]}'"; $query = mysql_query($sql)or die(mysql_error()."<p>With query:<br>$sql"); ?> Quote Link to comment Share on other sites More sharing options...
shotokan Posted December 7, 2007 Author Share Posted December 7, 2007 Yes, sorry I forgot to include that line. <?php $sql ="UPDATE $table_name SET posttitle ='{$_POST[posttitle]}', postername ='{$_POST[postername]}', posteremail ='{$_POST[posteremail]}', posttxt ='{$_POST[posttxt]}', WHERE postid ='{$_POST[postid]}'"; $result = @mysql_query($sql,$connection) or die(mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted December 7, 2007 Share Posted December 7, 2007 Okay, well change your code to this and tell us what it gives you <?php $sql ="UPDATE $table_name SET posttitle ='{$_POST[posttitle]}', postername ='{$_POST[postername]}', posteremail ='{$_POST[posteremail]}', posttxt ='{$_POST[posttxt]}', WHERE postid ='{$_POST[postid]}'"; $result = mysql_query($sql)or die(mysql_error()."<p>With query:<br>$sql"); echo "<p>$sql<p>"; Quote Link to comment Share on other sites More sharing options...
shotokan Posted December 7, 2007 Author Share Posted December 7, 2007 With the updated code I got the following: 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 'WHERE postid ='2'' at line 6 With query: UPDATE comtbl SET posttitle ='Testing', postername ='Joe Smith', posteremail ='joe@place.com', posttxt ='Testing to see if this is working...', WHERE postid ='2' Quote Link to comment Share on other sites More sharing options...
revraz Posted December 7, 2007 Share Posted December 7, 2007 See if removing the comma after posttxt ='{$_POST[posttxt]}', helps Quote Link to comment Share on other sites More sharing options...
shotokan Posted December 7, 2007 Author Share Posted December 7, 2007 Problem solved! The comma was the culprit. Thanks for your help revraz and pocobueno1388, your help is very much appreciated! 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.