General Community > Scripting Help

UPDATE query not updating the database

(1/3) > >>

Les Mackenzie:
I have a bit of stubborn code that doesn't seem to want to update properly in mySQL...  I have verified that the variables are being passed down the script just they are not being updated in the end.

--- Code: --- $a_row = mysql_fetch_object($result);

      // print form with values pre-filled
?>
<form action="<? echo $PHP_SELF; ?>" method="POST">
<p style="margin-top: 0; margin-bottom: 0">
<input size="24" maxlength="250" type="text" name="duration" value="<? echo $a_row->duration; ?>"> &nbsp;&nbsp;Duration <b>x weeks[mm/dd - mm/dd]</b></p></form>
<?

--- End code ---

The rest of the variables are plugged in similar to the above code.

Here is my SQL statement - No Error, it just doesn't update the database?

--- Code: ---// generate and execute query
      $query = "UPDATE resource SET slug = '$slug', content = '$content', contact = '$contact', timestamp = NOW(), duration = '$duration', startdate = '$startdate', time = '$time', cost = '$cost', day = '$day' WHERE id = '$id'";
      $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());


--- End code ---

I added statements like echo $slug and verified the form data is available, it just doen't update.

Any help from anyone would help at this point.  Thanks

Tyris:
hmmmm... dunno if it'll be the problem... but try replacing your single quotes with the angled single quotes...
ie:
'
to
`
or perhaps putting ` around the values being set... so `slug` = '$slug' (<-- I think that should work)
(I've had some dodgy probs like this with just as dodgy solutions)

Les Mackenzie:
nope...  still doesn't seem to wanna work.  Oh and when you ' ' the field name in gives you an error in syntax...

Shadow:
I can't see anything wrong with it, yet... but I thought of something. Is that running inside of a function? And is register globals on? then I might think because there are spaces in in the query for, something = '$something' but spaces don't seem to do anything in PHP so I don't think that's it... so... Unknown!!!

Aquilo:
this might work don't know!


--- Code: ---// generate and execute query
   $result = mysql_query("
      UPDATE resource
      SET slug='$slug', content='$content', contact='$contact', timestamp='" . NOW() . "', duration='$duration', startdate='$startdate', time='$time', cost='$cost', day='$day'
      WHERE id='$id'") or die ("Error in query: $query. " . mysql_error());
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version