Closed Thread Icon

Topic awaiting preservation: MySQL/PHP Troubles - unexpected '?' Pages that link to <a href="https://ozoneasylum.com/backlink?for=23629" title="Pages that link to Topic awaiting preservation: MySQL/PHP Troubles -  unexpected &amp;#039;?&amp;#039;" rel="nofollow" >Topic awaiting preservation: MySQL/PHP Troubles -  unexpected &#039;?&#039;\

 
Author Thread
Jimmy
Nervous Wreck (II) Inmate

From: Alderaan
Insane since: Sep 2004

posted posted 10-12-2004 03:44

I decided to attempt and learn how to use MySQL w/ PHP. In searching this forum I found Zend and their tutorial dealing with PHP & MySQL. I pretty much copied and pasted to code from the tutorial into Dreamweaver, saved the file, and uploaded it. Obviously I replaced their user information with my own. The code is below. For obvious reasons I changed my login information.

code:
<?php 

// set database server access variables:
$host = "mysql.mydomain.com";
$user = "username";
$pass = "pwd";
$db = "database";

// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

// create query
$query = "SELECT * FROM symbols";

// execute query
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

// see if any rows were returned
if (mysql_num_rows($result) > 0) {
    // yes
    // print them one after another
    echo "<table cellpadding=10 border=1>";
    while($row = mysql_fetch_row($result)) {
        echo "<tr>";
        echo "<td>" . $row[0] . "</td>";
        echo "<td>" . $row[1] . "</td>";
        echo "<td>" . $row[2] . "</td>";
        echo "</tr>";
    }
    echo "</table>";
}
else {
    // no
    // print status message
    echo "No rows found!";
}

// free result set memory
mysql_free_result($result);

// close connection
mysql_close($connection);

?>



When I run the php file the error message that is displayed is:

code:
Parse error: parse error, unexpected '?' in /home/.waikiki/seib3184/polkadotboxers.com/php/dbexample.php on line 32



Line 32 according to Dreamweaver is:

code:
 
