SOLID Posted June 24, 2006 Share Posted June 24, 2006 Hi Everyone, Im new to php and only been using it for a couple of months now. Im having some trouble with a db query?I have 3 tables questions, answers & selectionsIm trying to get an output like this[b]Question 1[/b]option1 - answeroption2 - answeroption3 - answer[b]Question 2[/b]option1 - answeroption2 - answeroption3 - answerI do get the question and the option to display but not the answer?? im not sure what i am doing wrong.There is an error being thrown.. Warning: mysql_query(): A link to the server could not be established in /index.php on line 84Access denied for user: 'root@localhost' (Using password: NO)I have highlighted the line like this ############heres the code[code]<?phpinclude("include/dbConnect.php");mysql_connect($fasthit,$user,$password);@mysql_select_db($database) or die( "Unable to select database");$query = "SELECT * FROM $dbQs WHERE year = $yr";$result = mysql_query($query) or die("unable to get data");$num = mysql_num_rows($result); mysql_close();$i=0;while ($i < $num) {$Qid=mysql_result($result,$i,"Qid");$question=trim(mysql_result($result,$i,"question"));$type=trim(mysql_result($result,$i,"type"));// WRITE QUESTIONecho "<p><b>".$question."</b></p>";// GET OPTION mysql_connect($fasthit,$user,$password); @mysql_select_db($database) or die( "Unable to select database"); $Squery = "SELECT * FROM $dbS WHERE parent_id = $Qid"; $Sresult = mysql_query($Squery) or die(mysql_error()); $Snum = mysql_num_rows($Sresult); mysql_close(); $S=0; while ($S < $Snum) { $option=mysql_result($Sresult,$S,"option"); echo $option." "; // GET SELECT BOX ANSWER include_once ("include/dbConnect.php");############ error here???? ############ mysql_connect($fasthit,$user,$password); @mysql_select_db($database) or die( "Unable to select database"); $SSquery = "SELECT COUNT(*) AS itIS FROM $dbAs WHERE Qid = $Qid"; $SSresult = mysql_query($SSquery) or die(mysql_error()); mysql_close(); echo $itIS."<br>"; $S++; }}[/code]I hope thats not too confusing?? sorry i usually use Coldfusion.Thanks in advance for your help Quote Link to comment Share on other sites More sharing options...
SOLID Posted June 25, 2006 Author Share Posted June 25, 2006 Can anyone point me in the right direction as to what im doing wrong here??Please help .. Quote Link to comment Share on other sites More sharing options...
jajtiii Posted June 25, 2006 Share Posted June 25, 2006 check your dbConnect file. It appears that it is not setting the correct values for your mysql connection validation. In fact, it appears that those variables are coming out to be null, so you're trying to connect with no username or pw.mysql then assumes you're coming in as root with no pw, which does not authenticate. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.