Another question for you all! I've been coming up against this problem for a while now and just can't seem to work it out myself. Basically I'm trying to use a form to make an entry into the database and although it clocks what the date is (so that bit is working), I can't get the data from the other fields (namely name, gender and breed) to get entered into the MySQL database.
It seems to me that this is probably because at no point are $name, $gender and $breed defined, however I'm basing what I'm doing on this code earlier which definitely does work to put the information into the database (immediately below, the code I'm then having trouble with is posted afterwards) and can't see $uname defined there, either, so I'm really lost as to which bit of this code DOES define these parameters.
<?php
include('connect.php');
include('header.php');
if($loggedin == '1')
die("Sorry matey-o, you can't register another account while you're logged in!");
// Register Script
// So, the register script is a sample of the basic elements of
// coding used in a simple sim game, namely, putting new data
// into databases.
if(isset($_POST['submit']))
{
// trim removes the whitespaces from the beginning and end of text
// this keeps someone from having a username of " "
$uname = trim($_POST['username']);
$email = trim($_POST['email']);
// Make sure all forms were filled out.
if((!isset($_POST['username'])) || (!isset($_POST['pass'])) || (!isset($_POST['email']))
|| ($uname == '') || ($_POST['pass'] == '') || ($_POST['email'] == ''))
die("Please fill out the form completely. <br><br>
<a href=register.php>Continue</a>");
// Make sure name hasn't already been used.
$check = @mysql_query("SELECT id FROM players WHERE username = '$uname'");
$check = @mysql_num_rows($check);
if($check > 0)
die("Sorry, that username has already been taken. Please try again.
<br><br>
<a href=register.php>Continue</a>");
// Make sure email hasn't already been used more than twice.
$check = @mysql_query("SELECT id FROM players WHERE email = '$email'");
$check = @mysql_num_rows($check);
if($check >= 2)
die("Sorry, you already seem to have the maximum number of accounts allowed per person.
<br><br>
<a href=register.php>Continue</a>");
// Encrypt password
$pass = md5($_POST['pass']);
$date = date("m/d/y");
// Finally, create the record.
$newPlayer = @mysql_query("INSERT INTO players (username, password, registered, email) VALUES ('$uname', '$pass', '$date', '$email')") or die("Error: ".mysql_error());
echo 'You have been registered! You may now <a href=index.php>Log in</a>.';
}
else
{
// A simple example of a form.
echo 'Sign up for an account on Sled-League! Just fill in the details below...<br><br>
<form action=register.php method=post>
Username: <input type=text name=username><br>
Password: <input type=password name=pass><br>
Email: <input type=text name=email><br>
<input type=submit name=submit value=Submit>
</form><br>
<a href=index.php>Back to main page</a><br><br>';
}
include('footer.php');
?>
So this is what I'm trying to sort out (below) so that the information is sent to the database. Can anybody suggest how I might get it to transfer across into the database? I want the Dog Name, Dog Breed and Dog Gender to transfer across!
<?php
include('connect.php');
include('header.php');
echo 'The Dog Traders seem to have some dogs for sale! Buy one?<bR><br>';
if(isset($_POST['submit']))
{
// trim removes the whitespaces from the beginning and end of text
// this keeps someone from having a username of " "
$name = trim($_POST['name']);
$gender = trim($_POST['gender']);
$breed = trim($_POST['breed']);
$date = date("m/d/y");
// Finally, create the record.
$newDog = @mysql_query("INSERT INTO dogs (name, gender, breed, date) VALUES ('$name', '$gender', '$breed', '$date')") or die("Error: ".mysql_error());
echo 'You have made a new dog';
}
else
{
// A simple example of a form.
echo '<form action=dogtrader.php method=post>
Dog Name: <input type=text value=name><br>
Gender: <select>
<option value=gender>Male</option>
<option value=gender>Female</option>
</select><br>
Dog Breed: <select>
<option value=breed>Happydog</option>
<option value=breed>Saddog</option>
<option value=breed>Smellydog</option>
</select><br><br>
<input type=submit name=submit value=Submit>
</form>';
}
include('footer.php');
?>
Thanks in advance for any answers!