View Full Version : PHP Error


Julie
11-10-2004, 02:33 AM
Hey, I was trying out a PHP script, but I couldn't get it to work. Any ideas? The error meassage was "Parse error: parse error, unexpected $ in /home/jetblack/public_html/another/bases/test.php on line 45"

<?php

include 'db.inc';
if (!($connection = @ mysql_pconnect($hostName,
$username,
$password)))
showerror();

if (!mysql_select_db("jetblack_pets", $connection))
showerror();

if (!($result = @ mysql_query ($query, $connection)))
showerror();


$query = mysql_query("SELECT * FROM 'ImageTB' WHERE 'id' = 100");
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
{
?>
<?php
if ($row = @ mysql_fetch_array($result))
{
?>
<?php
do
{
?>
<tr>

<td><?php echo "<img src=\"img.php?file={$row["id"]}\">";?></td>
</tr>
</table>
<?php
} while ($row = @ mysql_fetch_array($result));
?>
<?php
} // if mysql_fetch_array()
else
echo "<h3>There are no images to display</h3>\n";
?>

db.inc has the username and password info. Img.php displays an image.

Thanks in advance for your help

Z inc.
11-10-2004, 07:23 PM
Could you give me a copy of the file? It'll be easier to check it in that way. Use my AIM address Fanstoptk in order to send... Is that that entire file, btw? The line in out of range...

Julie
11-10-2004, 07:48 PM
Sorry, I don't have AIM. ~.~ Or do you mean that address plus @aol.com? Also I think it included the db.inc in that, but I'm not sure...

Z inc.
11-10-2004, 07:53 PM
Ah. Give me a little time to configure an upload script, then you can use that to provide the file.

Z inc.
11-10-2004, 08:01 PM
Done. http://melicbot.com/fanstop/upload/index.php

Julie
11-10-2004, 08:03 PM
Ok! *goes to upload* do you want all 3 pages?

Z inc.
11-10-2004, 08:08 PM
Yes, if you would.

Julie
11-10-2004, 08:11 PM
I changed the username and password, but otherwise they should work.

Z inc.
11-10-2004, 08:14 PM
I changed the username and password, but otherwise they should work.
That's odd... Test.php is
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>

Whereas in the initial post, it was this
<?php

include 'db.inc';
if (!($connection = @ mysql_pconnect($hostName,
$username,
$password)))
showerror();

if (!mysql_select_db("jetblack_pets", $connection))
showerror();

if (!($result = @ mysql_query ($query, $connection)))
showerror();


$query = mysql_query("SELECT * FROM 'ImageTB' WHERE 'id' = 100");
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
{
?>
<?php
if ($row = @ mysql_fetch_array($result ))
{
?>
<?php
do
{
?>
<tr>

<td><?php echo "<img src=\"img.php?file={$row["id"]}\">";?></td>
</tr>
</table>
<?php
} while ($row = @ mysql_fetch_array($result ));
?>
<?php
} // if mysql_fetch_array()
else
echo "<h3>There are no images to display</h3>\n";
?>


Did you upload the wrong file?

Julie
11-10-2004, 08:15 PM
Ack! Sorry, I have a test.php in two different folders. ^^;

Z inc.
11-10-2004, 08:17 PM
Heh. I'll delete the existing one, and allow you to upload the next one... You can now upload.

Z inc.
11-10-2004, 08:31 PM
Okay, I think I figured out the problem... PHP was counting lines including your INC file... I went to line 40 accoringly, and I found a bracket below your "$result = mysql_query($query) or die('Query failed: ' . mysql_error());"... Simply remove that bracket, and It'll function.


Shiny new code:
<?php

include 'db.inc';
if (!($connection = @ mysql_pconnect($hostName,
$username,
$password)))
showerror();

if (!mysql_select_db("jetblack_pets", $connection))
showerror();

if (!($result = @ mysql_query ($query, $connection)))
showerror();


$query = mysql_query("SELECT * FROM 'ImageTB' WHERE 'id' = 100");
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
?>
<?php
if ($row = @ mysql_fetch_array($result ))
{
?>
<?php
do
{
?>
<tr>

<td><?php echo "<img src=\"img.php?file={$row["id"]}\">";?></td>
</tr>
</table>
<?php
} while ($row = @ mysql_fetch_array($result ));
?>
<?php
} // if mysql_fetch_array()
else
echo "<h3>There are no images to display</h3>\n";
?>

Julie
11-10-2004, 08:36 PM
Done

Edit: I mean uploading *didn't see the post*

Julie
11-10-2004, 08:40 PM
Now it says "Error 1065 : Query was empty" but I have files in the database

Z inc.
11-10-2004, 08:40 PM
Done

Edit: I mean uploading *didn't see the post*
Okay.. I'll take another look.

Julie
11-10-2004, 08:43 PM
Thank you very much.

Z inc.
11-10-2004, 08:48 PM
I've looked into it, and have made a conclusion


include 'db.inc';
if (!($connection = @ mysql_pconnect($hostName,
$username,
$password)))
showerror();

if (!mysql_select_db("jetblack_pets", $connection))
showerror();

if (!($result = @ mysql_query ($query, $connection))) //This line calls a non-existant variable. ($query)
showerror();


There's no query defined... You need to put a query into the script to have it read.

Julie
11-10-2004, 09:30 PM
Ok, I tried this, but I still got an error "Query failed: Query was empty", but I think I defined it this time...
<?php

include 'db.inc';
if (!($connection = @ mysql_pconnect($hostName,
$username,
$password)))
showerror();

$query = mysql_query("SELECT * FROM 'ImageTB' WHERE 'id' = 100");
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
if (!mysql_select_db("jetblack_pets", $connection))
showerror();
if (!($result = @ mysql_query ($query, $connection)))
showerror();
?>
<?php
if ($row = @ mysql_fetch_array($result ))
{
?>
<?php
do
{
?>
<tr>

<td><?php echo "<img src=\"img.php?file={$row["id"]}\">";?></td>
</tr>
</table>
<?php
} while ($row = @ mysql_fetch_array($result ));
?>
<?php
} // if mysql_fetch_array()
else
echo "<h3>There are no images to display</h3>\n";
?>

Z inc.
11-12-2004, 04:28 PM
Heh. You need to define the variable $query as a string, not as a mysql_query().

$query = mysql_query("SELECT * FROM 'ImageTB' WHERE 'id' = 100");
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
Needs to be
$query = "SELECT * FROM 'ImageTB' WHERE 'id' = 100";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
That'll fix it.

Julie
11-13-2004, 01:58 PM
Thank you so much, it's working now! *hugs*

Z inc.
11-14-2004, 09:01 PM
You're quite welcome. If you need any help in the future, feel free to contact me.