blink359 Posted April 26, 2009 Share Posted April 26, 2009 my form isnt submitting into the database please help <?php $dbhost = "localhost"; $dbuser = "nathan"; $dbpass = "your_password"; $dbname = "logon"; mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname); $user = $_POST['user']; $pass = $_POST['pass']; $flag = $_POST['flag']; $success = true; $problemMessage = ""; if(!$user || !$pass || !$flag) { $problemMessage = "Please fill in all required fields"; $success = false; } else { $query = "SELECT acct FROM accounts WHERE login = '".$user."' AND password = '".$pass."';"; $result = mysql_query($query) or die(mysql_error()); $numrows = mysql_num_rows($result); echo "<tr><td align=center>"; if($newpass != $newpass2) { die("Your new passwords did not match"); } if($numrows == 0) { die("Invalid account name or password!"); } $query = "UPDATE accounts SET flags = '".$flag."' WHERE login = '".$user."';"; $result = mysql_query($query) or die(mysql_error()); echo "Your expansion settings has been changed"; } ?> <html> <head> <title>Expansion Settings</title> </head> <body> Account Creation Page<br> Username: <input name="user" type="text"/> <br> Password: <input name="pass" type="text"/> <br> Pre TBC <input type="radio" name="flag" value="0"> <br> TBC Enabled <input type="radio" name="flag" value="8"> <br> Wotlk Enabled <input type="radio" name="flag" value="24"> <br> <input type=submit name=submit value=Submit> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/155726-solved-form-isnt-submitting/ Share on other sites More sharing options...
gevans Posted April 26, 2009 Share Posted April 26, 2009 You need to look at your html, you have no form tag <form method="POST OR GET" action="URL"> the form... </form> Quote Link to comment https://forums.phpfreaks.com/topic/155726-solved-form-isnt-submitting/#findComment-819667 Share on other sites More sharing options...
blink359 Posted April 26, 2009 Author Share Posted April 26, 2009 Still doesnt change anything in the DB Quote Link to comment https://forums.phpfreaks.com/topic/155726-solved-form-isnt-submitting/#findComment-819671 Share on other sites More sharing options...
gevans Posted April 26, 2009 Share Posted April 26, 2009 Post the code you have now Quote Link to comment https://forums.phpfreaks.com/topic/155726-solved-form-isnt-submitting/#findComment-819672 Share on other sites More sharing options...
blink359 Posted April 26, 2009 Author Share Posted April 26, 2009 <?php $dbhost = "localhost"; $dbuser = "nathan"; $dbpass = "your_password"; $dbname = "logon"; mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname); $user = $_POST['user']; $pass = $_POST['pass']; $flag = $_POST['flag']; $success = true; $problemMessage = ""; if(!$user || !$pass || !$flag) { $problemMessage = "Please fill in all required fields"; $success = false; } else { $query = "SELECT acct FROM accounts WHERE login = '".$user."' AND password = '".$pass."';"; $result = mysql_query($query) or die(mysql_error()); $numrows = mysql_num_rows($result); echo "<tr><td align=center>"; if($newpass != $newpass2) { die("Your new passwords did not match"); } if($numrows == 0) { die("Invalid account name or password!"); } $query = "UPDATE accounts SET flags = '".$flag."' WHERE login = '".$user."';"; $result = mysql_query($query) or die(mysql_error()); echo "Your expansion settings has been changed"; } ?> <html> <head> <title>Expansion Settings</title> </head> <body> <form method="POST" action=""> Expansion Settings<br> Username: <input name="user" type="text"/> <br> Password: <input name="pass" type="text"/> <br> Pre TBC <input type="radio" name="flag" value="0"> <br> TBC Enabled <input type="radio" name="flag" value="8"> <br> Wotlk Enabled <input type="radio" name="flag" value="24"> <br> <input type=submit name=submit value=Submit> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/155726-solved-form-isnt-submitting/#findComment-819677 Share on other sites More sharing options...
gevans Posted April 26, 2009 Share Posted April 26, 2009 Is there any more code? There's a few problems. Where are you getting the following variables from? if($newpass != $newpass2) { You're not checkling if the form has been submitted. You're attempting to run the queries on ever page load. The following code is a rough fix, but there's still the question of the random $newpass check... <?php if(isset($_POST['submit'])) { $dbhost = "localhost"; $dbuser = "nathan"; $dbpass = "your_password"; $dbname = "logon"; mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname); $user = $_POST['user']; $pass = $_POST['pass']; $flag = $_POST['flag']; $success = true; $problemMessage = ""; if(!$user || !$pass || !$flag) { $problemMessage = "Please fill in all required fields"; $success = false; } else { $query = "SELECT acct FROM accounts WHERE login = '$user' AND password = '$pass'"; $result = mysql_query($query) or die(mysql_error()); $numrows = mysql_num_rows($result); echo "<tr><td align=center>"; if($newpass != $newpass2) { die("Your new passwords did not match"); } if($numrows == 0) { die("Invalid account name or password!"); } $query = "UPDATE accounts SET flags = '".$flag."' WHERE login = '".$user."';"; $result = mysql_query($query) or die(mysql_error()); if($result) echo "Your expansion settings has been changed"; else echo "Nothing changed"; } } ?> <html> <head> <title>Expansion Settings</title> </head> <body> <form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>"> Expansion Settings<br> Username: <input name="user" type="text"/> <br> Password: <input name="pass" type="text"/> <br> Pre TBC <input type="radio" name="flag" value="0"> <br> TBC Enabled <input type="radio" name="flag" value="8"> <br> Wotlk Enabled <input type="radio" name="flag" value="24"> <br> <input type="submit" name="submit" value="Submit"> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/155726-solved-form-isnt-submitting/#findComment-819681 Share on other sites More sharing options...
blink359 Posted April 26, 2009 Author Share Posted April 26, 2009 Ah i sorta edited one of my other scripts Quote Link to comment https://forums.phpfreaks.com/topic/155726-solved-form-isnt-submitting/#findComment-819686 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.