PDA

View Full Version : [PHP] The use of "!eregi" - am I correct?



ckevin
June 6th, 2002, 09:43
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:-


...
$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:-

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!

hohoho
June 6th, 2002, 09:51
you could use strcmp instead of eregi

ckevin
June 6th, 2002, 10:18
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!

spec
June 6th, 2002, 11:27
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();
}

ckevin
June 7th, 2002, 07:06
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!

hohoho
June 7th, 2002, 07:12
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 ? :o :o :rolleyes:

ansa
June 7th, 2002, 07:21
He wants examples of using strcmp Mitja...

hohoho
June 7th, 2002, 07:25
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 ;)

spec
June 7th, 2002, 12:49
<?
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.

ckevin
June 8th, 2002, 09:55
spec, mitja thank you for your help! The problem is solved :)

THANK YOU VERY MUCH!

I still keep on learning PHP :p