Valid query statement not updating db

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Valid query statement not updating db

Post 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?
:?:
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

DESC is a reserved word - see mysql manual for a full list.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

Post by penguinboy »

You can accually use desc,
but you would have to put `s around it.

`desc`
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

That's good to know too, but I changed the table name to "Descr"
Worked like magic.
Post Reply