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.

$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.

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

Then, mark as Solved with the link below the editor.

Sorry I didn`t know how to do that, Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.