32: // yes
    33: // print them one after another
    34: echo "<table cellpadding=10 border=1>";
    35: while($row = mysql_fetch_row($result)) {
    36: echo "<tr>";
    37: echo "<td>" . $row[0] . "</td>";
    38: echo "<td>" . $row[1] . "</td>";
    39: echo "<td>" . $row[2] . "</td>";
    40: echo "</tr>";



I don't like to ask vague questions but in this case I honestly don't know what the question is. I suppose everyone has to start some place though. If anyone could look at that code and tell me where my problem lies, I would appreciate it greatly.

Jim

Jimmy
Nervous Wreck (II) Inmate

From: Alderaan
Insane since: Sep 2004

posted posted 10-12-2004 03:45

BTW, I used myPHP Admin to create the table.

Jim

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 10-12-2004 09:42

the code you have above is ok.

Are you sure it was uploaded correctly?

Jimmy
Nervous Wreck (II) Inmate

From: Alderaan
Insane since: Sep 2004

posted posted 10-12-2004 15:54

What do you mean uploaded correctly, TP? I use CuteFTP for mac for my FTP and I uploaded it like I would any PHP file. I double checked with Dreamhost to ensure that my login information was correct, and it was.

BTW, I really appreciate all the help I've gotten here. I've created just two topics and I've already learned a whole lot. I hope to continue the learning.

Jim

(Edited by Jimmy on 10-12-2004 15:55)

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 10-12-2004 18:10

Yeah I can't find an error either. Give this a try on the first line put

error_reporting(E_ALL);

This is a good first line for all scripts you work on it should give more debug info.



.:[ Never resist a perfect moment ]:.

norm
Paranoid (IV) Inmate

From: [s]underwater[/s] under-snow in Juneau
Insane since: Sep 2002

posted posted 10-12-2004 18:32

Sometimes if you copy & paste from a webpage you pick up hidden characters that do not show up in most editors. These hidden characters can really mess things up.

You said you are on a Mac, so here is what I would suggest... grab a copy of BBedit (best program ever written...) and click on Text/Zap Gremlins. This will remove those troublesome hidden characters.

If you don't want to use BBedit, try re-typing all of the code by hand.

/* Sure, go ahead and code in your fancy IDE. Just remember: it's all fun and games until someone puts an $i out */

Jimmy
Nervous Wreck (II) Inmate

From: Alderaan
Insane since: Sep 2004

posted posted 10-12-2004 19:27

Thanks for the help Norm & Bit. I tried what you guys side but it didn't change anything. Even with the error_reporting(E_ALL); included and retyping the code I'm still getting an error message in the same line.

Edit: the line that was having the problem was the comment Yes. So I took it out. I'm told the error is on the same line though, where theres nothing there.

New developments: Since all the errors I was receiving pointed to a comment, I took out all of my comments. I then received an error Parse error: parse error, unexpected '?' on line 28 which was an echo statement. While learning PHP I always used print statements instead of echo so I changed it and there was no change. Is there a problem with:

code:
print ("<table cellpadding=10 border=1>");



Any other ideas?

Current code:

code:
<?php 
error_reporting(E_ALL);

$host = "mysql.polkadotboxers.com";
$user = "XXXXXXX";
$pass = "XXXXXXX";
$db = "polkadot";

$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

mysql_select_db($db) or die ("Unable to select database!");

$query = "SELECT * FROM symbols";

$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

if (mysql_num_rows($result) > 0)
{
    
    print ("<table cellpadding=10 border=1>");
    while($row = mysql_fetch_row($result))
{
        echo "<tr>";
        echo "<td>" . $row[0] . "</td>";
        echo "<td>" . $row[1] . "</td>";
        echo "<td>" . $row[2] . "</td>";
        echo "</tr>";
    }
    echo "</table>";
}
else
{
    echo "No rows found!";
}

mysql_free_result($result);

mysql_close($connection);
?>



Jim

stripped out the user and pass -bit

(Edited by bitdamaged on 10-12-2004 20:31)

Hebedee
Paranoid (IV) Inmate

From: Maryland, USA
Insane since: Jan 2001

posted posted 10-13-2004 00:22

What kind of data should be in the result set?

Jimmy
Nervous Wreck (II) Inmate

From: Alderaan
Insane since: Sep 2004

posted posted 10-13-2004 01:34

Thanks bit! I copied and pasted without even checking it.

Hebedee - It's supposed to print out a table with 6 rows and 3 columns. The first column is just numbers (1-6), the second country names, and the third is animals. It's not that I'm getting an incorrect output. I'm getting a PHP error that I just can't figure out.

Quick thought - Would permission matter in this case? I've read a little bit about CHMODing. It doesn't seem like something that needs special permission but as near as I can tell the PHP/MySQL is correct.

Jim

(Edited by Jimmy on 10-13-2004 01:40)

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 10-13-2004 04:01

Nope if the permissions were wrong you wouldn't get any output you'd end up with a 403 error.

Try this, start commenting out code around line 32. This is the basics of any trouble shooting. You can actually either do this at line 32 or just start from the top putting a closing comment at the end of everything ( */ ) and then start dropping the opening comment down from the top line. You still have to have full statements though so be careful not to break anything else.


Note in PHP frequently errors will be above the listed line number. For example missing a semi-colon on line 31 will actually error on line 32 (The line doesn't "break" until it runs into another statement). Similar problems with missing brackets.

This really seems like some sort of encoding error though.



.:[ Never resist a perfect moment ]:.

Jimmy
Nervous Wreck (II) Inmate

From: Alderaan
Insane since: Sep 2004

posted posted 10-13-2004 04:16

I'll try the comment suggestion but can you expand on encoding error? I don't know what that means.

Jim

Jimmy
Nervous Wreck (II) Inmate

From: Alderaan
Insane since: Sep 2004

posted posted 10-13-2004 04:38

What the hell?

Well it worked. All I did was follow bit's advice and started commenting things. But oddly enough, I didn't change ANYTHING. I commented out everything except the actually connection to the database. Obviously I was given error messages since it referenced unused variables, so I used the @ to supress the messages. Then I started uncommenting things until nothing was left ... and it worked.

Well You can see my first (or should I say Zend's) PHP/MySQL script here. I'm happy.

Thanks to everyone for all the help. I hope no one minds if I have more questions in the future, I'm sure I will.

Jim

« BackwardsOnwards »

Show Forum Drop Down Menu