Webdetector Webmaster Forums - Your favorite webmaster community
 

Advertise Here Wordpress Premium Sportscrazyforum - Where Sport is a religion dnfame.com Spruce Host chooseapixel.com

Go Back   Webdetector Webmaster Forums - Your favorite webmaster community > Developers Corner > Programming > PHP Forum

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-26-2008, 11:54 AM
Member
noobee
 
Join Date: Jun 2008
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default How come I get an error using double quotes in PHP?

I am a newbie, and am readin MySQL and PHP For Dummies 3rd edition. All the programs have double quotes in them, but whenever I have a double quote in them, I get this error:

Parse error: syntax error, unexpected '>' in C:\****\test\mysql_send.php on line 6

Is there a setting that I need to change somewhere? Is it magic quotes?

For example, this code will give me the same error as above...

Code:
<?php
/*Program: mysql_send.php
*Desc: PHP program that sends an SQL query to the
* MySQL server and displays the results.
*/
echo ?<html><head><title>SQL Query Sender</title></head><body>?;
The error I recieve is
Parse error: syntax error, unexpected '>' in C:\****\test\mysql_send.php on line 6

Then, I remove the " in line 6, and replace it with a ', and I get this error, (I will put it in the edit section)
(Cont. Question)

Warning: Unexpected character in input: ''' (ASCII=39) state=1 in C:\****\test\mysql_send.php on line 6

Parse error: syntax error, unexpected '<' in C:\****\test\mysql_send.php on line 6

I remove the " on line 8 and replace it with a '...and its fixed. But I get a different error with the ECHO statement, the following is line 22, 23, and 24 of the same program:

echo ?Database Selected: <b>{$_POST[?database?]}</b><br>
Query: <b>{$_POST[?query?]}</b><h3>Results</h3><hr>?;

I get this error for that line:


Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\kyle\testing\mysql_send.php on line 22
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
  #2 (permalink)  
Old 06-26-2008, 07:21 PM
Member
noobee
 
Join Date: May 2008
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default How come I get an error using double quotes in PHP?

The error isn't from the double quotes, it's because your echo statement is broken up over several lines.

Try this...
echo "<html><head><title>SQL Query Sender</title></head><body>";

or you can do it this way...
echo "<html>";
echo "<head><title>SQL Query Sender</title></head>";
echo "<body>";

Also, make sure you are not using "curly" quotes. Some programs, like Microsoft Word, automatically convert straight quotes into curly quotes. That isn't good for programming languages.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-27-2008, 10:14 AM
Member
Marketeer
 
Join Date: May 2008
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default How come I get an error using double quotes in PHP?

What type of editor are you using? make sure it is not something like Wordpad that wants to put in curly quotes. That will not be good. If you don't have a code editor (like vim, or some PHP IDE) use Notepad to insure you are editing as text, not rich text.

The broken lines should be fine w/ echo. At least it is in the examples on the php.net documentation for echo
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-27-2008, 05:40 PM
directory_man's Avatar
Super Moderator
noobee
 
Join Date: Jun 2008
Posts: 34
Thanks: 2
Thanked 0 Times in 0 Posts
Default How come I get an error using double quotes in PHP?

You can't have a string that goes over more than one line.

Easiest way to do this is either:

<?php
/*Program: mysql_send.php
*Desc: PHP program that sends an SQL query to the
* MySQL server and displays the results.
*/
?><html><head><title>SQL Query Sender</title></head><body><?
// More php stuff here
?>


or...



<?php
/*Program: mysql_send.php
*Desc: PHP program that sends an SQL query to the
* MySQL server and displays the results.
*/
echo ?<html>";
echo ?<head><title>SQL Query Sender</title></head>";
echo ?<body>?;
?>

Either will work just fine


What text editor are you using? I'd suggest using either a proper programmers editor (I quite like Crimson Editor, personally) or stick to Notepad, not Wordpad.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-28-2008, 01:06 AM
Member
noobee
 
Join Date: May 2008
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default How come I get an error using double quotes in PHP?

The quotation marks I see are stylized, and not the character PHP expects. You need to use the " character (which, on at least my Finnish keyboard comes from Shift + 2).

This might be the editor you're using interfering. I recommend Notepad++ or any other editor designed for programming.

And you can have linebreaks in your echo statements (and other stuff such as declaring variables) with strings, unlike what some people may claim.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +1. The time now is 03:10 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Ad Management by RedTyger