This code was to create a simple database with a table and add records with the following. toIm having trouble with the 'id' auto_increment.
<?php
$con=mysqli_connect("localhost","root","distortion","my_databs");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Create table
$sql="CREATE TABLE empl(ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,FirstName CHAR(30),LastName CHAR(30), Age INT)";
// Execute query
if (mysqli_query($con,$sql)) {
echo "Table persons created successfully";
} else {
echo "Error creating table: " . mysqli_error($con);
}
// escape variables for security
$firstname = mysqli_real_escape_string($con, $_POST['firstname']);
$lastname = mysqli_real_escape_string($con, $_POST['lastname']);
$age = mysqli_real_escape_string($con, $_POST['age']);
$sql="INSERT INTO Empl (ID ,FirstName, LastName, Age )
VALUES ( NULL,'$firstname', '$lastname', '$age')";
if (!mysqli_query($con,$sql)) {
die( 'Error:' . mysqli_error($con));
}
echo"<br>";
echo " -> 1 record added";