Seaholme Posted June 29, 2010 Share Posted June 29, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/206186-which-part-of-this-code-inserts-into-the-database/ Share on other sites More sharing options...
kickstart Posted June 29, 2010 Share Posted June 29, 2010 Hi You input form at the bottom of your non working script doesn't appear to have any names for the various input fields. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/206186-which-part-of-this-code-inserts-into-the-database/#findComment-1078758 Share on other sites More sharing options...
Seaholme Posted June 29, 2010 Author Share Posted June 29, 2010 Thanks! I've managed to get it to put the name into the database, but not having as much luck with the gender/breed info. This is what the table looks like now: echo '<form action=dogtrader.php method=post> Dog Name: <input type=text name=name><br> Gender: <select> <option value=male name=gender>Male</option> <option value=male name=gender>Female</option> </select><br> Dog Breed: <select> <option value=happydog name=breed>Happydog</option> <option value=saddog name=breed>Saddog</option> <option value=smellydog name=breed>Smellydog</option> </select><br><br> <input type=submit name=submit value=Submit> </form>'; Do you have any idea what I've got wrong? :/ Quote Link to comment https://forums.phpfreaks.com/topic/206186-which-part-of-this-code-inserts-into-the-database/#findComment-1078765 Share on other sites More sharing options...
kickstart Posted June 29, 2010 Share Posted June 29, 2010 Hi For a drop down the name goes in the <select> tag rather than the <option>. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/206186-which-part-of-this-code-inserts-into-the-database/#findComment-1078775 Share on other sites More sharing options...
Seaholme Posted June 29, 2010 Author Share Posted June 29, 2010 Oops, probably should've tried that out as an option before troubling you all again! Thanks so much for being so helpful! Quote Link to comment https://forums.phpfreaks.com/topic/206186-which-part-of-this-code-inserts-into-the-database/#findComment-1078777 Share on other sites More sharing options...
Maq Posted June 29, 2010 Share Posted June 29, 2010 Why are you echoing your HTML out? It would be easier to read if you just wrote it as HTML. You should have quotes around attributes values. Your Gender option has 2 values of 'male'. The second should be female. And what kickstart said Quote Link to comment https://forums.phpfreaks.com/topic/206186-which-part-of-this-code-inserts-into-the-database/#findComment-1078779 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.