Newb to php just looking for help with a solution to my problem. Im trying to send form data to a db. I connect fine to the db but I echo out "no record made" when I submit and go to the success.php page.
At one point I did get the error "Incorrect integer value: '' for column 'mobile' at row 1" But seemed to have fixed it by cleaning up my code.
Any help would be greatly appreciated as I'm a bit stumbed!
//index.php code
<?php
//CONNECT DETAILS
$user = 'root';
$password = 'root';
$db = 'db_dev';
$host = 'localhost';
$port = 8889;
//CREATE CONNECT
$link = mysqli_init();
$success = new mysqli($host, $user, $password, $db, $port);
$success->query("SET NAMES 'utf8'");
$success->query("SET CHARACTER SET utf8");
// Check CONNECTION
if ($success->connect_error) {
die("Connection failed: " . $success->connect_error);
}
//VARIABLES & INSERT QUERY
if (isset($_POST["submit"])) {
$sql = "INSERT INTO db_test (name, mobile, date, email )
VALUES ( '', '$_POST[name]', '$_POST[email]', '$_POST[mobile]', NOW())";
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$userID = mysqli_insert_id($success);
}
mysqli_close($success);
?>
//success.php code
<?php
//LOCAL CONNECT/MAMP
$user = 'root';
$password = 'root';
$db = 'db_dev';
$host = 'localhost';
$port = 8889;
//CREATE CONNECT
$link = mysqli_init();
$success = new mysqli($host, $user, $password, $db, $port);
$success->query("SET NAMES 'utf8'");
$success->query("SET CHARACTER SET utf8");
// Check CONNECTION
if ($success->connect_error) {
die("Connection failed: " . $success->connect_error);
}
//ECHO OUT SUCCESS
if ($success->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: no record made" . $sql . "<br>" . $success->error;
}
mysqli_close($success);
?>