Jump to content

syntax error message because of an apostrophe


contra10

Recommended Posts

hello, i keep getting a syntax error message when I try to display my data from my database, heres the code that i use fo veiwing the data

 

<?php
$alb = mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("programs") or die(mysql_error()); 

mysql_set_charset('utf8', $alb); 

$query = "SELECT * FROM `canpro` WHERE `directory` = '$sub' ORDER BY area, school ASC";
$result = mysql_query($query) or die(mysql_error());

while ($postede = mysql_fetch_assoc($result))
{
$area = "{$postede['area']}";
$dn = "{$postede['dn']}";
$dl = "{$postede['dl']}";

echo "<font size='3'><b>$school</b></font><br>";
echo "<font size='2'><b>$dn</b></font><br><font size='2' color = '#3B5998'><b>$dl</b></font><br>";

mysql_select_db("schools") or die(mysql_error()); 
$query2 = "SELECT * FROM `canschools` WHERE `name` = '$area'";
$result2 = mysql_query($query2) or die(mysql_error());

while ($postede2 = mysql_fetch_assoc($result2))
{
$city = "{$postede2['city']}";
$area2 = "{$postede2['area']}";
echo "<font size='2'><b>$city, $area2</b></font><br><br>";
}
}
?>

 

The display message i get is

 

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 's Calender'' at line 1

 

it shows all my information except when the word contains an apostrohpe then it doesn't shows the error and all the information afterwords won't get displayed

Link to comment
Share on other sites

Yes, the single quote is still present in the string, and it will break the query, as you've seen. It's important to understand that the backslashes inserted when the data is escaped are not (and should not be) stored with the data. Therefore you need to escape the data again if you want to use it in another query string.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.