Jump to content

Simple PHP Searching... plz take a look


Nazirul

Recommended Posts

;D

 

Hello

 

this is my code.. i can't use the if-else statement.. any idea?

 

$query = "SELECT * FROM $table WHERE student_number LIKE '".$_POST['txtSearch']."'";  
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result))
{
$Student_Number = $row['Student_Number'];
$Student_Name = $row['Student_Name'];
$Qualification = $row['Qualification'];
$Status = $row['Status'];

$kirim = $_POST['txtSearch'];

if ($kirim == $Student_Number)
{
	echo "You are success";
}
else 
       {
	echo("You are failed!!!");
}
}

 

i want to display a msg if the student success or not... is it the correct way for it?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/153878-simple-php-searching-plz-take-a-look/
Share on other sites

2 things:

 

1) Why can't you use if-else?

2) If you're going to use LIKE in your SQL statement, surround the value with %:

$query = "SELECT * FROM $table WHERE student_number LIKE '%".$_POST['txtSearch']."%'";  

 

If this is a school assignment and you can't use if-else, you're probably looking for the ternary operator: http://us.php.net/operators.comparison

 

the code is actually working ...  ;D

 

it is just try-n-error code...

 

but the problem is... i want to display an error when the student number did not match in the table...

 

how thats gonna be... i've spend a few hours for that... (im newbie anyway, :) )

   if ($kirim == $Student_Number)
   {
      echo "You are success";
   }
[b]   else
       {
      echo("You are failed!!!");
   }[/b]

 

i have a problem with the 'else' statement... when the student did not match like in the table, it display nothing... that is "      echo("You are failed!!!"); " did not works...  ???

 

 

Well, it's got to display one of the two lol.

 

lol... its confusing me... it is either one must work...

 

i've tried ...

 

   if ($kirim != $Student_Number)
  {
     echo "You are failed!!!";
  }
  else
      {
     echo("You are success");
  }

 

it just does not output the correct echo when the student number was wrong... no luck... :(

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.