By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,304 Members | 1,254 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,304 IT Pros & Developers. It's quick & easy.

Syntax Problem

P: n/a
I have the following PHP/MySQL code segment

$query2="UPDATE reports
SET fsacars_rep_url = $url_new
WHERE pilot_id = $pid";

echo"$query2";

$result2=mysql_query($query2) or die(mysql_error());

The above code produces the following messages:

The echo of the query shows:
UPDATE reports SET fsacars_rep_url = http://69.72.192.154/
~caa/caa/logbooks/no_rept.txt WHERE pilot_id = 2

When the query runs the following error message is generated:
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
'://69.72.192.154/~caa/caa/logbooks/no_rept.txt WHERE pilot_id = 2' at line
2

What is the proper syntax?

Thanks,
Tom
May 9 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Call Me Tom" <no****@devnull.spamcop.netwrote in message
news:z7q0i.9619$pW5.3833@trnddc07...
>I have the following PHP/MySQL code segment

$query2="UPDATE reports
SET fsacars_rep_url = $url_new
WHERE pilot_id = $pid";

echo"$query2";

$result2=mysql_query($query2) or die(mysql_error());

The above code produces the following messages:

The echo of the query shows:
UPDATE reports SET fsacars_rep_url = http://69.72.192.154/
~caa/caa/logbooks/no_rept.txt WHERE pilot_id = 2

When the query runs the following error message is generated:
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
'://69.72.192.154/~caa/caa/logbooks/no_rept.txt WHERE pilot_id = 2' at
line
2

What is the proper syntax?
I don't know but my guess is that you need to put ' ' on your variables,

$query2="UPDATE reports
SET fsacars_rep_url = '$url_new'
WHERE pilot_id = '$pid';";


May 9 '07 #2

P: n/a
At Wed, 09 May 2007 20:26:07 +0000, Call Me Tom let his monkeys type:
I have the following PHP/MySQL code segment

$query2="UPDATE reports
SET fsacars_rep_url = $url_new
WHERE pilot_id = $pid";

echo"$query2";

$result2=mysql_query($query2) or die(mysql_error());

The above code produces the following messages:

The echo of the query shows:
UPDATE reports SET fsacars_rep_url = http://69.72.192.154/
~caa/caa/logbooks/no_rept.txt WHERE pilot_id = 2

When the query runs the following error message is generated:
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
'://69.72.192.154/~caa/caa/logbooks/no_rept.txt WHERE pilot_id = 2' at line
2

What is the proper syntax?

Thanks,
Tom
Tom,

Using strings in MySQL queries, enclose them in quotes:

$query2="UPDATE reports
SET fsacars_rep_url = '$url_new'
WHERE pilot_id = $pid";

// add quotes around $pid as well if it's a character field, not if it's a
numerical value in the db.

HTH
Sh
May 9 '07 #3

P: n/a
Schraalhans Keukenmeester <in*****@invalid.spamwrote in
news:pa****************************@invalid.spam:
At Wed, 09 May 2007 20:26:07 +0000, Call Me Tom let his monkeys type:
>I have the following PHP/MySQL code segment

$query2="UPDATE reports
SET fsacars_rep_url = $url_new
WHERE pilot_id = $pid";

echo"$query2";

$result2=mysql_query($query2) or die(mysql_error());

The above code produces the following messages:

The echo of the query shows:
UPDATE reports SET fsacars_rep_url = http://69.72.192.154/
~caa/caa/logbooks/no_rept.txt WHERE pilot_id = 2

When the query runs the following error message is generated:
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 '://69.72.192.154/~caa/caa/logbooks/no_rept.txt WHERE pilot_id =
2' at line 2

What is the proper syntax?

Thanks,
Tom

Tom,

Using strings in MySQL queries, enclose them in quotes:

$query2="UPDATE reports
SET fsacars_rep_url = '$url_new'
WHERE pilot_id = $pid";

// add quotes around $pid as well if it's a character field, not if
it's a numerical value in the db.

HTH
Sh
Thanks. That solved the problem.

Tom
May 9 '07 #4

P: n/a
Call Me Tom wrote:
Thanks. That solved the problem.
But it will cause another (when $new_url contains a quote mark!)

This should be (more or less) indestructible:

$q2 = sprintf("UPDATE reports SET fsacars_rep_url='%s' WHERE pilot_id=%d;",
mysql_real_escape_string($url_new),
(int)$pid);

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux
May 10 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.