Forum Moderators: coopster

Message Too Old, No Replies

How come this isn't working

It's just giving me a blank page now..

         

undream2

2:28 am on Mar 8, 2008 (gmt 0)

10+ Year Member



Hi,

I just fixed an error. I had to put in a period behind an array. Now, it is just giving me a blank page.

How, come this isn't working. I am not advanced in mysql coding..

mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);

$query = 'SELECT * FROM $usertable';
$result = mysql_query($query);
if($result) {
while($row = mysql_fetch_array($result)){
$imagelink = $row["imagelink"];
$deallink = $row["deallink"];
$linktitle = $row["linktitle"];
$dealdescription = $row["dealdescription"];
$expires = $row["expires"];
$couponcode = $row["couponcode"];

echo "<tr>\n";
echo "<td width=150 valign=top>\n";
echo "<img src=".$imagelink.">";
echo "</td>\n";
echo "<td>\n";
echo "<font face=verdana size=4><a href=".$deallink.">".$linktitle."</a></font><br>\n";
echo "<font face=arial size=3>".$dealdescription."</font><br>\n";
echo "<font face=verdana size=3><b><u>Expires</u>: </b>".$expires."</font> &nbsp;&nbsp;&nbsp;&nbsp;";
echo "<font face=verdana size=3><b><u>Coupon Code</u>: </b></font>";
echo "<font face=verdana size=3>".$couponcode."</b></font><br><br>";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";


}
}
?>

jatar_k

2:37 am on Mar 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



is $usertable defined before your query?

undream2

2:44 am on Mar 8, 2008 (gmt 0)

10+ Year Member



yes, it the database connection is fine...

jatar_k

2:47 am on Mar 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I mean the variable in the query

$query = 'SELECT * FROM $usertable';

and now that I look at that again, if it is a variable it won't get resolved inside single quotes so try this way

$query = "SELECT * FROM $usertable";

and if that doesn't work then try adding an or die to your query

$result = mysql_query($query) or die (mysql_error());

undream2

2:55 am on Mar 8, 2008 (gmt 0)

10+ Year Member



I don't know why this happened. After, testing a similiar code yesterday on the same table.. That it would give me this error..

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-Packard' at line 1

undream2

2:56 am on Mar 8, 2008 (gmt 0)

10+ Year Member



I forgot I used the mysql_error code line after the double quotes.

undream2

3:00 am on Mar 8, 2008 (gmt 0)

10+ Year Member



I guess, if I changed the HYPHEN out of the table name. And, updated the sql server to 5.0 from 4.1 that it would work... Any suggestions?

undream2

5:29 am on Mar 8, 2008 (gmt 0)

10+ Year Member



Sweet it worked. Using the same code. I just changed the table name and upgraded to mysql 5.0. Don't know which one worked.

feels good to have it come together.