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

?>

Link to comment
Share on other sites

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

 

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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'

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.