Wrox Programmer Forums
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 10th, 2004, 01:02 AM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default MySQL query

Hi,I want update my record into the dbase. When i run at browser it display error msg.
I have test the script,it can function but when I copy it in other system get error.
So, what problem? I also have try change the script to prod_id= '$_POST[prod_id]', it stil can't function.:(

Attche code:
//create connection
$conn = mysql_connect("localhost", "phpuser","") or die (mysql_error());

//select dbase
$db = mysql_select_db("prod", $conn) or die (mysql_error());

//Formulate and execute the query
$sql = "UPDATE product SET
    prod_id='$prod_id',
    b_type='$b_type',
    desc='$desc',
    cust_id='$cust_id',
    person= '$person',
    mod='$mod'
    WHERE prod_id='$prod_id'";
$result = mysql_query($sql, $conn)or die(mysql_error());

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 'desc= '', cust_id= '', person= '', mod= '' WHERE prod_i

Thanks in advance.

 
Old June 10th, 2004, 01:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

Not sure, but it might be because DESC (descending) is a reserved word in SQL.
You would normally use it in an ORDER BY clause, as in

SELECT * FROM product ORDER BY prod_id DESC

 
Old June 10th, 2004, 01:32 AM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

Hi Jonax,

Yes, you're right. desc is reserved word.
Now, it can function. :)
Thanks for your help.



 
Old June 10th, 2004, 01:45 AM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

Hi Jonax,

The system can run and don't have error BUT it can't UPDATE the new data in dbase.
So, what's wrong?

Thanks in advance.

 
Old June 10th, 2004, 01:56 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Did you try print these variable's values, if all has something in it?

$prod_id
$b_type
$desc
$cust_id
$person
$mod
$prod_id

Cheers!

_________________________
-Vijay G
Strive for Perfection
 
Old June 10th, 2004, 02:10 AM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

I write in this way, can?

Attach code:

<?php
//function
    function check(&$var)
    {
        return (isset($var))? $var :'';
    }

    echo" <br><b>\n".
        " ".check($_POST['prod_id'])."\n".
        " </b>\n".
        " - The product has been updated to the database.\n".
        " <p> </p>\n".
        " <table width='45%' border='1'>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Product ID:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['prod_id'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Board Type:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['b_type'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Description:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;\n".
        " </td>\n".
        " <td>\n";
?>
             <textarea name='descp' cols='80' rows='5' id='desc'><? echo "".check($_POST['descp'])."\n"; ?></textarea>

<?php
     echo " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Customer ID:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['cust_id'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Last Person:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['person'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Last Modified:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['mod'])."\n".
        " </td>\n".
        " </tr>\n".
        " </table>\n";
?>

The problem is the system can't store updated record in dbase but it can display at interface. So, at first I though it already save in dbase,but when I refer to dbase, actually they not save!

Thanks in advance.

 
Old June 10th, 2004, 02:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I am not sure, if you mean that the DB has updated value but the page does not get the updated values.

If that is what you mean, are you re-querying the data from the database, once after UPDATE is successful?

Cheers!

_________________________
-Vijay G
Strive for Perfection
 
Old June 10th, 2004, 02:36 AM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

No, is the page can display and get the updated values. Dbase still store the old value. That mean UPDATE is not successful.
So, what's the problem?

Thanks in advance.

 
Old June 10th, 2004, 02:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:The problem is the system can't store updated record in dbase but it can display at interface. So, at first I though it already save in dbase,but when I refer to dbase, actually they not save!
Then how come you say your code works fine to show updated values, when the DB does not have the updated ones.

There should be something wrong with your UPDATE query. Can you check that by printing the UPDATE query on the page before running the UPDATE from your page onto database. Then copy that code and execute it directly on database, see if that errs.

Something should be missing for sure.

Or there should be no records matching the WHERE clause

Or $prod_id should hold empty value when you try to run the UPDATE.

Also I suspect, if the prod_id an INTEGER/NUMERIC type in your database. If so you should not use single QUOTEs around it in the where clause, which causes no records get updated in the DB.

Hope that helps.
Cheers!

_________________________
-Vijay G
Strive for Perfection
 
Old June 10th, 2004, 03:33 AM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

I have try, my UPDATE query can function, it doesn't display any error msg. I also have try execute the query at MySQL Control Center, it can function.

So, I really don't know what's wrong!!

Please give me advise and help to solve this problem.

Thanks in advance.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Mysql query...Pls help me raaj MySQL 2 March 17th, 2007 12:43 AM
MySQL syntax in query Tachyon Beginning PHP 1 June 26th, 2004 08:42 PM
Impossible MySQL Query? mrcornelia SQL Language 4 November 18th, 2003 03:08 AM
Random MySQL Query cmiller Beginning PHP 5 November 18th, 2003 12:44 AM
MySQL Query Problem cmiller Beginning PHP 4 August 26th, 2003 12:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.