Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-23-2012, 04:35 PM   PM User | #1
JohnnyLee
New to the CF scene

 
Join Date: Feb 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
JohnnyLee is an unknown quantity at this point
Unhappy PHP - MySQL error

i'm trying to move/migrate old web application for a client of mine to latest versions of MySQL and PHP.

i'm having problems fixing this error:

There was a problem adding the initial timeframe to the database. Please inform the System Administrator. Insert failed

There was a problem logging this transaction. Please print out this page and inform the System Administrator.
Insert failed : INSERT INTO log VALUES( 0, "2012-02-23 16:22:41", "job", , "root", "1005,380,\'open\',\'2012-02-23 16:22:41\',\'root\',\'2012-02-23 16:22:41\',\'root\',\'\',\'lab\',\'\'", "added")


the code behind this is this:

PHP Code:
$insert_t0 mysql_db_query("databaseName""INSERT INTO timeframe VALUES (0,$new_int_job_no,\"T0\",1)")
    or print (
"<p><font face=\"Verdana, Arial, Helvetica, sans-serif\">There was a problem adding the initial timeframe to the database.  Please inform the System Administrator.  Insert failed\n</font>\n");

  
$added_data "$cust_to_edit,$new_job_no,\'open\',\'$datetimenow\',\'$login\',\'$datetimenow\',\'$login\',\'$jobinit_ponum\',\'lab\',\'\'";

  
$query "INSERT INTO log VALUES(
    0,
    \"$datetimenow\",
    \"job\",
    $new_int_job_no,
    \"$login\",
    \""
.$added_data."\",
    \"added\")"

i'm guessing this is something to do with the SQL syntax.

any help would be much appreciated
Johnny
JohnnyLee is offline   Reply With Quote
Old 02-23-2012, 05:26 PM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,500
Thanks: 44
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Why are you using double quotes? - You're getting very confused about their usage and the difference between PHP and mysql's use of quote marks.

This is how you should do it:
PHP Code:
$query "INSERT INTO log VALUES(
    0,
    '$datetimenow',
    'job')"
;  //Etc 
Your query is already inside double quotes. Therefore the $Variables will still be replaced with their values inside the single quotes.

For mysql, you always wrap values in single quotes and optionally wrap column names in backticks ` (which you've not specified in your query btw - insert into <table> (`columns`) values ('$Values');

In php anything inside single quotes (unless inside a double quoted string) will be exactly as you see it:

PHP Code:
$Name 'Joe Bloggs';

//Single quotes:
$Str 'Name is $Name'// Name is $Name

$Str "Name is $Name"// Name is Joe Bloggs

$Query "insert into <table> (`column`) values ('$Name')"//insert into <table> (`column`) values ('Joe Bloggs') 
For more information, see the Quotes tip in my signature.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 02-23-2012, 05:45 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
What's with all of these escapes? The $query itself needs to be escaped or swapped to use single quotes (on either the fields or the variable itself), but the $added_data is escaping when it should not be. Change the outside " to '. Since these are inserted fields, the location where $added_data is used should not be quoted.

Given the text output you have above, you need to do some verification of your data as well. , in the middle without any data should be using NULL, assuming that it allows null values of course.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
error, myslq, php, syntax

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:37 AM.


Advertisement
Log in to turn off these ads.