0
if(isset($_POST['addreservation']) and $_POST['addreservation'] == 'Add'){
include $_SERVER['DOCUMENT_ROOT'] . '/TattooSite/include/db.inc.php';

$username=$_SESSION['username']; //Geting the id of loggedin client
$result=mysqli_query($link, "SELECT id FROM client_tbl WHERE user_name='$username' "); 
	if(!$result){
		$error='Error identifying user ' . mysqli_error($link);	
		include $_SERVER['DOCUMENT_ROOT'] . '/TattooSite/include/error.html.php';	
		exit();	
		}
	$row=mysqli_fetch_array($result);
	$clientid=$row['id'];

	//Geting the values generated in reservation form
	$id=mysqli_real_escape_string($link, $_POST['id']);
	$tattoo=mysqli_real_escape_string($link, $_POST['tattoo']);
	$price=mysqli_real_escape_string($link, $_POST['price']);
	$date=mysqli_real_escape_string($link, $_POST['date']);
	$width=mysqli_real_escape_string($link, $_POST['width']);
	$hight=mysqli_real_escape_string($link, $_POST['hight']);

$sql="INSERT INTO tattoo_tbl SET description='$tattoo', width='$width', hight='$hight'";
	if(!mysqli_query($link, $sql)){
$error='Error inserting new tattoo parameters: ' . mysqli_error($link);
include $_SERVER['DOCUMENT_ROOT'] . '/TattooSite/include/error.html.php';
exit();
}	
$tattooid = mysql_insert_id();	
$sql1="INSERT INTO reservation_tbl SET tattoo_id='$tattooid', client_id='$tattooid', date='$date', price='$price'";
if(!mysqli_query($link, $sql1)){
$error='Error inserting new reservation parameters: ' . mysqli_error($link);
include $_SERVER['DOCUMENT_ROOT'] . '/TattooSite/include/error.html.php';
exit();
			}	
header('Location: .');
exit();

The problem is that when I select the records from database, client_id is '0' all the time. I think mysqli_insert_id() is not storing the id from the previous query. Please any ideas what maid be the problem.

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by Dragan.
0

$sql1="INSERT INTO reservation_tbl SET tattoo_id='$tattooid', client_id='$clientid', date='$date', price='$price'";
Not to confuse u more, this was little mistake i`v done when i was editing the code!
Still waiting for replay I`m stuck at this issue for days! I have read a lot forums but non of the solution worked for me.

0

Ok my problem is solved! I don`t know how, but the only change i`v made is this $tattooid = mysql_insert_id($link); yeeeeeeesssssssssssssss!!!! Finally
I have tried the same thing many times before and didn`t worked, probably back then i had couple more problems which i solved by now....
I hope this example will be useful for some one

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.