Using auto increment in PHP
Posted: Fri Mar 04, 2011 9:55 am
I'm just a beginner, when I search for auto increment in PHP, i did what I've search. But it doesn't insert very well in the database. The if else statement doesn't show up anything so I can't see the error.
Does the result carry a value, after $result=$db->query($query);?
Thanks for the help.
Does the result carry a value, after $result=$db->query($query);?
Thanks for the help.
Code: Select all
$cellphone_nr=$_POST['cellphone_nr'];
$amount=$_POST['amount'];
$month=$_POST['month'];
$day=$_POST['day'];
$year=$_POST['year'];
$date=$year."-".$month."-".$day;
@ $db = mysqli('localhost', 'root','12345', 'load_business');
if (mysqli_connect_errno()){
echo 'Error: Could not connect to the database.';
exit;
}
$query = "insert into globe (cellphone_nr, amount, date) values
('".$cellphone_nr."','".$amount."','".$date."')";
$result=$db->query($query);
if($result){
echo $db->affected_rows." book inserted into database.";
echo $cellphone_nr."<br>";
echo $amount."<br>";
echo $date;
}
else{
echo "An error has occurred. The item was not added.";
}
$db->close();