0

Can someone with experience with PDO help me on this? I've spent like 6 hours but I am still unable to get a query running.

Here is my code:

<?php include('database.php'); //print_r($_GET); if(isset($_GET['ctype'])) { $ctype = $_GET['ctype']; } else { die("Could determine type of input"); } if($ctype==1) { //it is client if((isset($_GET['uid'])) && (isset($_GET['name'])) && (isset($_GET['address'])) && (isset($_GET['city'])) && (isset($_GET['state'])) && (isset($_GET['zip']))) { try { $conn = new PDO("mysql:host=$host;dbname=$database", $username, $password); //$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "INSERT INTO clients (uid, name, address, city, state, zip) VALUES(:uid, :name, :address, :city, :state, :zip)";       $stmt = $conn->prepare($sql);       $stmt->execute(array(     ':uid' => $_GET['uid'],     ':name' => $_GET['name'],     ':address' => $_GET['address'],     ':city' => $_GET['city'],     ':state' => $_GET['state'],     ':zip' => $_GET['zip']    ));    echo $stmt->rowCount(); // 1 } catch(Exception $e) {    echo 'Error: ' . $e->getMessage(); } } }?> 

database.php being:

<?php //Please Enter database settings here $username = "root"; $password = ""; $database="letters"; $host="localhost"; ?> 

I hit the page with this GET request

http://localhost/letters/contact_add.php?ctype=1&uid=mmm&name=test&address=6182&city=xyz&state=abc&zip=123456 

Error I am getting:

Parse error: in C:\xampp\xampp\htdocs\letters\contact_add.php on line 26 

Line 26 being:

$sql = "INSERT INTO clients (uid, name, address, city, state, zip) VALUES (:uid, :name, :address, :city, :state, :zip)"; 

I have browsed almost any link I could get on google and still unable to find the problem. the link which I followed is this. I am running xampp 1.8.1 and extension=php_pdo_mysql.dll is enabled.

8
  • Parse error means you have an error in your PHP code, not in whatever PDO interaction Commented Feb 7, 2013 at 16:04
  • Yup that was my first though but look at line 26, its basically a string assignment so I thought those values with ":" might be responsible for it? Commented Feb 7, 2013 at 16:07
  • I have tested your code on a local MAMP server and worked first time. I think your issue is more likely to be your setup. More specifically PDO. Maybe see stackoverflow.com/questions/6113262/… Commented Feb 7, 2013 at 16:12
  • what version of PHP are you running? Also, does it include the PDO extension? (check what extensions are loaded with php_info()). Commented Feb 7, 2013 at 16:28
  • 1
    it's phpinfo() - without an underscore Commented Feb 7, 2013 at 17:50

1 Answer 1

0

There are no parse errors in the code you posted. So, you're running some other code then.
Please, double-check the file you're actually running.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm checking the code with new installation of xampp now. Unfortunately, the file is correct ( this is my only project in htdocs) and If I press enter before the line 26, error shifts to line 27 ( I do have some common sense :)). I really appreciate your help, gonna post results in few minutes!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.