Forum Moderators: coopster

Message Too Old, No Replies

New to PHP not working properly

using url query lines to access database

         

itechdesigns

9:30 pm on Feb 10, 2006 (gmt 0)

10+ Year Member



I am trying to display a list a website layouts including thumbnails and id #s. I am storing the location of the thumbnail images and download locations in a database.

Here is the code I am using:
<html>
<body>
<?
$username="";
$password="";
$database="";
$var_array = explode("/",$PATH_INFO);
$page_num = $var_array;

mysql_connect("db1.awardspace.com",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM catalog ;
$result=mysql_query($query);

$id=mysql_result($result,$page_num,"id");
$thumb=mysql_result($result,$page_num,"thumb");
$image=mysql_result($result,$page_num,"image");
$download=mysql_result($result,$page_num,"download");

echo "<table><tr><td><image src=$thumb><br>ID: $id<br>Download:<a href=$download>Download</a></td> $page_num++;
<td><image src=$thumb><br>ID: $id<br>Download:<a href=$download>Download</a></td></tr></table>";
mysql_close();
?>
</body>
</html>

The error that keeps being returned is:

Parse error: parse error, unexpected T_STRING in /home/www/example.com/catalog.php on line 15

Now of course I have filled in the correct username and password and database information. That is not the problem. If anyone can help, please do so.

[1][edited by: jatar_k at 10:29 pm (utc) on Feb. 10, 2006]
[edit reason] examplified [/edit]

Dijkgraaf

9:35 pm on Feb 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, you are missing the closing quotes on
$query="SELECT * FROM catalog ;
it should be
$query="SELECT * FROM catalog";

itechdesigns

9:46 pm on Feb 10, 2006 (gmt 0)

10+ Year Member



wow thank you. I have a new problem though.
Here is a look at my database:

ID Thumb Download etc.
1 [......] [......]
2 [......] [......]

Now the id # is stored in the variable $page_num which is determined by the url query string. The problem is that I need to add 1 to it everytime it is executed. That is what this string was for:
$page_num++;

Except when the screen appears, I get ++; as plain text and so therefore the ID never changes and I could never have it display a different image other than the one associated with ID1.

Dijkgraaf

9:55 pm on Feb 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Increment $page_num before you do the echo.
eg.
$page_num++;
echo "<table><tr><td><image src=$thumb><br>ID: $id<br>Download:<a href=$download>Download</a></td> $page_num
<td><image src=$thumb><br>ID: $id<br>Download:<a href=$download>Download</a></td></tr></table>";

I'm not even sure if ++ is valid in PHP, if it isn't use
$page_num=$page_num+1;
echo "<table><tr><td><image src=$thumb><br>ID: $id<br>Download:<a href=$download>Download</a></td> $page_num
<td><image src=$thumb><br>ID: $id<br>Download:<a href=$download>Download</a></td></tr></table>";

<edit>
You may also want to break that echo into two lines to make it more readable.
</edit>

[edited by: Dijkgraaf at 10:08 pm (utc) on Feb. 10, 2006]

Dijkgraaf

10:02 pm on Feb 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also, see this thread [webmasterworld.com] how to loop through multiple rows.

itechdesigns

10:09 pm on Feb 10, 2006 (gmt 0)

10+ Year Member



Okay, well now the issue is that I put the following in:

echo "<table><tr><td><image src=$thumb><br>ID: $id<br>Download:<a href=$download>Download</a></td>";
$page_num=$page_num+1;
echo"<td><image src=$thumb><br>ID: $id<br>Download:<a href=$download>Download</a></td></tr></table>";

so it is supposed to display the first product then add 1 to the $page_num variable then when it adds the second one it is supposed to have all the details of the second product. But instead it repeats the first.

[edited by: itechdesigns at 10:14 pm (utc) on Feb. 10, 2006]

Dijkgraaf

10:13 pm on Feb 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try
$var_array = explode("/",$_SERVER['PATH_INFO']);
the way you had it is dependant on a server configuration setting that is better left off.

P.S. You may want to edit out your domain name, and replace it with www.example.com as posting your URL's is against the terms of service of this forum.
If you don't edit it out, one of the admins will :-)

itechdesigns

10:16 pm on Feb 10, 2006 (gmt 0)

10+ Year Member



note the editted topic above. I just solved the issue

Dijkgraaf

10:19 pm on Feb 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So is it working fully now, or do you still have an issue?
If you still have an issue please post the code as you have it now, and what your issue is.

itechdesigns

10:24 pm on Feb 10, 2006 (gmt 0)

10+ Year Member



"Okay, well now the issue is that I put the following in:

echo "<table><tr><td><image src=$thumb><br>ID: $id<br>Download:<a href=$download>Download</a></td>";
$page_num=$page_num+1;
echo"<td><image src=$thumb><br>ID: $id<br>Download:<a href=$download>Download</a></td></tr></table>";

so it is supposed to display the first product then add 1 to the $page_num variable then when it adds the second one it is supposed to have all the details of the second product. But instead it repeats the first. "

-Is that the question to which you answered:

"Try
$var_array = explode("/",$_SERVER['PATH_INFO']);
the way you had it is dependant on a server configuration setting that is better left off."

-If not could you please try this question out?

itechdesigns

10:25 pm on Feb 10, 2006 (gmt 0)

10+ Year Member



Nevermind, I solved the issue. Thanks for your help

jatar_k

10:30 pm on Feb 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



and Welcome to WebmasterWorld itechdesigns

itechdesigns

11:34 pm on Feb 10, 2006 (gmt 0)

10+ Year Member



Haha, wow this is getting realluy old. I have a new error:
Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/www/siteexample.com/catalog.php on line 21
Here is lines 21-23

echo"<table cellspacing=4><tr><td><image src=$thumb><br>ID: $id<br><a href=$download><image src="http://example.com/images/button(download).bmp" border=0 srcover="http://example.com/images/button(download)press.bmp"></a></td>";

If you see what the problem is then please help out.
Oh and by the way, the srcover refers to a javascript used earlier.

[edited by: jatar_k at 11:46 pm (utc) on Feb. 10, 2006]
[edit reason] examplified [/edit]

jatar_k

11:45 pm on Feb 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



mismatched double quotes

when you start your string to be echo'ed

echo "

this set of quotes will be closed at the next set of double quotes

echo"<table cellspacing=4><tr><td><image src=$thumb><br>ID: $id<br><a href=$download><image src="http://example.com/images/button(download).bmp" border=0 srcover="http://example.com/images/button(download)press.bmp"></a></td>";

you need to, either, use single quotes inside your double quoted string like so

echo"<table cellspacing=4><tr><td><image src=$thumb><br>ID: $id<br><a href=$download><image src='http://example.com/images/button(download).bmp' border=0 srcover='http://example.com/images/button(download)press.bmp'></a></td>";

that way you can just jam your variables inside your double quoted string and they will be resolved

or

you put single quotes around the outside. You can then use double quotes inside if needed but then the vars won't be resolved so you could do it this way

echo '<table cellspacing=4><tr><td><image src="',$thumb,'"><br>ID: ',$id,'<br><a href="',$download,'"><image src="http://example.com/images/button(download).bmp" border=0 srcover="http://example.com/images/button(download)press.bmp"></a></td>';

that's the way I do it. The echo function allows you to use commas between seperate values to be echo'ed. You can also use the period . called the concatenation operator, but I have found the comma is faster.

itechdesigns

11:58 pm on Feb 10, 2006 (gmt 0)

10+ Year Member



Is there a reason this image won't appear?
<image src="http://example.com/images/button(download).bmp" border=0 srcover="http://example.com/images/button(download)press.bmp">

I've already tried removing the srcover part.

jatar_k

12:04 am on Feb 11, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



are these really the image names?

button(download)press.bmp

and

button(download).bmp

itechdesigns

12:09 am on Feb 11, 2006 (gmt 0)

10+ Year Member



yes they are

jatar_k

12:19 am on Feb 11, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hmm, you might want to try changing that, I don't believe the ( and ) are allowed chars. Maybe swap them to a - and see if that makes the difference

itechdesigns

12:27 am on Feb 11, 2006 (gmt 0)

10+ Year Member



this has been solved...
but now, how do you link to a script in php?
this would normally go in the header of an html file
<script type="text/javascript" src="imagerollover.js">.
I have tried placing it in the header, but it didnt work. I have also tried exiting the php code long enough to try and use it but it wouldnt.

Example:
echo"<table cellspacing=4><tr><td><image src=$thumb><br>ID: $id<br><a href=$download>";
?>
<image src='http://www.examplesite.com/images/buttondown.bmp' border=0 srcover='http://www.examplesite.com/images/buttondownpress.bmp'>
<? echo"</a></td>";?>

The javascript code works in normal html files. The srcover points to part of the coding in imagerollover.js.

thanks again and again

jatar_k

1:27 am on Feb 11, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I am no javascript whizz but my first thoughts when things don't work correctly are

1. view source of the page and see if the output is correctly formatted
2. make sure the paths to all files and images are actually correct
3. for js make sure the source of the function call is correct as well