Jump to content

[SOLVED] Problem with UPDATE command


shotokan

Recommended Posts

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

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/80550-solved-problem-with-update-command/
Share on other sites

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");

?>

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());

 

?>

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>";

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 ='[email protected]', posttxt ='Testing to see if this is working...', WHERE postid ='2'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.