Jump to content

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.