Jump to content

Seaholme

Members
  • Posts

    81
  • Joined

  • Last visited

Everything posted by Seaholme

  1. It's hard to articulate this, but basically I have this bit of PHP // Get all the data from the dogs table $result = mysql_query("SELECT * FROM dogs WHERE owner='13'") or die(mysql_error()); And the general set-up is that I want the owner=13 bit to have it so that instead of 13, the database selects anything which has the same 'owner' number as the session ID. Or just basically some way to show only the dogs from the database where the person who's logged into the account is also their owner, rather than every player seeing every dog. I've tried the below, if it helps you to understand what I mean... // Get all the data from the dogs table $result = mysql_query("SELECT * FROM dogs WHERE owner='$_SESSION['id']") or die(mysql_error()); But I just get this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/91/6351791/html/camp.php on line 16 Can anybody help me work out how to tie in the user session (and therefore the user's ID) with picking certain things out of the database? Please let me know if anything needs explaining further! Thanks.
  2. Oops, probably should've tried that out as an option before troubling you all again! Thanks so much for being so helpful!
  3. 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? :/
  4. 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!
  5. Thanks a bunch for that! Fixed! I'll also give indenting a try. It's probably a good idea to start off with good habits!
  6. Hey guys, I'm literally just starting out (as of 2.5 hours ago!!) so I'm guessing this is really simple. I've read some stuff about PHP syntax and what makes things quit out on you, but still can't spot my error. I'm guessing it's probably because I don't know enough :S This isn't actually my coding (unfortunately!), it's one somebody else gave me as a login-style script to learn from, and I've been trying to learn via making modifications to it, so if some parts seem sensible and others totally crazy or whatever, that'd be me :X Anyway, the error reads: Parse error: syntax error, unexpected T_EXIT in /home/content/91/6351791/html/register.php on line 23 I've marked out line 23 for you guys with "***line23***" -- this isn't there in the actual code I'm using! Really appreciate any help and advice. If I've missed giving out any info., please let me know! <?php include('connect.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']); // Make sure all forms were filled out. if((!isset($_POST['username'])) || (!isset($_POST['pass']) || (!isset($_POST['email'])) || ($uname == '') || ($_POST['pass'] == '') || ($email == '')) die("Please fill out the form completely. <br><br> ***line23*** <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 '<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>'; } ?> Thanks in advance!
×
×
  • 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.