开发者

niceEDIT and PHP/MySQL special chars

Hi I have a form with a text area on it which has descriptive text which will contain punctuation marks such as comma's etc.

on the PHP script I have used this

$description    = empty( $_POST['inputDescription'])? 'NULL': "'" .  mysql_real_escape_string($_POST['inputDescription']) . "'";

But I still get a syntax error when submitting the text which contains comma's which is this..

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

any thoughts would be great I am pulling my hair out!

EDIT Lots of code (Sorry)

<?php
    session_start();
    include "includes/connection.php";

    $contact        = $_POST['inputName'];
    $company    = $_POST['inputCompany'];
    $region             = $_POST['inputRegion'];
    $address1   = $_POST['inputAddress1'];
    $address2   = empty( $_POST['inputAddress2'])? 'NULL'   : "'" . mysql_real_escape_string(  $_POST['inputAddress2']) . "'";
    $city               = $_POST['inputCity'];
    $county             = empty( $_POST['inputCounty'])? 'NULL' : "'" . mysql_real_escape_string(  $_POST['inputCounty']) . "'";
    $postcode   = $_POST['inputPostcode'];
    $email          = empty( $_POST['in开发者_如何学JAVAputEmail'])? 'NULL'  : "'" . mysql_real_escape_string(  $_POST['inputEmail']) . "'";
    $telephone1 = $_POST['inputPhoneOne'];
    $telephone2 = empty( $_POST['inputPhoneTwo'])? 'NULL'   : "'" . mysql_real_escape_string(  $_POST['inputPhoneTwo']) . "'";
    $website        = empty( $_POST['inputWebsite'])? 'NULL'    : "'" . mysql_real_escape_string(  $_POST['inputWebsite']) . "'";
    $description    = empty( $_POST['inputDescription'])? 'NULL': "'" .  mysql_real_escape_string($_POST['inputDescription']) . "'";
    $userid             = $_POST['inputUserID'];

    if(
    $contact == '' || 
    $company == '' ||  
    $address1 == '' || 
    $address2 == '' || 
    $city == '' || 
    $county == '' || 
    $postcode == '' ||  
    $telephone1 == '' || 
    $telephone2 == '' || 
    $email == '' || 
    $website == '' || 
    $description == '' || 
    $region == '' ||  
    $userid == ''){
    $_SESSION['status'] = 'error';
    } else {
        mysql_query("INSERT INTO RegionalContacts
                (`bID`,`user_id`,`Name`,`Company`,`Address1`,`Address2`,`City`,`County`,`Postcode`,`Telephone1`,`Telephone2`,`eMail`,`Website`,`Description`,`Region`)
VALUES(NULL,'$userid','$contact','$company','$address1',$address2,'$city',$county,'$postcode','$telephone1',$telephone2,$email,$website,$description,'$region')") or die(mysql_error());
        $_SESSION['status'] = 'success';
    }
    header("location: regionalContacts.php");
?>


Your insert statement looks like it has values that (I assume) are strings passed to it without quotes around them such as address2, county, telephone2, email, website and description. That would cause a syntax error.


Some of the values in your INSERT-statement have quotes around them, others don't:

'$telephone1',$telephone2

Use prepared statements instead to avoid such mistakes…

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