ubuntu Posted May 11, 2007 Share Posted May 11, 2007 Dear all, Below is my code, I couldn't find any error, what's wrong with my coding. Thanks for your kind attention Regards. <?php include('info.config'); //check for required fields error_reporting( E_ALL ); $error = NULL; if (!$_POST['fullname']) { $error .= "Full name is required.<br>"; } if (!$_POST['ic_no']) { $error .= "NRIC no. is required.<br>"; } if (!$_POST['gender']) { $error .= "Gender is required.<br>"; } if (!$_POST['address']) { $error .= "Address is required.<br>"; } if (!$_POST['city']) { $error .= "City is required.<br>"; } if (!$_POST['state']) { $error .= "State is required.<br>"; } if (!$_POST['contact_no']) { $error .= "Contact Tel No. is required.<br>"; } if (!$_POST['hp_no']) { $error .= "Handphone no. is required.<br>"; } if (!$_POST['email']) { $error .= "Email is required.<br>"; } if (!$_POST['username']) { $error .= "Username is required.<br>"; } if (!$_POST['password']) { $error .= "Password is required.<br>"; } if (!$_POST['confirmpassword']) { $error .= "Confirm password is required.<br>"; } if (!is_null($error)) { die($error); } //connect to server and select database $connection = mysql_connect("$host", "$user", "$password") or die(mysql_error()); $db = mysql_select_db($database, $connection) or die(mysql_error()); //build and issue query $sql = "SELECT * FROM pendaftaran WHERE username = '" . $_POST['username'] . "'"; $result = mysql_query($sql) or die (mysql_error()); //get the number of rows in the result set $num = mysql_num_rows($result); //if username already exists, print the message if ($num != 0) { die("The Username " . $_POST['username'] . " already exists, please select another username."); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/50892-solved-whats-wrong-with-my-code-i-cant-run-it/ Share on other sites More sharing options...
btherl Posted May 11, 2007 Share Posted May 11, 2007 Can you tell us what you expect your code to do and what it actually does? We are not mind-readers Quote Link to comment https://forums.phpfreaks.com/topic/50892-solved-whats-wrong-with-my-code-i-cant-run-it/#findComment-250299 Share on other sites More sharing options...
ubuntu Posted May 11, 2007 Author Share Posted May 11, 2007 I want to test if the user had enter the same username that exists in database, then it will notify user. Quote Link to comment https://forums.phpfreaks.com/topic/50892-solved-whats-wrong-with-my-code-i-cant-run-it/#findComment-250302 Share on other sites More sharing options...
StormTheGates Posted May 11, 2007 Share Posted May 11, 2007 And its not printing out any errors or anything? Also your script is insecure, you never want to use a direct user input in an SQL query unless youve checked it for SQL injection. Although I dont see any definitions for the variables for the db connector. So maybe its not connecting? Quote Link to comment https://forums.phpfreaks.com/topic/50892-solved-whats-wrong-with-my-code-i-cant-run-it/#findComment-250303 Share on other sites More sharing options...
btherl Posted May 11, 2007 Share Posted May 11, 2007 We need you to tell us the error message you get. What do you see when you run this script? Quote Link to comment https://forums.phpfreaks.com/topic/50892-solved-whats-wrong-with-my-code-i-cant-run-it/#findComment-250307 Share on other sites More sharing options...
ubuntu Posted May 11, 2007 Author Share Posted May 11, 2007 It only display the message Address is required. Quote Link to comment https://forums.phpfreaks.com/topic/50892-solved-whats-wrong-with-my-code-i-cant-run-it/#findComment-250310 Share on other sites More sharing options...
btherl Posted May 11, 2007 Share Posted May 11, 2007 Is your form supplying the address to your script? Check your form for something like <input name="address" type="text"> Quote Link to comment https://forums.phpfreaks.com/topic/50892-solved-whats-wrong-with-my-code-i-cant-run-it/#findComment-250313 Share on other sites More sharing options...
ubuntu Posted May 11, 2007 Author Share Posted May 11, 2007 Thank you btherl, yes, it's my mistake there. Appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/50892-solved-whats-wrong-with-my-code-i-cant-run-it/#findComment-250428 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.