Jinidoc Posted January 17, 2011 Share Posted January 17, 2011 Hi All, I Have an issue validating and inserting the data in to the database. I am beginner and the error message is new to me however i have google it but unable to find hope any one can help Thanks in advanced. Error : "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\signupck.php on line 32 Deprecated: Function eregi() is deprecated in C:\wamp\www\signupck.php on line 50 Welcome, You have successfully signed up Click here to login" Please find the Code Below: File name:signup.php <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Fast Fix Pro Signup</title> <script type="text/javascript"> function validate(form) { if(form1.userid.value == "") { alert('Please enter userid '); form1.userid.focus(); return false; } if(form1.userid.value == "") { alert('Please enter userid '); form1.userid.focus(); return false; } if(form1.password.value == "") { alert('Please enter password '); form1.password.focus(); return false; } if(form1.password2.value == "") { alert('Please renter the password '); form1.password2.focus(); return false; } if(form1.email.value == "") { alert('Please enter Email '); form1.email.focus(); return false; } if(form1.fname.value == "") { alert('Please enter First Name '); form1.fname.focus(); return false; } if(form1.lname.value == "") { alert('Please enter Last Name '); form1.lname.focus(); return false; } if (!document.form1.agree.checked) { alert("Please Read the guidlines and check the box below ."); return false; } return true; } </script> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"> <br/> <br/> <table width='67%' height="454" border='0' align=center cellpadding='0' cellspacing='0'><form name="form1" method=post action="signupck.php" onsubmit='return validate(this)'><input type="hidden" name="todo" value=post> <tr bgcolor='#f1f1f1'><td align=center colspan=2><font face='Verdana' size='2' ><b>Signup</b></td></tr> <tr bgcolor='#f1f1f1'><td > <font face='Verdana' size='2' >User ID</td><td ><font face='Verdana' size='2'><input type=text name=userid></td></tr> <tr ><td > <font face='Verdana' size='2' >Password</td><td ><font face='Verdana' size='2'><input name=password type=password></td></tr> <tr bgcolor='#f1f1f1'><td > <font face='Verdana' size='2' >Re-enter Password</td><td ><font face='Verdana' size='2'><input name=password2 type=password></td></tr> <tr ><td ><font face='Verdana' size='2' > Email</td><td ><input type=text name=email></td></tr> <tr bgcolor='#f1f1f1'><td > <font face='Verdana' size='2' >First Name</td><td ><font face='Verdana' size='2'><input type=text name=fname></td></tr> <tr ><td > <font face='Verdana' size='2' >Last Name</td><td ><font face='Verdana' size='2'><input type=text name=lname></td></tr> <tr bgcolor='#f1f1f1' ><td > <font face='Verdana' size='2' >I agree to terms and conditions</td><td ><font face='Verdana' size='2'><input type=checkbox name=agree value='yes'></td></tr> <tr ><td align=center colspan=2><input type=submit value=Signup> <input name="Reset" type=reset value=Reset> <td colspan=2 align=left> </td></td></tr> </table> <center> <br><font face='Verdana' size='2' ><a href='login.php'>Already a member ? Please Login</a></font></center> </body> </html> File Name :signuppck.php <?php include ("Connection.php");// database connection details stored here ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>(Type a title for your page here)</title> <meta name="GENERATOR" content="Arachnophilia 4.0"> <meta name="FORMATTER" content="Arachnophilia 4.0"> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"> <?php extract($_POST); //<---I don't recommand this really if(isset($todo) and $todo=="post") { $status = "OK"; $msg=""; // if userid is less than 3 char then status is not ok if(!isset($userid) or strlen($userid) <3) { $msg=$msg."User id should be =3 or more than 3 char length<BR>"; $status= "NOTOK"; } if(mysql_num_rows(mysql_query("SELECT userid FROM signup WHERE userid = '$userid LIMIT 1' "))) <-------------------(line 32) { $msg=$msg."Userid already exists. Please try another one<BR>"; $status= "NOTOK"; } if ( strlen($password) < 3 ) { $msg=$msg."Password must be more than 3 char legth<BR>"; $status= "NOTOK"; } if ( $password <> $password2 ) { $msg=$msg."Both passwords are not matching<BR>"; $status= "NOTOK"; } if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) <--------------- (Line 50) { $msg=$msg."enter valid email address<BR>"; $status= "NOTOK"; } if ($agree<>"yes") { $msg=$msg."You must agree to terms and conditions<BR>"; $status= "NOTOK"; } if($status<>"OK") { echo "<font face='Verdana' size='2' color=red>$msg</font><br><input type='button' value='Retry' onClick='history.go(-1)'>"; }else{ // if all validations are passed. $query=mysql_query("INSERT INTO signup(userid,password,email,Fname,Lname) values('$userid','$password','$email','$fname','$lname')");; echo "<font face='Verdana' size='2' color=green>Welcome, You have successfully signed up<br><br><a href=login.php>Click here to login</a><br></font>"; } } ?> </body> </html> File Name :<include file> <HTML> <HEAD> <TITLE>Connecting to Database</TITLE> </HEAD> <BODY> <?php $db = "quantas"; mysql_connect("localhost","root","") or die (mysql_error()); mysql_select_db($db); ?> </BODY> </HTML> Quote Link to comment https://forums.phpfreaks.com/topic/224742-issue-with-validating-the-login-information-and-inserting-in-to-database/ Share on other sites More sharing options...
Pikachu2000 Posted January 17, 2011 Share Posted January 17, 2011 Post your questions in the correct forum. Make use of the forum's . . . BBCode tags when posting code. Quote Link to comment https://forums.phpfreaks.com/topic/224742-issue-with-validating-the-login-information-and-inserting-in-to-database/#findComment-1160889 Share on other sites More sharing options...
Jinidoc Posted January 17, 2011 Author Share Posted January 17, 2011 Also tried change the below code to if(mysql_num_rows(mysql_query("SELECT userid FROM signup WHERE userid = '$userid'"))) to if(mysql_num_rows(mysql_query("SELECT * FROM signup WHERE userid = '$userid'"))) but still No go Quote Link to comment https://forums.phpfreaks.com/topic/224742-issue-with-validating-the-login-information-and-inserting-in-to-database/#findComment-1160894 Share on other sites More sharing options...
Muddy_Funster Posted January 17, 2011 Share Posted January 17, 2011 if(mysql_num_rows(mysql_query("SELECT userid FROM signup WHERE userid = '$userid LIMIT 1' "))) <-------------------(line 32) is your original code. You have wrapped the LIMIT 1 inside the single quotes, which will result in an error in the sql. try something like this: $qry = 'SELECT userid FROM signup WHERE userid = "'.$userid.'" LIMIT 1'; $result = mysql_query($qry) or die ('Error in the SQL SELECT QUERY! : '.mysql_error()); if(mysql_num_rows($result) > 0 ){ //your error code here } Quote Link to comment https://forums.phpfreaks.com/topic/224742-issue-with-validating-the-login-information-and-inserting-in-to-database/#findComment-1160912 Share on other sites More sharing options...
Jinidoc Posted January 17, 2011 Author Share Posted January 17, 2011 Hi I was able to insert the data by using the below code: if(mysql_num_rows(mysql_query("SELECT userid FROM signup WHERE userid = '$userid' "))) { $msg=$msg."Userid already exists. Please try another one<BR>"; $status= "NOTOK"; } There was just a mistake with my database name. But now when execute i get an error "Deprecated: Function eregi() is deprecated in C:\wamp\www\signupck.php on line 50 Welcome, You have successfully signed up" Line (50)------------------------------>(line 50) if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $msg=$msg."enter valid email address<BR>"; $status= "NOTOK"; } Thanks in Advanced Quote Link to comment https://forums.phpfreaks.com/topic/224742-issue-with-validating-the-login-information-and-inserting-in-to-database/#findComment-1161047 Share on other sites More sharing options...
Muddy_Funster Posted January 17, 2011 Share Posted January 17, 2011 ereg has been depreciated, it's not supported any more as of PHP 4. look into this: http://www.php.net/manual/en/ref.pcre.php Quote Link to comment https://forums.phpfreaks.com/topic/224742-issue-with-validating-the-login-information-and-inserting-in-to-database/#findComment-1161052 Share on other sites More sharing options...
Jinidoc Posted January 17, 2011 Author Share Posted January 17, 2011 Can please let me now the code to validate the email address Quote Link to comment https://forums.phpfreaks.com/topic/224742-issue-with-validating-the-login-information-and-inserting-in-to-database/#findComment-1161058 Share on other sites More sharing options...
Muddy_Funster Posted January 17, 2011 Share Posted January 17, 2011 read through the examples for preg_match() you will see the similarities to what you are using and should be able to fill in the blanks. I have never used it, so can't really comment on its application. although I am sure there are plenty that have. Quote Link to comment https://forums.phpfreaks.com/topic/224742-issue-with-validating-the-login-information-and-inserting-in-to-database/#findComment-1161064 Share on other sites More sharing options...
medved Posted January 27, 2011 Share Posted January 27, 2011 Hi, I have similar problem: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /data/www/www_oobtrebic_cz/mcr11/libraries/joomla/database/database/mysql.php on line 342 Content of mysql.php: /** * Description * * @access public * @return int The number of rows returned from the most recent query. */ function getNumRows( $cur=null ) { return mysql_num_rows( $cur ? $cur : $this->_cursor ); } /** * This method loads the first field of the first row returned by the query. * * @access public * @return The value returned in the query or null if the query failed. */ function loadResult() { if (!($cur = $this->query())) { return null; } $ret = null; if ($row = mysql_fetch_row( $cur )) { $ret = $row[0]; } mysql_free_result( $cur ); return $ret; } Row 342 is red. Can anybody help me? Thaks a lot§ Quote Link to comment https://forums.phpfreaks.com/topic/224742-issue-with-validating-the-login-information-and-inserting-in-to-database/#findComment-1166179 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.