daveh33 Posted October 18, 2007 Share Posted October 18, 2007 <?php session_start(); include("dbconnect.php"); $username = $_POST['UserName']; if (!$username) { echo "You Must enter a username<br>"; $problem = "error"; } $result = mysql_query("SELECT * from registration WHERE username='$username'"); $row = mysql_fetch_array( $result ) or die(mysql_error()); $dbusername = $row['username']; $numrows = $row['numrows']; if ($numrows>0) { echo "Sorry that username is not avaialbe, please go back and try again.<br>"; $problem = "error"; } $password = $_POST['UserPassword']; if (!$password) { echo "You Must enter a password<br>"; $problem = "error"; } $dob = $_POST['UserDob']; if (!$dob) { echo "You Must enter Your date of birth<br>"; $problem = "error"; } $email = $_POST['UserEmail']; $mobile = $_POST['UserMobile']; if (!$mobile) { echo "You Must enter your mobile number<br>"; $problem = "error"; } if ($problem=="error") { echo "Your registration was not sucessful<br>"; } else { mysql_query("INSERT INTO registration (username, password, age, msid, email) VALUES ('$username', '$password', '$dob', '$mobile', '$email')"); echo "<p>Registration sucessful, welcome $username!"; } ?> When I run the above code and set the value of $username to nothing - the code prints "You Must enter a username" When I assign text to $username and the other variables - the page prints nothing... Can anyone see whats wrong??? Quote Link to comment https://forums.phpfreaks.com/topic/73836-help-my-registration-code-stops-processing-for-no-reason/ Share on other sites More sharing options...
BlueSkyIS Posted October 18, 2007 Share Posted October 18, 2007 can we see the form that POSTs to the script? Quote Link to comment https://forums.phpfreaks.com/topic/73836-help-my-registration-code-stops-processing-for-no-reason/#findComment-372522 Share on other sites More sharing options...
steve448 Posted October 18, 2007 Share Posted October 18, 2007 Try changing the last mysql_query to: mysql_query("INSERT INTO registration (username, password, age, msid, email) VALUES ('$username', '$password', '$dob', '$mobile', '$email')") or die(mysql_error()); I.e. Added or die(mysql_error()); So we can make sure the sql is valid and not killing the script Quote Link to comment https://forums.phpfreaks.com/topic/73836-help-my-registration-code-stops-processing-for-no-reason/#findComment-372536 Share on other sites More sharing options...
daveh33 Posted October 18, 2007 Author Share Posted October 18, 2007 Added or die(mysql_error()); it still displays nothing ??? the form code is below <form id="Form1" name="Form1" method="post" action="processregistration.php"> <font color="#400040" face="Arial">Select a User Name</font><br> <input name="UserName" maxlength="30"/><br> <font color="#400040" face="Arial">Select your own secret Password</font><br> <input name="UserPassword" maxlength="30" type="password"/><br> <font color="#400040" face="Arial">Age</font><br> <input name="UserDob" maxlength="2"/><br> <font color="#400040" face="Arial">Email Address</font><br> <input name="UserEmail" maxlength="50"/><br> <font color="#400040" face="Arial">Mobile Number (International Format)</font><br> <input name="UserMobile" maxlength="19"/><br> <font color="#400040" face="Arial">eg: UK = 447123456789</font><br> <br> <input name="Submit" type="submit" value="Submit"/><br> <br> Quote Link to comment https://forums.phpfreaks.com/topic/73836-help-my-registration-code-stops-processing-for-no-reason/#findComment-372551 Share on other sites More sharing options...
BlueSkyIS Posted October 18, 2007 Share Posted October 18, 2007 close your form? </form> also would like to see or die(mysql_error()) after this: $result = mysql_query("SELECT * from registration WHERE username='$username'"); also, define your form field types, e.g., <input type='text' name="UserName" maxlength="30"/> Quote Link to comment https://forums.phpfreaks.com/topic/73836-help-my-registration-code-stops-processing-for-no-reason/#findComment-372555 Share on other sites More sharing options...
steve448 Posted October 18, 2007 Share Posted October 18, 2007 Also try with mysql_error() on the first query, at the moment its just on the mysql_fetch_array I'm assuming you've selected your database in your connection file? Quote Link to comment https://forums.phpfreaks.com/topic/73836-help-my-registration-code-stops-processing-for-no-reason/#findComment-372566 Share on other sites More sharing options...
daveh33 Posted October 18, 2007 Author Share Posted October 18, 2007 Have added the or die - still no change I changed the code for the form to below <input type='text' name="UserName" maxlength="30"/><br> <font color="#400040" face="Arial">Select your own secret Password</font><br> <input type='password' name="UserPassword" maxlength="30"/><br> <font color="#400040" face="Arial">Age</font><br> <input type='text' name="UserDob" maxlength="2"/><br> <font color="#400040" face="Arial">Email Address</font><br> <input type='text' name="UserEmail" maxlength="30"/><br> <font color="#400040" face="Arial">Mobile Number (International Format)</font><br> <input type='text' name="UserMobile" maxlength="19"/><br> <font color="#400040" face="Arial">eg: UK = 447123456789</font><br> <br> <input name="Submit" type="submit" value="Submit"/><br> </form> <br> Quote Link to comment https://forums.phpfreaks.com/topic/73836-help-my-registration-code-stops-processing-for-no-reason/#findComment-372574 Share on other sites More sharing options...
daveh33 Posted October 18, 2007 Author Share Posted October 18, 2007 Also try with mysql_error() on the first query, at the moment its just on the mysql_fetch_array I'm assuming you've selected your database in your connection file? Yes I have used the form to add to the database earlier - it justs stopped working when I added the conditional formatting. Quote Link to comment https://forums.phpfreaks.com/topic/73836-help-my-registration-code-stops-processing-for-no-reason/#findComment-372577 Share on other sites More sharing options...
steve448 Posted October 18, 2007 Share Posted October 18, 2007 To be honest if it's nothing to do with the first mysql_query then I have no idea. Although I would still bet that it is, try commenting that whole section out and running it again. On a slightly related note, I assume you don't have a column in your db called 'numrows' so $numrows = $row['numrows']; if ($numrows>0) { is not going to be any good, you will want to use mysql_num_rows, although this is not going to be your problem at the moment Quote Link to comment https://forums.phpfreaks.com/topic/73836-help-my-registration-code-stops-processing-for-no-reason/#findComment-372598 Share on other sites More sharing options...
daveh33 Posted October 18, 2007 Author Share Posted October 18, 2007 Yes when I comment it out I get the below output You Must enter a password Your registration was not sucessful This is the code: - /*if (!$username) { echo "You Must enter a username<br>"; $problem = "error"; } $result = mysql_query("SELECT * from registration WHERE username='$username'") or die(mysql_error()); $row = mysql_fetch_array( $result ) or die(mysql_error()); $dbusername = $row['username']; $numrows = mysql_num_rows; if ($numrows>0) { echo "Sorry that username is not avaialbe, please go back and try again.<br>"; $problem = "error"; }*/ Quote Link to comment https://forums.phpfreaks.com/topic/73836-help-my-registration-code-stops-processing-for-no-reason/#findComment-372636 Share on other sites More sharing options...
daveh33 Posted October 18, 2007 Author Share Posted October 18, 2007 Can anyone see an error in this code?? /* $result = mysql_query("SELECT * from registration WHERE username ='$username'") or die(mysql_error()); $row = mysql_fetch_array( $result ) or die(mysql_error()); $dbusername = $row['username']; $numrows = mysql_num_rows; if ($numrows>0) { echo "Sorry that username is not avaialbe, please go back and try again.<br>"; $problem = "error"; }*/ Quote Link to comment https://forums.phpfreaks.com/topic/73836-help-my-registration-code-stops-processing-for-no-reason/#findComment-372655 Share on other sites More sharing options...
BlueSkyIS Posted October 18, 2007 Share Posted October 18, 2007 $numrows = mysql_num_rows; should be $numrows = mysql_num_rows($result); Quote Link to comment https://forums.phpfreaks.com/topic/73836-help-my-registration-code-stops-processing-for-no-reason/#findComment-372659 Share on other sites More sharing options...
daveh33 Posted October 18, 2007 Author Share Posted October 18, 2007 OK I have changed that - but when I remove the comments it stops processing like before..... Quote Link to comment https://forums.phpfreaks.com/topic/73836-help-my-registration-code-stops-processing-for-no-reason/#findComment-372664 Share on other sites More sharing options...
steve448 Posted October 18, 2007 Share Posted October 18, 2007 The only thing I can suggest is that you test each line on its own. I would guess that the error is on this line: $result = mysql_query("SELECT * from registration WHERE username ='$username'") or die(mysql_error()); But it is not showing an error because you have error reporting switched off. Are you certain that in your include dbconnect.php file you have selected your database and not just connected to it using mysql_select_db($database_name, $connection_id); Quote Link to comment https://forums.phpfreaks.com/topic/73836-help-my-registration-code-stops-processing-for-no-reason/#findComment-372713 Share on other sites More sharing options...
daveh33 Posted October 18, 2007 Author Share Posted October 18, 2007 yes the dbconnect.php is as below: - <?php $connection = mysql_connect("localhost", "dbusername", "dbpassword"); mysql_select_db("tablename", $connection); ?> Quote Link to comment https://forums.phpfreaks.com/topic/73836-help-my-registration-code-stops-processing-for-no-reason/#findComment-372720 Share on other sites More sharing options...
steve448 Posted October 18, 2007 Share Posted October 18, 2007 Try debugging it like the code below in a separate file away from the other code, so we can really try to isolate the error //this should force it to show the errors error_reporting("E_ALL"); $connection = mysql_connect("localhost", "dbusername", "dbpassword"); mysql_select_db("tablename", $connection); $username = '' //make this equal to a username you know exists so we are sure to get a result //Use if to test if it returns true if($result = mysql_query("SELECT * from registration WHERE username ='$username'")) { echo 'did the mysql_query part<br />'; } if($row = mysql_fetch_array($result)) { echo 'did the mysql_fetch_array part<br />'; } Quote Link to comment https://forums.phpfreaks.com/topic/73836-help-my-registration-code-stops-processing-for-no-reason/#findComment-372737 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.