csplrj Posted June 2, 2007 Share Posted June 2, 2007 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 More sharing options...
AndyB Posted June 2, 2007 Share Posted June 2, 2007 $query = sprintf("INSERT .... world's longest query ...); // you forgot to close the quotes Then you tried to determine mysql_insert_id before executing the INSERT query. Link to comment https://forums.phpfreaks.com/topic/53930-mysql_insert_id-not-working/#findComment-266646 Share on other sites More sharing options...
csplrj Posted June 2, 2007 Author Share Posted June 2, 2007 Thanks for helping me out I was in this error for the past 2 hours and could not see that silly errors Worlds Longest Query.? I mean there must be other requirements where there may be queries much longer than this? Thanks again CSJakharia Link to comment https://forums.phpfreaks.com/topic/53930-mysql_insert_id-not-working/#findComment-266651 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.