Smudly Posted June 9, 2010 Share Posted June 9, 2010 This code is supposed to choose a random website to be displayed once the user clicks the next button (This is for a traffic exchange project I'm working on). I'm getting the following errors: Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/s/m/u/smudlys/html/surf.php on line 10 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/content/s/m/u/smudlys/html/surf.php on line 10 Error in query: SELECT `users.id`, users.credits, users.username, websites.id, websites.url, websites.userid, websites.active FROM users INNER JOIN websites ON websites.userid = users.id where websites.active='y' and users.credits > 0 and websites.userid != order by rand(). Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) Here is the code I'm using: // Select a Random Website $sitequery = "SELECT users.id, users.credits, users.username, websites.id, websites.url, websites.userid, websites.active FROM users INNER JOIN websites ON websites.userid = users.id where websites.active='y' and users.credits > 0 and websites.userid !=".$id." order by rand()"; $siteresult = mysql_query($sitequery) or die("Error in query: $sitequery. " . mysql_error()); if (mysql_num_rows($siteresult) != 0){ $siterow = mysql_fetch_array($siteresult); $url = $siterow["url"]; } any suggestions? Where did I go wrong? Link to comment https://forums.phpfreaks.com/topic/204311-choosing-random-website-from-database/ Share on other sites More sharing options...
ohdang888 Posted June 9, 2010 Share Posted June 9, 2010 your error has nothing to do with the query itself, its the connection. are you connecting the to database before this code is executed? Link to comment https://forums.phpfreaks.com/topic/204311-choosing-random-website-from-database/#findComment-1070047 Share on other sites More sharing options...
Smudly Posted June 9, 2010 Author Share Posted June 9, 2010 I think that was the problem. But here's a new problem. I created a connect.php file, and included it near the top of my file after <?php For some reason, it is just echoing it to the page. Why would it be doing this? Link to comment https://forums.phpfreaks.com/topic/204311-choosing-random-website-from-database/#findComment-1070078 Share on other sites More sharing options...
ohdang888 Posted June 9, 2010 Share Posted June 9, 2010 post the code of both files Link to comment https://forums.phpfreaks.com/topic/204311-choosing-random-website-from-database/#findComment-1070084 Share on other sites More sharing options...
Smudly Posted June 9, 2010 Author Share Posted June 9, 2010 In the include file I failed to put the <?php ?> inside. That is now fixed. Here is my current error: Error in query: SELECT users.id, users.credits, users.username, websites.id, websites.url, websites.userid, websites.active FROM users INNER JOIN websites ON websites.userid = users.id where websites.active='y' and users.credits > 0 and websites.userid != order by rand(). 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 'order by rand()' at line 3 And my code: <?php session_start(); include('inc/connect.php'); // Select a Random Website $sitequery = "SELECT users.id, users.credits, users.username, websites.id, websites.url, websites.userid, websites.active FROM users INNER JOIN websites ON websites.userid = users.id where websites.active='y' and users.credits > 0 and websites.userid !=".$id." order by rand()"; $siteresult = mysql_query($sitequery) or die("Error in query: $sitequery. " . mysql_error()); if (mysql_num_rows($siteresult) != 0){ $siterow = mysql_fetch_array($siteresult); $url = $siterow["url"]; } ?> Link to comment https://forums.phpfreaks.com/topic/204311-choosing-random-website-from-database/#findComment-1070118 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.