SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Threaded View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2008
    0 Post(s)
    0 Thread(s)

    Problem with PDO array insert

    I am trying to make an insert into my DB and checking if the $_POST global isset but do not seem to have any luck get an insert to work.
    It will work if there is only one field and checking one field, but I want more than one.

    Can you see what is wrong with my code please.
    PHP Code:
    if (isset($_POST['name'])&& ($_POST['email']) && ($_POST['message'])){
    $pdo = new PDO('mysql:host=localhost;dbname=chairkit'$user,$pass);
    $pdo->exec('SET NAMES "utf8"');
        catch (
    PDOException $e)
    $output 'unable to connect to server'$e->getMessage();

    // get connection to DB
    try {

    $sql "INSERT INTO comments (name,email,comment) VALUES (:name,:email,:comment)";
    $s $pdo->prepare($sql);
        } catch (
    PDOException $e)
    $error 'Error inserting comments ' $e->getMessage();
    header('Location: thankyou.html');

    Last edited by SpacePhoenix; Sep 29, 2013 at 15:58. Reason: placed php tags around php code

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts