steviemac Posted July 1, 2007 Share Posted July 1, 2007 Let me start by saying I am new to PHP. I have learned a lot at PHPfreaks but I'm a little stumped right now. I am trying to check if a user is in a db so they can register to view a page. This is the code <?PHP include 'dbmembers.php' ?> <?PHP ini_set('display_errors', 1) ; error_reporting(E_ALL); { $query = "SELECT last_name keynumber FROM table WHERE last_name = '$last_name' && keynumber = '$keynumber'"; $result = mysql_query($query) or die ("Couldn't connect to DataBase"); $record=mysql_num_rows($result); if ($record == 0)//not registered { echo "<P>You are not a registered user of this web site. </p>";exit; } } ?> I an getting the following error Notice: Undefined variable: last_name in /home/site/public_html/register_members.php on line 64 Notice: Undefined variable: keynumber in /home/site/public_html/register_members.php on line 64 Can any one tell me what I am doing wrong? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 1, 2007 Share Posted July 1, 2007 You need to separate your field names by commas. Change this: $query = "SELECT last_name keynumber FROM table WHERE last_name = '$last_name' && keynumber = '$keynumber'"; To: $query = "SELECT last_name, keynumber FROM table WHERE last_name = '$last_name' && keynumber = '$keynumber'"; Quote Link to comment Share on other sites More sharing options...
steviemac Posted July 1, 2007 Author Share Posted July 1, 2007 I tried that before and I just did it again and I get the same error. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 1, 2007 Share Posted July 1, 2007 I don't think you are showing us the correct part of the code where the error is coming from. Could you post more of it? Also, you might want to change this line: $result = mysql_query($query) or die ("Couldn't connect to DataBase"); To: $result = mysql_query($query) or die (mysql_error()); Just in case there is an error in the query. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 1, 2007 Share Posted July 1, 2007 Did you give a value to the variables $last_name and $keynumber earlier in your script? Quote Link to comment Share on other sites More sharing options...
steviemac Posted July 1, 2007 Author Share Posted July 1, 2007 OK here is everything. What bothers me is that I use the same script on a different server for another web site and it works. Oh well.. This is the form <table border='0' width='400' cellspacing='0' cellpadding='0' align=center> <form name="form1" method="post" action="register_members.php" onSubmit="return validateCompleteForm(this, 'error');"><input type=hidden name=todo value=post> <tr><td align=center colspan=2 height="22" class="gray"><p align="center"><b>Signup<br> <span style="color: red; font-size: 8px;">All Form Fields Are Required</span></b></p></td></tr> <tr ><td height="32"><P>User ID</P></td><td ><input type="text" name="userName" value="" required="1" regexp="/^\w*$/" minlength="4" realname="User ID"></td></tr> <tr><td height="32"><P>Password</P></td><td ><input type="password" name="password" required="1" regexp="/^\w*$/" realname="Password"></td></tr> <tr ><td height="33"><P>Re-enter Password</P></td><td ><input type="password" name="password2" required="1" regexp="/^\w*$/" realname="Password2"></td></tr> <tr> <td height="32"><P>E_Mail Address</P></td> <td ><input type="text" name="email" required="1" regexp="/^\w*$/" realname="E-Mail Address"></td></tr> <tr> <td height="32"><P>Key Number</P></td> <td ><input type="text" name="keynumber" required="1" regexp="/^\w*$/" realname="Key Number"></td></tr> <tr > <td height="32"><P>Last Name</P></td> <td > <input type="text" name="last_name" required="1" regexp="/^\w*$/" realname="Last Name"></td></tr> <tr > <td height="32"><P>First Name</P></td> <td ><input type="text" name= "first_name" required="1" regexp="/^\w*$/" realname="First Name"></td></tr> <tr><td align=center colspan="2" class="gray"><input type=submit value=Signup></td></tr> </table> <P align="center">Already a member? <a href="members.php">Please Login</a></P> And this is all the code <?PHP include 'dbmembers.php' ?> <?PHP //displays in email Table ini_set('display_errors', 1) ; error_reporting(E_ALL); { $query = "SELECT last_name, keynumber FROM table WHERE last_name = '$last_name' && keynumber = '$keynumber'"; $result = mysql_query($query) or die (mysql_error()); $record=mysql_num_rows($result); if ($record == 0)//not registered { echo "<P>You are not a registered user of this form.</p>";exit; } } ?> <? if(isset($todo) and $todo=="post"){ $status = "OK"; $msg=""; // if userid is less than 5 char then status is not ok if(!isset($userName) or strlen($userName) < 5){ $msg=$msg."User id should be 6 characters in length.<BR>"; $status= "NOTOK";} if ( strlen($password) < 5 ){ $msg=$msg."Password must be more than 5 char length<BR>"; $status= "NOTOK";} if ( $password <> $password2 ){ $msg=$msg."Both passwords are not matching.<BR>"; $status= "NOTOK";} if (!preg_match("/^([a-zA-Z0-9])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/", $_POST['email'])){ $msg=$msg."Your E-Mail Address does not appear to be valid<BR>"; $status= "NOTOK";} $encript_pass = md5($password); 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 myuser (first_name, last_name, userName, userPass, email) VALUES ('{$_POST['$first_name']}', ({$_POST['$last_name']}', '{$_POST['$userName']}', '{$_POST['$encript_pass']}', '{$_POST['$email']}'"); echo "<P><font color=green>Welcome, You have successfully signed up<br><br> <form action=\"/membership/index.php\" method=\"POST\"> <input type=\"hidden\" name=\"action\" value=\"login\"> Username <input type=\"text\" name=\"userName\"> Password <input type=\"password\" name=\"userPass\"><br> <input type=\"submit\" value=\"Login\"> </form> </font></P>"; } } ?> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 1, 2007 Share Posted July 1, 2007 Above this line: $query = "SELECT last_name, keynumber FROM table WHERE last_name = '$last_name' && keynumber = '$keynumber'"; Put the following code: <?php $last_name = $_POST['last_name']; $keynumber = $_POST['keynumber']; ?> You might want to define the rest of your POST variables from the form like that as well. On your other server you probably had register_globals on, and on this server you don't. Quote Link to comment Share on other sites More sharing options...
steviemac Posted July 1, 2007 Author Share Posted July 1, 2007 That was it. I will take care of the rest of the code and I will go back to my other server and re code it. Thanks for your help. Quote Link to comment 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.