Page 1 of 2

[SOLVED]Parse error: parse error, unexpected '?' in c:\.....

Posted: Fri Nov 07, 2003 2:10 pm
by Jascn
Hello,

Im working through a tutorial and am having difficulty with this lesson. I have double checked the code it has me write and I can not seem to locate where my mistake is.

Im getting this error:
Parse error: parse error, unexpected '?' in c:\program files\apache group\apache\htdocs\create_db.php on line 11

http://localhost/create_db.php

Code: Select all

<?php
$conn = @mysql_connect("localhost","root","password")
or die("Sorry - unable to connect to MySQL');
$rs1=	@mysql_create_db( $db );
$rs2=	@mysql_list_dbs($conn);
for($row=0; $row < mysql_num_rows($rs2); $row++)
&#123; $list .= mysql_tablename($rs2,$row)." | "; &#125;
?>
<html><head><title> Create New Database</title></head>
<body>
<form action="<?php echo($PHP_SELF); ?>" method="post">
Current databases: <?php echo($list); ?> <hr>
Name:<input type="text" name="db">
<input type="submit" values="create database">
</form></body></html>
I have register_globals ON, but that didnt reslove my problem.

Could you please assist me?

Posted: Fri Nov 07, 2003 2:24 pm
by Weirdan
echo is a keyword, not a function. use it as follows:

Code: Select all

echo "something\n";

Posted: Fri Nov 07, 2003 2:31 pm
by Jascn
weird.... that code i have in the first post is copied character for character from my tutorial book.

anyhow, Ive attempted your suggestion and still am recieving the same parse error.

Code: Select all

<?php
$conn = @mysql_connect("localhost","root","5suhide7")
or die("Sorry - unable to connect to MySQL');
$rs1=	@mysql_create_db( $db );
$rs2=	@mysql_list_dbs($conn);
for($row=0; $row < mysql_num_rows($rs2); $row++)
&#123; $list .= mysql_tablename($rs2,$row)." | "; &#125;
?>
<html><head><title> Create New Database</title></head>
<body>
<form action="<?php echo "$PHP_SELF\n"; ?>" method="post">
Current databases: <?php echo"$list"; ?> <hr>
Name:<input type="text" name="db">
<input type="submit" values="create database">
</form></body></html>

Posted: Fri Nov 07, 2003 2:34 pm
by d3ad1ysp0rk

Code: Select all

<form action="<?php echo $PHP_SELF; ?>" method="post">
try that.

Posted: Fri Nov 07, 2003 2:47 pm
by Jascn
Same error....

Code: Select all

<?php
$conn = @mysql_connect("localhost","root","5suhide7")
or die("Sorry - unable to connect to MySQL');
$rs1=	@mysql_create_db( $db );
$rs2=	@mysql_list_dbs($conn);
for($row=0; $row < mysql_num_rows($rs2); $row++)
&#123; $list .= mysql_tablename($rs2,$row)." | "; &#125;
?>
<html><head><title> Create New Database</title></head>
<body>
<form action="<?php echo $PHP_SELF; ?>" method="post">
Current databases: <?php echo $list; ?> <hr>
Name:<input type="text" name="db">
<input type="submit" values="create database">
</form></body></html>
Any other suggestions?

Posted: Fri Nov 07, 2003 2:51 pm
by d3ad1ysp0rk

Code: Select all

$conn = @mysql_connect("localhost","root","password")
or die("Sorry - unable to connect to MySQL");
$rs1=   @mysql_create_db( $db );
$rs2=   @mysql_list_dbs($conn);
for($row=0; $row < mysql_num_rows($rs2); $row++)
{
   $list .= mysql_tablename($rs2,$row)." | ";
}
?>
<html><head><title> Create New Database</title></head>
<body>
<form action="<?php echo($PHP_SELF); ?>" method="post">
Current databases: <?php echo($list); ?> <hr>
Name:<input type="text" name="db">
<input type="submit" values="create database">
</form></body></html>

RE:

Posted: Fri Nov 07, 2003 3:03 pm
by Jascn
Well we are on to something here...

Posted: Fri Nov 07, 2003 3:28 pm
by Jascn
LiLpunkSkateR wrote:

Code: Select all

$conn = @mysql_connect("localhost","root","password")
or die("Sorry - unable to connect to MySQL");
$rs1=   @mysql_create_db( $db );
$rs2=   @mysql_list_dbs($conn);
for($row=0; $row < mysql_num_rows($rs2); $row++)
{
   $list .= mysql_tablename($rs2,$row)." | ";
}
?>
<html><head><title> Create New Database</title></head>
<body>
<form action="<?php echo($PHP_SELF); ?>" method="post">
Current databases: <?php echo($list); ?> <hr>
Name:<input type="text" name="db">
<input type="submit" values="create database">
</form></body></html>
What is different here, than in my original post???
This made it start working. Id like to learn from my mistake.
Thanks for the help too!

Note: I found the need to add <?php to the begginning , probably just a copy/paste error you made.

Here is my error free code now:

Code: Select all

&lt;?php 
$list = " ";
$conn = @mysql_connect("localhost","root","5suhide7") 
or die("Sorry - unable to connect to MySQL"); 
$rs1=   @mysql_create_db( $db ); 
$rs2=   @mysql_list_dbs($conn); 
for($row=0; $row &lt; mysql_num_rows($rs2); $row++) 
&#123; $list .= mysql_tablename($rs2,$row)." | "; &#125; 
?&gt; 
&lt;html&gt;&lt;head&gt;&lt;title&gt; Create New Database&lt;/title&gt;&lt;/head&gt; 
&lt;body&gt; 
&lt;form action="&lt;?php echo($PHP_SELF); ?&gt;" method="post"&gt; 
Current databases: &lt;?php echo($list); ?&gt; &lt;hr&gt; 
Name:&lt;input type="text" name="db"&gt; 
&lt;input type="submit" values="create database"&gt; 
&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;

Posted: Fri Nov 07, 2003 3:37 pm
by d3ad1ysp0rk
Opened it in winSyntax

Syntax highlighting stopped and turned green after this line:

Code: Select all

or die("Sorry - unable to connect to MySQL');
so i changed it to this:

Code: Select all

or die("Sorry - unable to connect to MySQL");
you just tried to end your quotes with an apostraphy (sp?)

Posted: Fri Nov 07, 2003 3:48 pm
by Jascn
THANK YOU

I see the light.
/slaps self with large trout[/b]

Last question....
What program you editing in? (im using notepad)

Posted: Fri Nov 07, 2003 3:50 pm
by d3ad1ysp0rk
Opened it in winSyntax
;)

Posted: Fri Nov 07, 2003 3:53 pm
by Jascn
thanks again.

[/being stupid]

Posted: Fri Nov 07, 2003 3:58 pm
by qads
checkout viewtopic.php?t=6288 if your looking for a editor :).

Posted: Fri Nov 07, 2003 5:08 pm
by d3ad1ysp0rk
Dreamweaver 18% (31 votes)
and you wonder why i'm not going to rely on that thread to help me get a good php editor.. :P

Posted: Fri Nov 07, 2003 5:33 pm
by qads
what is wrong with dreamwaver? 8O, it might not be the greatest but when it comes to php and design at the same time, it is better then most of WYSIWYG editors...


frontpage any one? :lol: