Jump to content

mySQL UPDATE function


a1amattyj

Recommended Posts

Hi,

 

Im currently in the process of making an administration panel. I want admins to be able to add comments to each "report". So, after submitting the text to a form, it directs to the following code..

 

<?
if($_GET['id'] && $_GET['comment'] && !$_GET['email'] && !$_GET['mail']){
require("config.php");
$id = $_GET['id'];
$query = "SELECT * FROM reports WHERE id='$id'";
$comments = $_POST['comments'];
$result = mysql_query("UPDATE reports SET admin_comments='$comments' WHERE comments='NULL'") 
or die(mysql_error());  
$row = mysql_fetch_array( $result );
}
?>

 

I get this error :

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/easyfor1/public_html/report/admin/report_list.php on line 454

 

 

Finally, is it possible that the update ADD's to what is already in the field?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/91323-mysql-update-function/
Share on other sites

You get an error because you can't fetch an array from an update query.

 

if you want to add to whats there

$id = $_GET['id'];
$query = "SELECT * FROM reports WHERE id='$id'";
$res = mysql_query($query) or die(mysql_error());
$r = mysql_fetch_assoc($res);
$comments = stripslashes($r['admin_comments'];
$comments .= "\n ".addslashes($_POST['comments']);
$result = mysql_query("UPDATE reports SET admin_comments='$comments' WHERE comments='NULL'") or die(mysql_error()); 

 

Ray

 

Link to comment
https://forums.phpfreaks.com/topic/91323-mysql-update-function/#findComment-468016
Share on other sites

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.