ipsa24 Posted August 14, 2012 Share Posted August 14, 2012 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\student info system\student_registration_handler.php on line 33 No database selected <?php include 'Connect.php'; $flag = "success"; function rollbackData(){ mysql_query(" ROLLBACK "); global $flag; $flag = "error"; if(mysql_error() != null){ die(mysql_error()); } } $student_id = $_POST['st_id']; $student_pass = $_POST['st_pass']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $gender = $_POST['gender']; $contact_no = $_POST['contact_no']; $qualification= $_POST['qualification']; $city = $_POST['city']; $state = $_POST['state']; $country = $_POST['country']; $pin_code = $_POST['pin_code']; $email1 = $_POST['email1']; $address = $_POST['address']; $resumename = ""; $imagename = ""; $dobdate = date("Y-m-d",strtotime($_POST['dob'])); /* This block is used to check whether the student_id already exists in database. */ $select_query="select student_id from student_information where student_id = '$student_id'"; $result_set = mysql_query($select_query,$link_id); if($row = mysql_fetch_array($result_set)){ $flag="exists"; header("location:Student_login.php?flag=$flag&student_id=$student_id"); die(); } else{ /* This block is used to insert the student record in databaseif the student_id is already not present in the database. */ mysql_query("SET AUTOCOMMIT = 0 "); if(mysql_error() != null){ die(mysql_error()); } $query = "insert into student_information(student_id,student_password,first_name,last_name,registration_date,gender,date_of_birth,"; $query .="student_status,contact_no,qualification,city,state,country,pin_code,email1,address)"; $query .= "values('$student_id','$student_pass','$first_name','$last_name',now(),'$gender ','$dobdate','Disable','$contact_no',"; $query .="'$qualification','$city','$state','$country','$pin_code','$email1','$address')"; $result = mysql_query($query,$link_id); if(mysql_error() != null){ die(mysql_error()); } if($result){ if($_FILES['resume']['name'] != ""){ $filename = $_FILES['resume']['name']; $ext = strrchr($filename,"."); $resumename = $student_id; $resumename .= "_".$filename; if($ext ==".txt" || $ext ==".doc" || $ext ==".TXT" ||$ext ==".DOC" || $ext ==".pdf" || $ext ==".PDF"){ $size = $_FILES['resume']['size']; if($size > 0 && $size < 1000000){ $archive_dir = "resumes"; $userfile_tmp_name =$_FILES['resume']['tmp_name']; if(move_uploaded_file($userfile_tmp_name, "$archive_dir/$resumename")){ /* if image is successfullyuploaded then resumename is stored in database. */ mysql_query("updatestudent_information set resume='$resumename' wherestudent_id='$student_id'", $link_id); if(mysql_error() != null){ die(mysql_error()); } $flag = "success"; }else{ rollbackData(); } } else{ rollbackData(); die("You can upload resume of 1 MBsize only. Please, try again."); } } else{ rollbackData(); die("You can upload resume of .txt, .pdf,.doc extensions only. Please, try again."); } } if($_FILES['image']['name'] != ""){ $filename = $_FILES['image']['name']; $ext = strrchr($filename,"."); $imagename = $student_id; $imagename .="_". $filename; if($ext ==".jpg" || $ext ==".jpeg" || $ext ==".JPG" ||$ext ==".JPEG" || $ext ==".gif" || $ext ==".GIF"){ $size = $_FILES['image']['size']; if($size > 0 && $size < 1000000){ $archive_dir = "images"; $userfile_tmp_name =$_FILES['image']['tmp_name']; if(move_uploaded_file($userfile_tmp_name, "$archive_dir/$imagename")){ /* if image is successfullyuploaded then imagename is stored in database. */ mysql_query("updatestudent_information set image='$imagename' wherestudent_id='$student_id'", $link_id); $flag = "success"; if(mysql_error()!=null){ die(mysql_error()); } } else { if(file_exists('resumes/' .$resumename)) { unlink('resumes/' .$resumename); } rollbackData(); } } else{ if(file_exists('resumes/' .$resumename)) { unlink('resumes/' .$resumename); } rollbackData(); die("You can upload image of 1 MBsize only. Please, try again."); } } else{ if(file_exists('resumes/' . $resumename)) { unlink('resumes/' . $resumename); } rollbackData(); die("You can upload images of .jpg, .jpeg,.gif extensions only. Please, try again. "); } } } else{ $flag="error"; } if($flag == "success"){ mysql_query(" COMMIT "); $flag="success"; if(mysql_error() != null){ die(mysql_error()); } /* This block is used to send email to the successfully registered users.*/ /* $to = $email1;$subject = 'Congratulations';$message = 'Congratulations you are registered in our site.\r\n\r\n'; $message .= "Your Login Id : $student_id \r\n Password :$student_pass"; $headers = "From: info@sims.com\r\n"; $headers .= 'X-Mailer: PHP' . phpversion(); mail($to, $subject, $message, $headers); */ } header("location:Student_login.php?flag=$flag"); die(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/267064-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/ Share on other sites More sharing options...
trq Posted August 14, 2012 Share Posted August 14, 2012 This is a common error, and it tells you exactly what is wrong. Your passing a boolean to mysql_fetch_array(), it expects a resource. Check your query has actually succeeded before simply using it's result. And please, we have tags for a reason. Quote Link to comment https://forums.phpfreaks.com/topic/267064-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1369299 Share on other sites More sharing options...
ipsa24 Posted August 14, 2012 Author Share Posted August 14, 2012 How do I rectify it? Please, i am a beginner at php! Quote Link to comment https://forums.phpfreaks.com/topic/267064-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1369306 Share on other sites More sharing options...
GD77 Posted August 14, 2012 Share Posted August 14, 2012 usually this error happens if you have empty table... nothing to be returned Quote Link to comment https://forums.phpfreaks.com/topic/267064-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1369312 Share on other sites More sharing options...
PFMaBiSmAd Posted August 14, 2012 Share Posted August 14, 2012 @GD77, Queries that match zero rows don't produce php fetch statement errors. The only mysql data retrieval statement that produces a php error when there are zero rows in the result set is mysql_result. Quote Link to comment https://forums.phpfreaks.com/topic/267064-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1369314 Share on other sites More sharing options...
PFMaBiSmAd Posted August 14, 2012 Share Posted August 14, 2012 No database selected ^^^ You haven't selected a database at all or your mysql_select_db statement failed. Quote Link to comment https://forums.phpfreaks.com/topic/267064-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1369315 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.