943,974 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2291
  • PHP RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Aug 12th, 2008
0

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

Never mind.
Last edited by Demiloy; Aug 12th, 2008 at 2:02 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

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

Welcome to DaniWeb -- I'm pretty new here myself.
By the way, you can use the [ code][/code] tags to separate out your code snippets.

A couple pointers to start ...
Use curly brackets {} in your code, even when you can skip them
Use line indentation for successively nested blocks of code
Both of these will help you read your code better and find common problems faster

I found some missing end of line semi-colons (;). Programming is unforgiving of such minuscule errors.

There is no reason to chop up your PHP code with multiple <?php ... ?> blocks, unless there is regular html or other plain text in between these blocks.

Your first !isset test condition was missing the (!)

Your mysql query was missing '$dogbreed',

I think that's all I found that looked wrong in this code...but I might have missed something too. ;-)

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

Hope this helps, and keep playing and practicing ...
Last edited by langsor; Aug 12th, 2008 at 2:06 am.
Reputation Points: 30
Solved Threads: 36
Posting Whiz
langsor is offline Offline
389 posts
since Aug 2008
Aug 12th, 2008
0

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

I used your code langsor (thank you so much <3) but this error came up:

Parse error: parse error, unexpected '{' in C:\Program Files\EasyPHP 2.0b1\www\dogstore.php on line 49
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 is line 49?
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

} else {

That little block there, I believe.
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

Try eliminating the opening parentheses in "if ( ( !isset( $_POST['dogname'] ) )". And check to make sure you've got all your braces in there correctly.
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

Eliminating the parentheses got me a parse error saying unexpected '!', expected '(' so I put it back in, and now it gave me:

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

But I dunno what a boolean is. ._.; Gosh this code is messed up, I'll have to have a word with my friend. xD
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

OK, try this:
php Syntax (Toggle Plain Text)
  1. if (!isset($_POST['dogname']) || ($_POST['dogname'] == '' ) )
  2. {
  3. die( "Oops! You forgot to fill in the name!" );
  4. }

Works for me. I think there was an extra parentheses stuck there in the middle.

By the way, a Boolean is basically a true/false value. PHP uses that for its comparisons.
Last edited by Demiloy; Aug 12th, 2008 at 2:41 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

Sorry to introduce an error here ...

In this line
PHP Syntax (Toggle Plain Text)
  1. if ( ( !isset( $_POST['Buy Dog'] ) ) {
remove one of the leading brackets ( like this
PHP Syntax (Toggle Plain Text)
  1. if ( !isset( $_POST['Buy Dog'] ) ) {
No more error :-)
Reputation Points: 30
Solved Threads: 36
Posting Whiz
langsor is offline Offline
389 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