Please guys i need help in log in form, i'm newbie at php and tomorrow is the submission of our case study. can somebody help me in log in form. i'll post a code below and tell me if this is correct, if no please provide the right answer, and i'll do the rest.

My database is MySQL Workbench

<?php
include ("connectDB.php");

$idnum = $_POST["IDnum"];
$password_Field = $_POST["Passtxt"];

$insertSql = "SELECT * FROM studenttbl WHERE StudentID = '". $_POST["IDnum"] ."'";
//$insertSql .= " VALUES('$stud_First_Name','$stud_Last_Name', '$Password_Field')";
$result = $mysqli->query($insertSql); 

if(query_num_rows($insertSql)==1) {
	echo "record found successfully."; 
} else {
	echo "inserting a record was unsuccessful.";
	echo $insertSql;
}

?>

Thank you in advance.

Recommended Answers

All 2 Replies

OK. For starters, there's no point in storing your POST variable IDnum to the variable $idnum if you're not going to use it. So line 7 should read:

$insertSql = "SELECT * FROM studenttbl WHERE StudentID = '$idnum'";

On line 11, you should be checking the number of rows in the result, not the query. According to the manual (I don't use mysqli myself), this is eg. $result->num_rows
so maybe something like:

$numrows = $result->num_rows;
if($numrows==1) {

(I'm not sure if $result->num_rows would work inside the if, but it may)

Thank you sir, thank you very much. it worked!

:D thanks again.

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.