Log in

View Full Version : [HELP] PHP Code



Kazco
26-10-2007, 08:33 PM
Hey HxF users!

I have this code, and it seems to be giving me an error.

Here's the full code (it isn't mine, its off techtuts).


<?php
$base_host = "localhost"; # your sql host (usualy 'localhost')
$base_name = "your_database_name"; # your database name
$base_user = "your_database_user"; # your database username
$base_pass = "your_database_password"; # your database password
$base_table= "banners"; # the table your going to use?

# Connect to the database
$db = mysql_connect($base_host,$base_user,$base_pass); # connect to the database
mysql_select_db ($base_name) or die ("Cannot connect to database"); # or die (if theres a problem it will echo, cannot connect to the database.

$query = mysql_query("select * from ".$base_table.""); # SQL query
$total = mysql_num_rows($query); # count up all the rows in the table
$query = mysql_query("select * from ".$base_table.""); # SQL query
$total = mysql_num_rows($query); # count up all the rows in the table
$random = (rand()%$total); # Create a random number
$query = mysql_query("SELECT * FROM ".$db_table." LIMIT $random, 1"); # Retrieve the random banner from the database.
{ # echo the query
echo"<a href="$row->addr" target="_blank" title="$row->text"><img src="$row->ban_image" alt="$row->text" width="468" height="60"></a>";
$view = $row->views + 1; # update the times viewed
mysql_query("update ".$base_table." set views = $view where id = $row->"id"); # another query
} # close while()
?>I'm getting the error on this line:


echo"<a href="$row->addr" target="_blank" title="$row->text"><img src="$row->ban_image" alt="$row->text" width="468" height="60"></a>";Any help would be appreciated, thanks.

DeejayMachoo$
26-10-2007, 08:48 PM
echo"<a href=\"$row->addr\" target=\"_blank\" title=\"$row->text\"><img src=\"$row->ban_image\" alt="\$row->text\" width=\"468\" height=\"60\"></a>";

Kazco
26-10-2007, 08:50 PM
echo"<a href=\"$row->addr\" target=\"_blank\" title=\"$row->text\"><img src=\"$row->ban_image\" alt="\$row->text\" width=\"468\" height=\"60\"></a>";


Nope, still errors.

Any other ideas?

This is the error code I get:

Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /home/habtownn/public_html/Banner/bannner.php on line 19

Tomm
27-10-2007, 10:29 AM
echo"<a href=\"$row->addr\" target=\"_blank\" title=\"$row->text\"><img src=\"$row->ban_image\" alt=\"$row->text\" width=\"468\" height=\"60\"></a>";

Kazco
27-10-2007, 02:16 PM
echo"<a href=\"$row->addr\" target=\"_blank\" title=\"$row->text\"><img src=\"$row->ban_image\" alt=\"$row->text\" width=\"468\" height=\"60\"></a>";


Thanks..

However now I'm getting this line error'd.


mysql_query("update ".$base_table." set views = $view where id = $row->"id"); # another query

Beau
29-10-2007, 07:52 AM
Urgh, can I suggest you use upper case for SQL functions? eg. SELECT, ALTER, UPDATE. Makes reading code a lot easier.



mysql_query("UPDATE $base_table SET views='$view' WHERE id='{$row->"id"}'"); # another query
Should work.

Want to hide these adverts? Register an account for free!