943,846 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2291
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Aug 12th, 2008
0

Parse error: parse error, unexpected T_STRING on line 40

Expand Post »
Hi, I was wondering if someone could look over my coding? x3 I'm really, really new to PHP (just learning, in fact) and a friend gave me this sample code, but it doesn't seem to work... could someone please help? Thank you so much. <3 Here is the full code:

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. include ('connect.php');
  3. ?>
  4.  
  5. <form name="form1" method="post" action="dogstore.php">
  6. Dog's Name:
  7. <input name="dogname" type="text">
  8. <br>
  9. Dog's Breed:
  10. <select name="dogbreed">
  11. <option value="breed1">Breed</option>
  12. <option value="breed2">Breed</option>
  13. <option value="breed3">Breed</option>
  14. <option value="breed4">Breed</option>
  15. <option value="breed5">Breed</option>
  16. <option value="breed6">Breed</option>
  17. <option value="breed7">Breed</option>
  18. </select>
  19. <br>
  20. Dog's Gender:
  21. <select name="doggender">
  22. <option value="Male">Male</option>
  23. <option value="Female">Female</option>
  24. </select>
  25. <br>
  26. <input type="submit" name="Submit" value="Buy Dog">
  27. </form>
  28.  
  29. <?php
  30. //trim removes the white spaces from the beginning and end of the text
  31. $dogname = trim($_POST['dogname']);
  32. $dogbreed = trim($_POST['dogbreed']);
  33. $doggender = trim($_POST['doggender']);
  34. ?>
  35.  
  36. <?php
  37. //Make sure the name form is filled out.
  38. if ((isset($_POST['dogname']))
  39. || ($_POST['dogname'] == "))
  40. die("Oops! You forgot to fill in the name!");
  41. ?>
  42.  
  43. <?php
  44. $ownerid = $_SESSION['id']
  45. ?>
  46.  
  47. <?php
  48. if ((!isset($_POST['Buy Dog']))
  49. {
  50. echo "Congratulations! You've purchased a dog.";
  51. }
  52. else
  53. {
  54. echo "Congratulations! You've purchased a dog.";}
  55. }
  56. ?>
  57.  
  58. <?php
  59. $dog = @mysql_query("INSERT INTO dogs (ownerid, dogname, dogbreed, doggender)
  60. VALUES ('$ownerid', '$dogname', '$doggender')") or die("Error:
  61. ".mysql_error());
  62. ?>
  63.  
Last edited by Tekmaven; Aug 12th, 2008 at 5:58 am. Reason: Code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
wiccanwolf is offline Offline
10 posts
since Aug 2008
Aug 12th, 2008
0

Re: Parse error: parse error, unexpected T_STRING on line 40

Just wondering, where is line 40?

But some errors I spotted:
1. Your "$ownerid = $_SESSION['id']" needs a semicolon.
1. I think that your if ((!isset($_POST['Buy Dog'])) has an extra parentheses at the beginning.
3. And finally, you don't need to keep on opening and closing the php tags. Unless you have HTML or something else in between them, you should just open the tag at the beginning, and then close it only at the end.
Last edited by Demiloy; Aug 12th, 2008 at 1:37 am.
Reputation Points: 12
Solved Threads: 6
Light Poster
Demiloy is offline Offline
48 posts
since Aug 2008
Aug 12th, 2008
0

Re: Parse error: parse error, unexpected T_STRING on line 40

I just tried your suggestions, and received this error:

Parse error: parse error, unexpected T_BOOLEAN_OR in C:\Program Files\EasyPHP 2.0b1\www\dogstore.php on line 39
Reputation Points: 10
Solved Threads: 0
Newbie Poster
wiccanwolf is offline Offline
10 posts
since Aug 2008
Aug 12th, 2008
0

Re: Parse error: parse error, unexpected T_STRING on line 40

Where's line 39?
Reputation Points: 12
Solved Threads: 6
Light Poster
Demiloy is offline Offline
48 posts
since Aug 2008
Aug 12th, 2008
0

Re: Parse error: parse error, unexpected T_STRING on line 40

If I counted correctly:

die("Oops! You forgot to fill in the name!");
Reputation Points: 10
Solved Threads: 0
Newbie Poster
wiccanwolf is offline Offline
10 posts
since Aug 2008
Aug 12th, 2008
0

Re: Parse error: parse error, unexpected T_STRING on line 40

Wrap your code around [code=php] tags, and post, and they should have automatic line counts. And highlighting, which is tons easier to read.
Last edited by Demiloy; Aug 12th, 2008 at 1:51 am.
Reputation Points: 12
Solved Threads: 6
Light Poster
Demiloy is offline Offline
48 posts
since Aug 2008
Aug 12th, 2008
0

Re: Parse error: parse error, unexpected T_STRING on line 40

I tried it so that I had [*code=php] at the top and [*/code] at the bottom, and it gave me:

Parse error: parse error, unexpected T_BOOLEAN_OR in C:\Program Files\EasyPHP 2.0b1\www\dogstore.php on line 41

Argh, evil code, work already. x.X

Edit: Obvious the code was without the *
Last edited by wiccanwolf; Aug 12th, 2008 at 1:54 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
wiccanwolf is offline Offline
10 posts
since Aug 2008
Aug 12th, 2008
0

Re: Parse error: parse error, unexpected T_STRING on line 40

No, no. Sorry for miscommunication: post that here. Put (no space) and then put the code in between there. Then post all that here so we can see it all better.

Or better yet, edit your original post to do that.
Reputation Points: 12
Solved Threads: 6
Light Poster
Demiloy is offline Offline
48 posts
since Aug 2008
Aug 12th, 2008
0

Re: Parse error: parse error, unexpected T_STRING on line 40

In any case, your if structure:
php Syntax (Toggle Plain Text)
  1. <?php
  2. //Make sure the name form is filled out.
  3. if ((isset($_POST['dogname']))
  4. || ($_POST['dogname'] == "))
  5. die("Oops! You forgot to fill in the name!");
  6. ?>
  7.  
is wrong. You need to put braces around the die function. Also, you need to have two doubles quotes, i.e. || ($_POST['dogname'] == ""))
Last edited by Demiloy; Aug 12th, 2008 at 1:54 am.
Reputation Points: 12
Solved Threads: 6
Light Poster
Demiloy is offline Offline
48 posts
since Aug 2008
Aug 12th, 2008
0

Re: Parse error: parse error, unexpected T_STRING on line 40

Eeeep, I don't understand. x.x Okay, let me fix the if structure like you said, and I'll edit my original post to show what I've got.

I'm sorry this is so difficult, I'm really new to coding, and I really appreciate your help. <3
Reputation Points: 10
Solved Threads: 0
Newbie Poster
wiccanwolf is offline Offline
10 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: $_POST value with <a> link click
Next Thread in PHP Forum Timeline: Trying to commad a script based on timing! But it doesnt work. Please help?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC