Hey,
Basically I am trying to get the last Id from my database and pass it on to another php page. I keep on getting the following errors:
Warning: mysql_insert_id() expects parameter 1 to be resource, object given in C:\XAMPP\xampp\htdocs\WebProgCA\create_contact.php on line 17
Warning: Cannot modify header information - headers already sent by (output started at C:\XAMPP\xampp\htdocs\WebProgCA\create_contact.php:17) in C:\XAMPP\xampp\htdocs\WebProgCA\create_contact.php on line 23
I dont know where I am going wrong so I would appriciate any help!
Below is the script I am getting the errors with.
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (!empty($_POST['firstName']) && !empty($_POST['lastName'])
&& !empty($_POST['email']) && !empty($_POST['primNum'])) {
$contactID = $_POST['contactID'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$primNum = $_POST['primNum'];
require_once 'db_connect.php';
$link = new PDO($dbinfo, $user, $pass);
$sql = "INSERT INTO contacts(fName, lName, email, labelID) VALUES "
. "(?, ?, ?, ?)";
$contactID = mysql_insert_id($link);
$params = array($firstName, $lastName, $email, $primNum);
$stmt = $link->prepare($sql);
$status = $stmt->execute($params);
if ($status == true) {
header("Location: create_contact_num_form.php?contactID =" . $contactID);
}
}
}
?>
Basically I am trying to get the last Id from my database and pass it on to another php page. I keep on getting the following errors:
Warning: mysql_insert_id() expects parameter 1 to be resource, object given in C:\XAMPP\xampp\htdocs\WebProgCA\create_contact.php on line 17
Warning: Cannot modify header information - headers already sent by (output started at C:\XAMPP\xampp\htdocs\WebProgCA\create_contact.php:17) in C:\XAMPP\xampp\htdocs\WebProgCA\create_contact.php on line 23
I dont know where I am going wrong so I would appriciate any help!
Below is the script I am getting the errors with.
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (!empty($_POST['firstName']) && !empty($_POST['lastName'])
&& !empty($_POST['email']) && !empty($_POST['primNum'])) {
$contactID = $_POST['contactID'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$primNum = $_POST['primNum'];
require_once 'db_connect.php';
$link = new PDO($dbinfo, $user, $pass);
$sql = "INSERT INTO contacts(fName, lName, email, labelID) VALUES "
. "(?, ?, ?, ?)";
$contactID = mysql_insert_id($link);
$params = array($firstName, $lastName, $email, $primNum);
$stmt = $link->prepare($sql);
$status = $stmt->execute($params);
if ($status == true) {
header("Location: create_contact_num_form.php?contactID =" . $contactID);
}
}
}
?>