Jump to content

[SOLVED] Form isnt submitting


blink359

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/155726-solved-form-isnt-submitting/
Share on other sites

<?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>

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.