VaporX07 Posted July 31, 2007 Share Posted July 31, 2007 Hey PHPFreak Community, I'm new to PHP and I'm just trying to get a simple log in script working... I have the intention of the the script running after the submit button is pressed on my form, but when I do so, none of the information I have processed gets inserted to my DB... I know my DB settings are right... I can't even get a simple echo onto the screen after the submit button is pressed to know verify that atleast the script is executing... is this because of my first if statement condition? If anyone could please take a look at my code, and point out whats wrong, I would GREATLY appreciate it! <?php //Connect to DB mysql_connect("localhost", "root", "***my secret password ***") or die (mysql_error()); //Select DB mysql_select_db("oiam") or die (mysql_error()); //Run code only if submitted... if (isset($_POST['submit'])){ //Check to see if script executes... does not run as of now? possibly my "if" condition? echo "hellooo"; //Check for blank fields... if(!$_POST['username'] | !$_POST['password'] | !$_POST['firstname'] | !$_POST['lastname'] | !$_POST['email']){ die('You did not fill in all the fields.'); } //Check if username is taken already... if(!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']);} $usercheck = $_POST['username']; $check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //If username is taken, display message... if($check2 != 0){ die('Sorry, the username '.$_POST['username'].' is already in use.');} //Insert registration into DB... $insert = "INSERT INTO users (username, password, firstname, lastname, email) VALUES ('".$_POST['username']."', '".$_POST['password']."', '".$_POST['firstname']."', '".$_POST['lastname']."', '".$_POST['email']."')"; $add_member = mysql_query($insert); } else { } ?> <html> <title> Register Page </title> <body> <form name="input" action="" method="post"> User Name:<input type="text" name="username"></br> Password:<input type="password" name="password" size="10"></br> First Name: <input type="text" name="firstname"></br> Last Name:<input type="text" name="lastname"></br> Email:<input type="text" name="email"></br></br> <input type="submit" value="Register"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/62602-quick-fix-new-geek-to-php/ Share on other sites More sharing options...
btherl Posted July 31, 2007 Share Posted July 31, 2007 Try adding name="submit" to your submit control. If that doesn't work, add var_dump($_POST) before your if statement, so you can see exactly what is being posted. Quote Link to comment https://forums.phpfreaks.com/topic/62602-quick-fix-new-geek-to-php/#findComment-311615 Share on other sites More sharing options...
trq Posted July 31, 2007 Share Posted July 31, 2007 Youn need to name your submit button in order for your first if() condition to execute. <input type="submit" name="submit" value="Register"> Also... or is || not | this line.... if(!$_POST['username'] | !$_POST['password'] | !$_POST['firstname'] | !$_POST['lastname'] | !$_POST['email']){ will need to be.... if(!$_POST['username'] || !$_POST['password'] || !$_POST['firstname'] || !$_POST['lastname'] || !$_POST['email']){ Quote Link to comment https://forums.phpfreaks.com/topic/62602-quick-fix-new-geek-to-php/#findComment-311617 Share on other sites More sharing options...
Foser Posted July 31, 2007 Share Posted July 31, 2007 Im a bit short of time since I need to catch the bus but something I see your doing and I think you should avoid at all cost is this line: <?php $_POST['username'] = addslashes($_POST['username']);} $usercheck = $_POST['username']; ?> your comfusing itself because your changing the value of a global variable. change he $_POST['username'] = addslashes($_POST['username']); to a normal var. like $username_as = addslashes($_POST['username']); Quote Link to comment https://forums.phpfreaks.com/topic/62602-quick-fix-new-geek-to-php/#findComment-311619 Share on other sites More sharing options...
VaporX07 Posted July 31, 2007 Author Share Posted July 31, 2007 ahh shoot! that was such a newb thing to forget the name of the submit button in my control... thanks for the relies everyone! it worked perfectly after naming my submit button... i also edited my || sytanx as needed, thanks again for the help! i really appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/62602-quick-fix-new-geek-to-php/#findComment-312202 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.