Page 1 of 1

Valid query statement not updating db

Posted: Mon Feb 09, 2004 8:44 am
by Bill H
This code:

Code: Select all

<?php
include "db_connect.php";

if (isset($_POST['Recno']))         // user has approved data input
{
     $Query = "UPDATE Exprec SET Desc='" . addslashes($_POST['Desc']) . "'";

     if (isset($_POST['Qty']))
          $Query .= ",Qty=" . $_POST['Qty'];

     if (isset($_POST['Amt']))
     {    $Pamt = 0.00 + $_POST['Amt'];
          $Query .= ",Amt=$Pamt";
     }
     $Query .= " WHERE id=" . $_POST['Recno'];

     mysql_query($Query, $Link);
     echo "<script>onload=function(){opener.location.reload(true);self.close()}</script>";
     exit;
}
?>
is not updating the record. Here's the generated Query Statement:
UPDATE Exprec SET Desc='reports generated',Qty=14,Amt=8.5 WHERE id=2
Desc is a varchar column, Qty & id are ints, and Amt a decimal. The include file connects to the db and I know it works. The isset(...)) loop is executing, becuuse the window-closing script at the bottom of it is executing. The record number (id) is correct.

I've tried it with single quotes arounf the Amt and Qty values as well, even though it should not need them, and it is no help. I need another set of eyes -- what am I missing?
:?:

Posted: Mon Feb 09, 2004 9:04 am
by Bill H
While I was waiting for a reply a was doing further work on the project and I discovered the problem seems to be with the database itself -- the Desc column (varchar) will not allow a value to be either inserted or set. I see nothing (using phpmyadmin) that would cause that to be any sort of "read only" field, so why would it refuse entries made using sql statements?

Moderator, feel free to mpove this to the DB forum. I am not going to post this over there, assuming that you will move it. Don't want to create a double post.

Posted: Mon Feb 09, 2004 9:04 am
by McGruff
DESC is a reserved word - see mysql manual for a full list.

Posted: Mon Feb 09, 2004 9:10 am
by Bill H
As we say in the Deep South where I grew up:
Well, I swar.
All that brow beating, and in two minutes....

I should have come to you guys sooner, but I hate to abuse your hospitality.
:P

Posted: Mon Feb 09, 2004 12:56 pm
by penguinboy
You can accually use desc,
but you would have to put `s around it.

`desc`

Posted: Mon Feb 09, 2004 1:20 pm
by Bill H
That's good to know too, but I changed the table name to "Descr"
Worked like magic.