Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

81 users online



Check if ID number is available

Check if ID number is available

Currently viewing this thread: 1 (0 members and 1 guests)


euphoria_dream

euphoria_dream

Status: Offline!

Check if ID number is available

Ok? here?s the code for a ?view.php? page, I wrote this script to view the results of students when they type in their ID Number.

PHP:

 <?php
// Connect to databse
$db mysql_connect("localhost""root""password here");
mysql_select_db("12",$db);
// Start Query
$query "SELECT Idnumber, Name, Year, Grade FROM re WHERE idnumber='$id'";
$result mysql_query($query) or die(mysql_error());<br>

//show table header
echo "<table border=3 width=50% bordercolor=#000066>";
echo
"<tr>
<td align=center bgcolor=#00FFFF><b>Id Number</b></td>
    <td align=center bgcolor=#00FFFF><b>Student's Name</b></td>
    <td align=center bgcolor=#00FFFF><b>Year</b></td>
    <td align=center bgcolor=#00FFFF><b>Grade</b></td>
  </tr>"
;

// Show Data
if ($row mysql_fetch_array($result))
{
echo 
"<TR><TD align=center bgcolor=#66CCFF>";
echo 
$row["Idnumber"];
echo 
"<TD align=center bgcolor=#66CCFF>";
echo 
$row["Name"];
echo 
"<TD align=center bgcolor=#66CCFF>";
echo 
$row["Year"];
echo 
"<TD align=center bgcolor=#66CCFF>";
echo 
$row["Grade"];
echo 
"</TABLE>";
}

//error message view
if($id 130) {
echo 
"<align center><B>0 Results found, The Id Number ($id) was not found, please try again.</B></align>";
}
// End conection to databse
mysql_close($db);
?> 

this works great but my problem is with the ?//error message view? part, it says that if the ID number entered was more than ?130? echo the message?.

This is so far good for me, but now I want to make the script automatically search if the id number is there or not, cuz I excluded some numbers between (0 and 130) from my database because my site will only show results of my friends. So how can I let the script look for the id number and echo the same message if ID was not found?

Rad

Rad

thinking of something witty to put here
Status: Offline!
PHP:

<?php

if (mysql_num_rows($result) !== 0) {
    
//  echo the message
}

?>

yaoherm50

yaoherm50

Status: Offline!

$result = mysql_query("SELECT * FROM re WHERE idnumber = \"$id\"") or die (mysql_error());
if (@mysql_num_rows($result) != 0) {

// your listed results here

} else {

// no results found

}

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0079 seconds.