Jump to content

[SOLVED] Help editing rows


cs1h

Recommended Posts

Hi,

 

I have a script that is meant to be used to edit a row in a mysql table but its not doing it, I'm not getting any errors, its just not updating.

 

Can anyone help?

 

The script is

<?php

include "dog.php";

$email=$_POST['Email']; 
$name=$_POST['name']; 
$title=$_POST['title']; 
$id=$_POST['hiddenField'];
$Abs=$_POST['message']; 
$Art=$_POST['messagetwo']; 

mysql_connect("localhost", "zzz", "xxx") or die(mysql_error()) ; 
mysql_select_db("real") or die(mysql_error()) ; 

mysql_query(" UPDATE items
SET Email='$email', name='$name', title='$title', Abstract='$Abs', Article='$Art',  WHERE id='$id'");

echo "Changes made to $title.<br /> <a href='arteditor.php'>Click here</a> to return to the admin home.";

?>

 

Thanks

Colin

Link to comment
https://forums.phpfreaks.com/topic/74450-solved-help-editing-rows/
Share on other sites

Instead of...

 

<?php

  mysql_query(" UPDATE items
SET Email='$email', name='$name', title='$title', Abstract='$Abs', Article='$Art',  WHERE id='$id'");

?>

 

Use....

 

<?php

  $sql = "UPDATE items SET Email='$email', name='$name', title='$title', Abstract='$Abs', Article='$Art',  WHERE id='$id'";
  if (mysql_query($sql)) {
    echo "Success";
  } else {
    echo mysql_error() . "<br />$sql";
  }

?>

 

Now what do you get?

Thanks for the reply,

 

I made the changes surgested, but I now get the following error,

 

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 id=16' at line 1

UPDATE items SET Email='This is a system test', name='This is a system test ', title='This is a system test', Abstract='This is a system test ', Article='This is a system test ', WHERE id=16

 

The new script is

<?php

include "dog.php";

$email=$_POST['Email']; 
$name=$_POST['name']; 
$title=$_POST['title']; 
$id=$_POST['hiddenField'];
$Abs=$_POST['message']; 
$Art=$_POST['messagetwo']; 

mysql_connect("localhost", "zzz", "xxx") or die(mysql_error()) ; 
mysql_select_db("real") or die(mysql_error()) ; 

$sql = "UPDATE items SET Email='$email', name='$name', title='$title', Abstract='$Abs', Article='$Art',  WHERE id=$id";
 if (mysql_query($sql)) {
   echo "Success";
 } else {
   echo mysql_error() . "<br />$sql";
 }


?>


 

Any ideas why?

 

All help is very much appreciated.

 

Thanks

Colin

Done that but still no luck, I'm still getting the error

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 id = 16' at line 1

UPDATE items SET Email='This is a system test ', name='This is a system test ', Title='This is a system test ', Abstract='This is a system test ', Article='This is a system ', WHERE id = 16

 

Any more ideas, all help is appriciated.

 

Thanks

Colin

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.