Hi There,
I am trying to get the information that i have put in the database to be displayed on the screen but i am getting this error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\capat\result.php on line 44

The error doesn't seem to go away AT ALLL

this is my code

 * Install setup page to allow the inital user to be set up

 //build the page
 $UI->page_title = 'Web-PA Admin Setup';
 $UI->menu_selected = '';
 $UI->breadcrumbs = array	('Admin setup'	=> null ,);


 // see if any of the settings have been sent
 $question1 = (string) fetch_POST('question1', null);
 $question2 = (string) fetch_POST('question2', null);
 $question3 = (string) fetch_POST('question3', null);
 $question4 = (string) fetch_POST('question4', null);
 $question5 = (string) fetch_POST('question5', null);
 $username = (string) fetch_POST('username', null);
 $password = (string) fetch_POST('password', null);
 //if we have at least the username and the password then we can say that we are processing
 if ($username and $password){
 	// Sanitize the username/password data
	$username = substr($username,0,32);
	$password = substr($password,0,32);
	//hash the password
	//$password = md5($password);
	//add this information to the database
	$sql = 'INSERT INTO questions(question1, question2, question3, question4, question5, username, password)
		    VALUES ("'.$question1.'", "'.$question2.'", "'.$question3.'", "'.$question4.'", "'.$question5.'", "'.$username.'", "'.$password.'");';
	<div class="content_box">
		<p> Your details have been set up on the server and a new Administrator account has been created.</p>
		<p> To ensure that no other administrator accounts can be created we recomend that you remove this file from the server</p>


<div class="content_box">
	<p>You can enter your details as required below.</p>
	<p>If you are intending to use the Database Authentication then you will need to enter a passsword. If you are using the LDAP 
	Authentication then you still need to enter all the information, but the password is not required. </p>
	<form action="result.php" method="post" name="login_form" style="margin-bottom: 2em;">
		<div style="width: 300px;">
			<table class="form" cellpadding="2" cellspacing="1" width="100%">
					<th><label for="question1">Question 1</label></th>
					<td><input type="text" name="question1" id="question1" maxlength="30" size="30" value=""/></td>
					<th><label for="question2">Question 2</label></th>
					<td><input type="text" name="question2" id="question2" maxlength="30" size="30" value="" /></td>
					<th><label for="question3">Question 3</label></th>
					<td><input type="text" name="question3" id="question3" maxlength="30" size="30" value="" /></td>
					<th><label for="question4">Question 4</label></th>
					<td><input type="text" name="question4" id="question4" maxlength="30" size="30" value="" /></td>
					<th><label for="question5">Question 5</label></th>
					<td><input type="text" name="question5" id="question5" maxlength="30" size="30" value="" /></td>
					<th><label for="username"></label></th>
					<td><input type="hidden" value="none"name="username" id="username" maxlength="16" size="10" value="" /></td>
					<th><label for="password"></label></th>
					<td><input type="hidden" value="none" name="password" id="password" maxlength="16" size="10" value="" /></td>

			<div class="form_button_bar">
				<input class="safe_button" type="submit" name="submit" value="Set up" />

and result.php

$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="pa"; // Database name
$tbl_name="questions"; // Table name
 // Get info from the session

// Connect to server and select databse.
$db_handle= mysql_connect("$host", "$username", "$password")or die("cannot connect");
//$db_found = mysql_select_db("$db_name")or die("cannot select DB");

$db_found = mysql_select_db($db_name, $db_handle);

// Define $myquestion1 and $myquestion2 and $myquestion3 and $myquestion4 and $myquestion5

//$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and //password='$mypassword'";

//$sql=("SELECT * FROM $tbl_name WHERE question1='$myquestion1' and question2='$myquestion2' and question3 ='$myquestion3' and question4='$myquestion4' and question5='$myquestion5'");


// Mysql_num_row is counting table row
// If result matched $myquestion1 and $myquestion2 and $myquestion3 and $myquestion4 and $myquestion5, table row must be 1 row

//if ($db_found) {

$sql = "SELECT * FROM tb_questions";
$result = mysql_query($sql);
$rowdetail = mysql_fetch_array($result);
//while ($db_field = mysql_fetch_array($result)) {
//echo $db_field['question1'] . "<BR>";
//echo $db_field['question2'] . "<BR>";
//print $db_field['question3'] . "<BR>";
//print $db_field['question4'] . "<BR>";
//print $db_field['question5'] . "<BR>";
print "<p>Name: ".$rowdetail['firstname']." ".$rowdetail['surname']."<br />\n";  
print "Address: ".$rowdetail['address']."<br />\n";  
print "<input name= password id=password maxlength=316 size=110  />cxvbcv</td>"
//print "Postcode: ".$rowdetail['postcode']."\n";  


Please help me out!!!!

8 Years
Discussion Span
Last Post by dami06

on lines 44 and 45 of questions.php

$sql = 'INSERT INTO questions(question1, question2, question3, question4, question5, username, password) VALUES ("'.$question1.'", "'.$question2.'", "'.$question3.'", "'.$question4.'", "'.$question5.'", "'.$username.'", "'.$password.'");';

Is this insert working? The reason I ask is because you have );'; at the end. Try getting rid of that extra semicolon and end it with this )';

$sql = 'INSERT INTO questions(question1, question2, question3, question4, question5, username, password) VALUES ("'.$question1.'", "'.$question2.'", "'.$question3.'", "'.$question4.'", "'.$question5.'", "'.$username.'", "'.$password.'")';

Try removing the


at the top of your code.
Also, shouldn't your variables be this:


intead of


I tried all that but still it didn't work. I'll try another method and see how far i get on with that..Thanks a lot for your help y'all

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.