Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Apostrophe in form data causes error.... 1

Status
Not open for further replies.

admoore

IS-IT--Management
May 17, 2002
224
US
Apostrophe in form data causes error....

Any solution for this???

TIA,

-Allen
 
Any form data that contains an apostrophe, like in the description if the poster were to type "driver's license" as part of the job description.... The record will not be written & the php code will return my error message that the query failed...

code is as follows:
Code:
$result = mysql_query("INSERT INTO vacancies
(`jobid`, `date`, `location`, `title`, `desc`, `contact`, `contact_phone`, `filled`)
VALUES
('',CURDATE(), '$location', '$title', '$desc', '$contact', '$contact_phone', 'n')",$dbcnx);

if ($result == TRUE)
{
   print (&quot;A new job vacancy was listed as follows:<br>&quot;.
          &quot;<b>$title<br>$location<br></b><p>$desc</p>&quot;.
          &quot;Contact: $contact at $contact_phone for more information.&quot;.
          &quot;<br><br>Your vacancy is now online.&quot;);
}
else
{
print (&quot;An <font color=\&quot;red\&quot;>error </font>has occured; please try
again.&quot;);
print (&quot;A new job vacancy was NOT listed for:<br><br>&quot;.
          &quot;<b>$title<br>$location<br></b><p>$desc</p>&quot;.
          &quot;Contact: $contact at $contact_phone for more information.&quot;.
          &quot;<br><br>&quot;);

}
mysql_close($dbcnx);
 
You should use addslashes on your variables before you use them in your query. You could also try setting the magic_quotes_gpc to on, if you have administrative access to the server. //Daniel
 
I am also having similar problems with the use of ' in php/mysql.

What do you mean by adding slashes? Could you give a couple lines as an example?

Cheers

229257
 
This would do it to all POST variables:
Code:
while (list($key,$val) = each($_POST))
{
    $_POST[$key] = addslashes($val);
}
//Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top