why this update isnt working?

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
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

why this update isnt working?

Post by pelegk2 »

Code: Select all

<?php
UPDATE  table tblPrint set PrinterNum='1' where OrderNum='313.5'
?>
???
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

UPDATE table?

Sounds wierd to me. Try this instead:

Code: Select all

UPDATE tblPrint SET PrinterNum='1' WHERE OrderNum='313.5'
-Nay
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

still isnt working

Post by pelegk2 »

and i dont have a clue why!
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Try the query in phpmyadmin or something. See error that returns.

-Nay
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

syntax is wrong

Code: Select all

UPDATE yourtable SET whatever='whatever' WHERE whatever='whatever'
Last edited by m3mn0n on Mon Dec 15, 2003 4:40 am, edited 2 times in total.
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

i did so

Post by pelegk2 »

there is no error just not updating :(
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

In the query function use or die(mysql_error()).

btw see: http://www.mysql.com/doc/en/UPDATE.html
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

i have a strange thing

Post by pelegk2 »

the problem starts with the insert
the values are inserted but
when i on the mysql do a select i got an empty line!!!!!!!!!
why can that be?
this is my insert

Code: Select all

<?php
$query2="INSERT INTO tblPrint ('OrderNum','PrinterNum','DateTime') Values('$orderN','$radio','2003-12-15 10:25:33')";
		$result2 = mysql_query ($query2) or die ($query2);
?>
Arulraj
Forum Newbie
Posts: 10
Joined: Sun Dec 14, 2003 11:41 pm
Location: India

Post by Arulraj »

while doing insert there is no need of giving ('OrderNum','PrinterNum','DateTime') instead give

$query2="INSERT INTO tblPrint (OrderNum,PrinterNum,DateTime) Values('$orderN','$radio','2003-12-15 10:25:33')";

This should work

Bye.
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

this is the problem :
when i do this :
$query1="select OrderNum from tblPrint where OrderNum='$orderN'";
$result1 = mysql_query ($query1) or die ($query1);
$tmpDateTimeVal=date("Y-m-d H:i:s");
if (mysql_affected_rows()){ // the order already in DB
//echo "in table";
$query2="UPDATE tblPrint set PrinterNum='$radio',DateTimeVal='$tmpDateTimeVal' where OrderNum='$orderN'";
$result2 = mysql_query ($query2) or die (mysql_error());
}else{ // need to write the order for the first time
//echo "not in table";
$query2="INSERT INTO tblPrint (OrderNum,PrinterNum,DateTimeVal) Values('$orderN','$radio','$tmpDateTimeVal')";
$result2 = mysql_query ($query2) or die (mysql_error());
}

and $orderN=313.34 and $radio=1
and then i check the mysql
i see this line :
31.34 1 2003-12-15 14:38:39
first it cuts!!!!!!! the number i dont know why!
and secondly when on mysql oi do a select on
"31.34" as show or on "313.34" i get that there are no records although i see them with my own eyes!!!!!!!!!
what is going on?
i see
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

What is the exact data type of ordernum?
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

ordernum=varchar(8)
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

ordernum=varchar(8)
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

ordernum=varchar ( 8 )
Post Reply