• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

[PHP] The use of "!eregi" - am I correct?

ckevin

New Member
I wish to check if a unique ID submitted from a HTML form is existing in the database, if yes, then I continue to provide service, so here is my code:-

PHP:
...
	   $sql = "SELECT * FROM Project WHERE id='$id'";
	   $result = mysql_query($sql);
	   while($row = mysql_fetch_array($result)) {
		if (!eregi("$row[id]", $id)) {
		      DisplayErrMsg("Error : You have enter a wrong ID number!");
		      exit();
		}
	   }
...

However, it can't work properly, wrong IPs can still continue, any hints?

I do not want to code the scripts something like:-
PHP:
		if (eregi("$row[id]", $id)) {
		      echo "Provide Service, PHP code here...";
		      exit();
		}

I hope you understand what I'm talking about :rolleyes:

Thanks in advance!
 
thank you for your quick help mitja! If you have time, can you give me some e.g. as I'm new in PHP programming. :( Thanks!
 
I dont see the need for using eregi
"select * from project where id=$id"
if the id is unique this will only bring up 1. If this is bringing up more than you are not dealing with a unique id

oops for your counting dellema do this
if(!$num = mysql_num_rows){
echo "oops stink!";
exit();
}
 
Last edited:
spec, my need is to verify if the ID is in our database, if the ID is invalid, I suggest him to enter a correct ID, else, process the service required. Thus, can you alter my code (the first version in the first post), so that it can work with my need? I don't know what's wrong, but it can't work the way I need :( Thank you for your help!
 
Originally posted by ckevin
thank you for your quick help mitja! If you have time, can you give me some e.g. as I'm new in PHP programming. :( Thanks!
hmmm...what do u mean ? :eek: :eek: :rolleyes:
 
PHP:
include("users.php");
for($i=0; $i<=15; $i++) {
   if(strcmp($nick,$nick2[$i])==0) {
      $currpass = md5($pass);
      if(strcmp($currpass,$userpass[$i])==0) {
         session_start();
         session_register("leet");
         $_SESSION['leet'] = "leet";
      }
   }
}

this is the admin page login of an news script i am working on... with strcmp, it checks if the username and the password are in the users.php file ;)
 
PHP:
<?
if(!$num = mysql_num_rows($result)){
make him re enter stuff here
}
else{
process input
}
?>

mysql_num_rows checks to see if the query you made is valid.
I see no reson not to use it.
 
spec, mitja thank you for your help! The problem is solved :)

THANK YOU VERY MUCH!

I still keep on learning PHP :p
 
Back
Top