| | |
Parse error: parse error, unexpected T_STRING on line 40
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2008
Posts: 10
Reputation:
Solved Threads: 0
php Syntax (Toggle Plain Text)
<?php include ('connect.php'); ?> <form name="form1" method="post" action="dogstore.php"> Dog's Name: <input name="dogname" type="text"> <br> Dog's Breed: <select name="dogbreed"> <option value="breed1">Breed</option> <option value="breed2">Breed</option> <option value="breed3">Breed</option> <option value="breed4">Breed</option> <option value="breed5">Breed</option> <option value="breed6">Breed</option> <option value="breed7">Breed</option> </select> <br> Dog's Gender: <select name="doggender"> <option value="Male">Male</option> <option value="Female">Female</option> </select> <br> <input type="submit" name="Submit" value="Buy Dog"> </form> <?php //trim removes the white spaces from the beginning and end of the text $dogname = trim($_POST['dogname']); $dogbreed = trim($_POST['dogbreed']); $doggender = trim($_POST['doggender']); ?> <?php //Make sure the name form is filled out. if (isset($_POST['dogname'])) || ($_POST['dogname'] == "")) [die("Oops! You forgot to fill in the name!")]; ?> <?php $ownerid = $_SESSION['id']; ?> <?php if ((!isset($_POST['Buy Dog'])) { echo "Congratulations! You've purchased a dog."; } else { echo "Congratulations! You've purchased a dog.";} } ?> <?php $dog = @mysql_query("INSERT INTO dogs (ownerid, dogname, dogbreed, doggender) VALUES ('$ownerid', '$dogname', '$doggender')") or die("Error: ".mysql_error()); ?>
•
•
Join Date: Aug 2008
Posts: 381
Reputation:
Solved Threads: 33
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. ;-)
Hope this helps, and keep playing and practicing ...
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)
<?php include ('connect.php'); ?> <html> <head> </head> <body> <form name="form1" method="post" action="dogstore.php"> Dog's Name: <input name="dogname" type="text"> <br> Dog's Breed: <select name="dogbreed"> <option value="breed1">Breed</option> <option value="breed2">Breed</option> <option value="breed3">Breed</option> <option value="breed4">Breed</option> <option value="breed5">Breed</option> <option value="breed6">Breed</option> <option value="breed7">Breed</option> </select> <br> Dog's Gender: <select name="doggender"> <option value="Male">Male</option> <option value="Female">Female</option> </select> <br> <input type="submit" name="Submit" value="Buy Dog"> </form> </body> </html> <?php //trim removes the white spaces from the beginning and end of the text $dogname = trim( $_POST['dogname'] ); $dogbreed = trim( $_POST['dogbreed'] ); $doggender = trim( $_POST['doggender'] ); //Make sure the name form is filled out. if ( ( !isset( $_POST['dogname'] ) ) || ( $_POST['dogname'] == '' ) ) { // ! die( "Oops! You forgot to fill in the name!" ); } $ownerid = $_SESSION['id']; // ; if ( ( !isset( $_POST['Buy Dog'] ) ) { echo "Congratulations! You've purchased a dog."; // not really ... } else { echo "Congratulations! You've purchased a dog."; } $dog = @mysql_query( "INSERT INTO dogs (ownerid, dogname, dogbreed, doggender) VALUES ('$ownerid', '$dogname', '$dogbreed', '$doggender')" ) or die( "Error:".mysql_error() ); //'$dogbreed', ?>
Hope this helps, and keep playing and practicing ...
Last edited by langsor; Aug 12th, 2008 at 2:06 am.
•
•
Join Date: Aug 2008
Posts: 10
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Aug 2008
Posts: 48
Reputation:
Solved Threads: 4
OK, try this:
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.
php Syntax (Toggle Plain Text)
if (!isset($_POST['dogname']) || ($_POST['dogname'] == '' ) ) { die( "Oops! You forgot to fill in the name!" ); }
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.
•
•
Join Date: Aug 2008
Posts: 381
Reputation:
Solved Threads: 33
Sorry to introduce an error here ...
In this line
remove one of the leading brackets ( like this
No more error :-)
In this line
PHP Syntax (Toggle Plain Text)
if ( ( !isset( $_POST['Buy Dog'] ) ) {
PHP Syntax (Toggle Plain Text)
if ( !isset( $_POST['Buy Dog'] ) ) {
![]() |
Similar Threads
- Parse error: syntax error, unexpected T_STRING (PHP)
- parse error, unexpected T_STRING in (PHP)
- Parse error: parse error, unexpected T_STRING on line 12 (PHP)
- Please Help! parse error, unexpected T_STRING (PHP)
- Parse error: parse error, unexpected T_STRING (PHP)
- PHP Parse error: parse error, unexpected T_STRING (PHP)
- Parse error: parse error, unexpected T_STRING in /home/thei2k9/public_html/includes/f (PHP)
- Need Help With Parse Error... (PHP)
Other Threads in the PHP Forum
- Previous Thread: $_POST value with <a> link click
- Next Thread: Trying to commad a script based on timing! But it doesnt work. Please help?
| Thread Tools | Search this Thread |
ajax apache api array beginner beneath binary broadband broken button cakephp checkbox class cms code countingeverycharactersfromastring crack cron curl database date decode display dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip javascript joomla limit link links login mail match md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf php problem protocol query radio random recursion regex remote script search searchbox server session sessions sms smtp soap source space sql strip_tags survey syntax system table tutorial undefined update upload url validator variable video virus votedown web window.onbeforeunload=closeme; xml youtube





