PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
This snippet was running perfectly on localhost, but after I uploaded the file containing this snippet on a webserver, the script does generate an error, or even displaying none (no results).
#selects all data from table and displays it in textfields. If failed, it will display the error
$sql = "SELECT * from tblquotes ORDER BY Rand() LIMIT 1";
$result = mysql_query($sql,$connection);
if($result = mysql_query($sql ,$connection)) {
$num = mysql_numrows($result);
$count =0;
while ($count < $num){
$q1 = mysql_result($result,$count,"quote");
$q2 = mysql_result($result,$count,"author");
$count++;
}
} else{
echo "ERROR: ".mysql_error();
}
what seems to be the problem? Need help...
I'm running on PHP 4.4.4 on Localhost and PHP 5.2.9 on the webserver. Mysql 4/5 on Localhost and Mysql 4.1.22 on the webserver
#selects all data from table and displays it in textfields. If failed, it will display the error
$sql = "SELECT * from tblquotes ORDER BY Rand() LIMIT 1";
$result = mysql_query($sql,$connection);
if($result = mysql_query($sql ,$connection)) {
$num = mysql_numrows($result);
$count =0;
while ($count < $num){
$q1 = mysql_result($result,$count,"quote");
$q2 = mysql_result($result,$count,"author");
$count++;
}
} else{
echo "ERROR: ".mysql_error();
}
echo $q1."\n";
echo $q2;
#selects all data from table and displays it in textfields. If failed, it will display the error
$sql = "SELECT * from tblquotes ORDER BY Rand() LIMIT 1";
$result = mysql_query($sql,$connection);
if($result = mysql_query($sql ,$connection)) {
$num = mysql_numrows($result);
$count =0;
while ($count < $num){
$q1 = mysql_result($result,$count,"quote");
$q2 = mysql_result($result,$count,"author");
$count++;
}
} else{
echo "ERROR: ".mysql_error();
}
echo $q1."\n";
echo $q2;
oh, I just forgot to include the suceeding code, but I did include a way of displaying those variables.
The code was really fine, except for minor adjustments but now It seemed to be I can't establish a connection with the database.
is the hostname = localhost, for a web hosted account?
It depends on whether or not your SQL server is on the same machine as your web server or if they've done a hostname change. You need to contact your web host to find out.