• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

varia ble problem

when i  run the code below it not work but when I cahnge $Code02 to 12423 it work  But I try to check value of $Code02 by echo it get  12423


The code that not work

if($submit04)
{
echo $Code02 ;
include ("aut.inc");
$link_id1 = db_connect($default_dbname);

$sql = "UPDATE `sellhead`
                  SET `PayDate` ='$datedue01'

              WHERE Code= '$Code02' ";

$result = mysql_query($sql,$link_id1);
mysql_close($link_id1);


After I change  $Code02 to 12423  it can up date database

$sql = "UPDATE `sellhead`
                  SET `PayDate` ='$datedue01'

              WHERE Code= '12423 ' ";
 
0
teera
Asked:
teera
  • 3
  • 2
  • 2
  • +2
4 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
are there any spaces in the variable?

echo "(" . $Code02 . ")" ;

what data type is the field Code?

please try without the single quotes:
$sql = "UPDATE `sellhead`
                  SET `PayDate` ='$datedue01'
              WHERE `Code`= $Code02 ";

0
 
teeraAuthor Commented:
the data type of feild Code is double
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Did you try my 2 suggestions?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
teeraAuthor Commented:
yes i try it not work

The feild PayDate is date  
and varia ble $datedue01 like 20060519

I try but  it put  0000-00-00 00:00:00 in field PayDate
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
The the problem is the $datedue01 variable, which needs to be in this format: 1997-10-04 22:23:00

$datedue01 = '2006-05-19';

and the query will work
0
 
aminerdCommented:
Try putting var_dump($sql); on the line right before you execute the query. Then paste what's printed here.
0
 
topscoderCommented:
and to create a date like 1997-10-04 22:23:00 you could use the date() function of PHP:

<?php

$today = date("Y-m-d H:i:s");

?>
0
 
jmar_clickCommented:
remove the single quotes around the variable, non text fields dont need single quotes
0
 
aminerdCommented:
"The the problem is the $datedue01 variable, which needs to be in this format: 1997-10-04 22:23:00"

MySQL defaults invalid dates to 0000-00-00 [00:00:00]. So the insert should still WORK, but the date would be in the table incorrectly. Second, if he has a date column, and not a datetime column, he doesn't need to specify the time. Third, '20060519' is correctly interpreted as '2006-05-19' by MySQL:

mysql> insert into test values ('20060504');
Query OK, 1 row affected (0.00 sec)

mysql> select * from test;
+------------+
| date       |
+------------+
| 2006-05-04 |
+------------+

"remove the single quotes around the variable, non text fields dont need single quotes"

But it doesn't BREAK anything either. MySQL will insert a quoted numeric value into a numeric field without a problem.

Neither of these would cause the query to completely break.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now