Tylor_Famous Posted February 12, 2008 Share Posted February 12, 2008 Please help me out a bit. It should be an easy question seeing as I am new to php. I am working on a new login form for people to create accounts. I want to have the form and the actual php query code on the same page. Here is my code... <?php //Check for required fields from signup form if ($sending == "yes"){ if ((!isset($_POST["f_name"])) || (!isset($_POST["l_name"])) || (!isset($_POST["email"])) || (!isset($_POST["username"])) || (!isset($_POST["password1"])) ) { $login_message = "You must fill out all the fields."; exit; } if ( ($_POST["password1"]) !== ($_POST["password2"]) ){ $login_message = "Passowords don't match!"; exit; } mysql_connect("myserver", "login", "pass"); mysql_select_db("db"); $sql = "INSERT INTO accounts (`id` , `f_name` , `l_name` , `email` , `username` , `password` ) VALUES ('' , '".$_POST["f_name"]."' , '".$_POST["l_name"]."' , '".$_POST["email"]."' , '".$_POST["username"]."' , PASSWORD('".$_POST["password1"]."') );"; $result = mysql_query($sql) or die (mysql_error()); $login_message = "Thank you for making an account. Your account information is as follows. <br /> Name: '".$_POST["f_name"]."' '".$_POST["l_name"]."'<br /> Email: '".$_POST["email"]."' <br /> Username: '".$_POST["username"]."'<br /> Password: '".$_POST["password1"]."'<br />"; } else { exit; } ?> <?php echo "$login_message" ?> <form action="<?=$PHP_SELF?>" method="post" name="signup"> <p>First Name:<br /> <input name="f_name" type="text" maxlength="20" /></p> <p>Last Name:<br /> <input name="l_name" type="text" maxlength="20" /></p> <p>Email:<br /> <input name="email" type="text" maxlength="150" /></p> <p>Username:<br /> <input name="username" type="text" maxlength="20" /></p> <p>Password:<br /> <input name="password1" type="password" size="20" /></p> <p>Retype Password:<br /> <input name="password2" type="password" size="20" /> </p> <input name="sending" type="hidden" value="yes"> <input value="Create Account" type="submit" /> </form> As you can see, right away the php code shouldn't start to run because of the if statement if ($sending == "yes"){ And sending won't equal "yes" until they create an account where there is a hidden input with a value of "yes". Then the code should run through again and see that Sending = "yes". Well that's not the case for some reason. Right away it seems to disregard the first if statement and just go right on down and send a blank query. Please feel free to test it out and see if you can help me out at all. Thanks for any help! If I enter in the info and send it off it goes in fine. I just need to stop it from sending the blank query. P.S. Like I said before I am new to php so please explain it like you would if you were talking to a monkey. ;D Quote Link to comment https://forums.phpfreaks.com/topic/90594-every-refresh-sends-a-blank-query/ Share on other sites More sharing options...
pocobueno1388 Posted February 12, 2008 Share Posted February 12, 2008 First, change your form to this <form action="<?=$PHP_SELF?>" method="post" name="signup"> <p>First Name:<br /> <input name="f_name" type="text" maxlength="20" /></p> <p>Last Name:<br /> <input name="l_name" type="text" maxlength="20" /></p> <p>Email:<br /> <input name="email" type="text" maxlength="150" /></p> <p>Username:<br /> <input name="username" type="text" maxlength="20" /></p> <p>Password:<br /> <input name="password1" type="password" size="20" /></p> <p>Retype Password:<br /> <input name="password2" type="password" size="20" /> </p> <input value="Create Account" type="submit" name="submit"/> </form> I took out the hidden input named "sending" and gave the submit button a name. Now change this line if ($sending == "yes"){ To if (isset($_POST['submit'])){ Then you should be set Quote Link to comment https://forums.phpfreaks.com/topic/90594-every-refresh-sends-a-blank-query/#findComment-464503 Share on other sites More sharing options...
Tylor_Famous Posted February 12, 2008 Author Share Posted February 12, 2008 Thank you for the reply! Although that doesn’t seem to help :-\. I made the changes as you said but it didn't work. I am including this file into another main page and when I try to load the main page it seems to stop loading the page once it gets to the included login form. It seems weird but that’s what it does. Everything beneath the spot where the login form just stops getting loaded. I have NO idea why this would be! Quote Link to comment https://forums.phpfreaks.com/topic/90594-every-refresh-sends-a-blank-query/#findComment-464549 Share on other sites More sharing options...
haku Posted February 12, 2008 Share Posted February 12, 2008 Post your current code and a link to the live page. Quote Link to comment https://forums.phpfreaks.com/topic/90594-every-refresh-sends-a-blank-query/#findComment-464571 Share on other sites More sharing options...
Lamez Posted February 12, 2008 Share Posted February 12, 2008 try if ($sending == ('yes')){ //other code } Quote Link to comment https://forums.phpfreaks.com/topic/90594-every-refresh-sends-a-blank-query/#findComment-464573 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.