My PHP form is POSTing to a php file that connects to my database and supposed to INSERT the record.
As of now I have tested the connection and it is working, my SELECT statement is working. But my INSERT is not. I did an echo $sql->rowCount();
before the execution and it returns "0". Should there be a row per value?
My code:
try {
$db = new PDO('mysql:host=localhost;dbname=x;charset=utf8', 'x', 'x');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$db = new PDO('mysql:host=localhost;dbname=x;charset=utf8', 'x', 'x');
$ipaddress = $_SERVER['REMOTE_ADDR'];
$email = $_POST['email'];
$sql = $db->prepare("INSERT INTO ucm_signup (company, address1, address2, city, province, zip, fname,
lname, email, phone, session, iama, buyfrom, ipaddress)
VALUES (:company, :address1, :address2, :city, :province, :zip, :fname, :lname, :email, :phone, :session, :iama, :buyfrom, :ipaddress)");
$sql->bindParam(":company", $_POST['company'],PDO::PARAM_STR);
$sql->bindParam(":address1", $_POST['address1'],PDO::PARAM_STR);
$sql->bindParam(":address2", $_POST['address2'],PDO::PARAM_STR);
$sql->bindParam(":city", $_POST['city'],PDO::PARAM_STR);
$sql->bindParam(":province", $_POST['province'],PDO::PARAM_STR);
$sql->bindParam(":zip", $_POST['zip'],PDO::PARAM_STR);
$sql->bindParam(":fname", $_POST['fname'],PDO::PARAM_STR);
$sql->bindParam(":lname", $_POST['lname'],PDO::PARAM_STR);
$sql->bindParam(":email", $_POST['email'],PDO::PARAM_STR);
$sql->bindParam(":phone", $_POST['phone'],PDO::PARAM_STR);
$sql->bindParam(":session", $_POST['session'],PDO::PARAM_STR);
$sql->bindParam(":iama", $_POST['iama'],PDO::PARAM_STR);
$sql->bindParam(":buyfrom", $_POST['buyfrom'],PDO::PARAM_STR);
$sql->bindParam(":ipaddress", $_POST['ipaddress'],PDO::PARAM_STR);
$sql->execute();
//$db = null;
//header( "Location: http://www.x.com/company/ucm_signup2" );
Any ideas on why my execute is not correct? Thank you