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.
php_info()).phpinfo()- without an underscore