0

My database code is:

CREATE TABLE IF NOT EXISTS symptoms_list (
id int(11) NOT NULL,
available_names varchar(255) NOT NULL

PRIMARY KEY (id)
);

My php code is:

<?php

require 'config.php';

$available_names = array (
    array(‘Abdominal pain’, ‘Stomach ache’, ’Stomach trouble’, ‘Painful tommy’, ‘Tommy ache’, ‘Tommy pain’, ‘Belly ache’, ‘Belly pain’, ‘Painful tommy’),
    array(‘RUQ abdominal pain’, ‘RUQ pain’, ’Right upper quadrant abdominal pain’, ‘Right upper quadrant pain’, ‘Right hypochondriac pain’ ),
    array(‘Epigastric pain’, ’mid-upper abdominal pain’),
    array(‘LUQ abdominal pain’, ‘LUQ pain’, ‘Left hypochondriac pain’, ‘Lt upper quadrant abdominal pain’),
    array(‘Right Para umbilical pain’, ‘Rt para umbilical pain’, ‘Rt para umbilical pain’, ‘Right para umbilical abdominal pain’, ‘Pain right side of the belly button’),
    array(‘Umbilical pain’, ‘Periumbilical abdominal pain’, ‘umbilical pain’, ‘Belly button pain’, ‘Umbilical ache’),
    array(‘RLQ abdominal pain’, ‘Rt Lower quadrant abdominal pain’, ‘Right lower quadrant pain’, ‘Right lower quadrant abdominal pain’, ‘RLQ pain’),
    array(‘suprapubic pain’, ‘Suprapubic pain’, ‘Pain below the umbilicus’, ‘Pain below the navel’, ‘Pain below the belly button’),
    array(‘LLQ abdominal pain’, ‘Lt lower quadrant abdominal pain’, ‘LLQ pain’, ‘LLQ abdominal discomfort’, ‘Left lower quadrant abdominal pain’, ‘Left lower quadrant pain’),
    array(‘Back pain’, ‘Pain in the back’, ‘Back ache’, ‘Back discomfort’, ‘Pain at the back’),
    array(‘Fatigue’, ‘Easy fatiguability’, ’Lassitude’, ’Tiredness’, ’General weakness’, ’Exhaustion’),
    array(‘Chest pain’, ‘Painful chest’, ‘Chest discomfort’, ‘Chest heaviness’),
    array(‘Otalgia’, ‘Ear ache’, ’Ear pain’, ‘Ear discomfort’, ‘Painful ear’),
    array(‘Otorrhea’, ‘Discharging ear’, ‘Ear discharge’)
    );
    // STORE ARRAY
    $sql = $db->prepare("INSERT INTO symptoms_list (id, available_names) VALUES (:id, :available_names)");
    // CONNECT TO DATABASE
    try {
      $stmt = $pdo->prepare($sql);
    // Start Transaction
    $stmt =  $db->beginTransaction();
    $array = json_decode($data, true);
    // Insert each record
    foreach($data as $insertRow){
    
       // now loop through each inner array to match binded values
       foreach($insertRow as $column => $value){
          $stmt->bindValue(":{$column}", $value);
      }
    }
    // Execute statement to add to transaction
    $stmt->execute();
    
    // Clear statement for next record (not necessary, but good practice)
    $stmt = null;
    }
    // Commit all inserts
    $db->commit();
    ?> 

Each time I try to post the two dimensional array to mysql I get the error message:

"Parse error: syntax error, unexpected ';', expecting ')' in C:\xampp2\htdocs\public\symptoms7.php on line 4"

brombeer
  • 8,716
  • 5
  • 21
  • 27
  • 2
    Those quotes `‘` `’` are not single (double) quotes – brombeer Aug 14 '21 at 14:26
  • please edit your question title and use a shorter and better title about your issue. – nima Aug 15 '21 at 05:23
  • please explain more about your problem/expectation from the above code snippet to help your question be understandable. – nima Aug 15 '21 at 05:24
  • @novonimo. I just want to post the array of indexed arrays to mysql using the php pdo code snippet shown. I always get the error message about a parse error as shown. – Anthony Mbah Aug 15 '21 at 07:23
  • 1
    @brombeer. double quotes did not solve the problem. I still get the same error message. – Anthony Mbah Aug 15 '21 at 07:25
  • I doubt that you get _the same_ message after fixing the quotes. You will get a different one though, since your `try {` block doesn't have a `}catch()` block. https://www.php.net/manual/en/language.exceptions.php – brombeer Aug 15 '21 at 10:21
  • @brombeer. I have done everything I could but still I get errors pointing at a different line where I cannot figure out what the problem is. The site you referred me to was highly informative, though. Thanks a million. – Anthony Mbah Aug 21 '21 at 00:31
  • Not much anyone can do without knowing what the error. Advice for the future: always post the exact error message, so people who want to help know what to deal with. The only thing "suspicious" in your code is `$array = json_decode($data, true);` since there is no `$data` declared. Also, `foreach($data as $insertRow){` should probably use the decoded array, not `$data` again. Try changing `$array = json_decode($data, true);` to `$data = json_decode($available_names, true);`. Good luck – brombeer Aug 21 '21 at 05:40

0 Answers0