Jump to content

Recommended Posts

mysql_insert_id not working

It returns zero

 

 

Thanks in advance

 

CSJakharia

 

 

 

config.php

<?php
// This is an example of config.php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'dronaonline';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
mysql_select_db($dbname);
?>

 

 

register.php

 

<?php
include 'config.php';
session_start();

if(!isset($_SESSION['tutorId']))
$_SESSION['tutorId']=0;
if($_SESSION['tutorId']>0)
{
$result=mysql_query("SELECT * FROM masteruser WHERE id='".$_SESSION['tutorId']."'");
$row =  mysql_fetch_assoc($result);
extract($row);
}
else
{
extract($_GET);
$result =mysql_query(sprintf("SELECT count(*) FROM masteruser WHERE ucase(userName)='%s'",mysql_real_escape_string($userName))) or die('Error, insert query failed');
$row = mysql_fetch_array($result, MYSQL_NUM);
if(isset($Submit) && $row[0]==0)
{
		 $query = sprintf("INSERT INTO masteruser (userName,password, name, age, gender,qualification,address,phoneNo,emailAddress,mobileNo,subject,otherSubjects,typeOfTutoring,tutoringLocation,preferredDays,preferredLocation,tutoringExperience,feePayment,feeStructure,comments) VALUES ('%s','%s','%s','$age','$gender','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','$feePayment','%s','%s')",mysql_real_escape_string($userName),mysql_real_escape_string($password),mysql_real_escape_string($name),mysql_real_escape_string($qualification),mysql_real_escape_string($address),mysql_real_escape_string($phoneNo),mysql_real_escape_string($emailAddress),mysql_real_escape_string($mobileNo),mysql_real_escape_string(','.implode(',',$subject).','),mysql_real_escape_string($otherSubjects) ,mysql_real_escape_string(','.implode(',',$tutoring).',') ,mysql_real_escape_string(','.implode(',',$tutoringLocation).',') ,mysql_real_escape_string(','.implode(',',$preferredDays).',') ,mysql_real_escape_string(','.implode(',',$preferredLocation).','),mysql_real_escape_string($tutoringExperience),mysql_real_escape_string(','.implode(',',$preferredDays).','),mysql_real_escape_string(','.implode(',',$preferredLocation).','),mysql_real_escape_string($tutoringExperience),mysql_real_escape_string($feeStructure),mysql_real_escape_string($comments));
		 $_SESSION['tutorId']=mysql_insert_id($conn);
		echo $query;
		mysql_query($query) or die('Error, insert query failed');
		$query = "FLUSH PRIVILEGES";
		mysql_query($query) or die('Error, insert query failed');
		include 'closedb.php';
		$host  = $_SERVER['HTTP_HOST'];
		$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
		$extra = 'registerthanks.php';
		header("Location: http://$host$uri/$extra");
		exit;
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/53930-mysql_insert_id-not-working/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.