-2

I'm trying to insert data into database using PHP,MYSQL and Android.I'm getting following error.

$statment = $conn->prepare("INSERT INTO doctorsignuprequest (doc_first_name, doc_last_name, doc_email, doc_profile_image, doc_password, doc_ph_number, doc_age, doc_gender, doc_category, doc_education, doc_doctor_message)VALUES ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?");  
$statment->bind_param("sssssssssss" , $doc_first_name, $doc_last_name, $doc_email, $doc_profile_image, $doc_password, $doc_ph_number, $doc_age, $doc_gender, $doc_category, $doc_education, $doc_doctor_message);  
Professor Abronsius
  • 30,177
  • 5
  • 29
  • 43
  • hi thank you for your comment.Actually i wrote correct table and columns names from my mysql db .but still getting this error.i just wasted a whole day just because of this error :( – Malik Zeeshan May 23 '19 at 18:43
  • 2
    it generally means your `prepare` has failed.. check the SQL carefully and you'll see a missing `(` from----> `)VALUES ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?")` – Professor Abronsius May 23 '19 at 18:44
  • MySQL reports differently than regular PHP. Check for [mysqli errors](http://php.net/manual/en/mysqli.error.php) after your prepare to find out why it failed. – aynber May 23 '19 at 18:45
  • RamRaider mate i checked it again.its fine but not resolving the issue – Malik Zeeshan May 23 '19 at 18:52
  • did you also factor in the missplaced closing quote? - I should have added that to the comment too – Professor Abronsius May 23 '19 at 18:57
  • RamRaider please do add it in your comment here so that i can exactly figure out your answer :). Thanks for your time – Malik Zeeshan May 23 '19 at 19:19

1 Answers1

0

You might wish to try using a logical test to the creation of the prepared statement before blindly proceeding with the rest of the code - what I mean is like this:

$sql='INSERT INTO `doctorsignuprequest`
        ( `doc_first_name`, `doc_last_name`, `doc_email`, `doc_profile_image`, `doc_password`, `doc_ph_number`, `doc_age`, `doc_gender`, `doc_category`, `doc_education`, `doc_doctor_message` )
      VALUES
        ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )';

$stmt=$conn->prepare( $sql );
if( $stmt ){
    $stmt->bind_param( 'sssssssssss',
        $doc_first_name,
        $doc_last_name,
        $doc_email,
        $doc_profile_image,
        $doc_password,
        $doc_ph_number,
        $doc_age,
        $doc_gender,
        $doc_category,
        $doc_education,
        $doc_doctor_message
    );
    $res=$stmt->execute();
    $stmt->close();

    /* yay - all good perhaps */

} else {
    exit( 'BOGUS' );
}
Professor Abronsius
  • 30,177
  • 5
  • 29
  • 43