Hi,
I've been racking my brain for the last few days to figure out what is wrong with my PHP coding. I've managed to get the default value from my combo box into my database, but when I change the option it is breaking on me.
I have reduced my html to just to combo box for you, please can you help me?
Here is my HTML:
<html>
<body>
<form action="Signup.php" method="post">
Username: <input type="text" name="Username" /> <br/>
Password: <input type="text" name="Password" /> <br/>
Secret Question: <select name="Secret_Question">
<option value="What is your mother's maiden name?">What is your mother's maiden name?</option>
<option value="What is your place of birth?">What is your place of birth?</option>
<option value="What is your favourite food?"selected="selected">What is your favourite food?</option>
<option value="What is your favourite pet's name?">What is your favourite pet's name?</option>
</select> <br/
<input type="submit" value="Submit" />
</form>
</body>
</html>
I have not bothered with any validation yet, I just want to learn this basic lesson first.
Here is my PHP:
//DECLARING VARIABLES
$host = "I have my IP address in here"; // Host
$dbuser="web41-admin-2"; // Mysql username
$dbpassword="I have my password here"; // Mysql password
$db_name="web41-admin-2"; // Database name
$tbl_name="Users"; // Table name
$Username = $_POST;
$Password = $_POST;
$Secret_Question = $_POST;
$Secret_Answer = $_POST;
$first_name = $_POST;
$surname = $_POST;
$email = $_POST;
//ESTABLISHING CONNECTION
$con = mysql_connect("$host","$dbuser","$dbpassword");
if (!$con) //IF CONNECTION FAILS
die('Connection failed: ' . mysql_error()); //OUTPUTS ERROR MESSAGE
Else
Echo "It worked"; //INFORMS OF SUCCESS
mysql_select_db($db_name, $con); // ALL FUNCTIONAL TO THIS POINT
$query = "INSERT into Users values
('".$Username."','".$Password."','".$Secret_Question."','".$Secret_Answer."','".$first_name."','".$surname."','".$email."')";
$result = mysql_query($query);
if ($result)
echo mysql_affected_rows(). "user added";
?>
Also any feedback about my coding style will be greatly appreciated as I am a complete beginner.