| | |
Getting information from database and display on the screen
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2006
Posts: 90
Reputation:
Solved Threads: 0
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
questions.php
and result.php
Please help me out!!!!
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
questions.php
php Syntax (Toggle Plain Text)
<?php /** * * Install setup page to allow the inital user to be set up * */ require_once("include/inc_global.php"); //build the page $UI->page_title = 'Web-PA Admin Setup'; $UI->menu_selected = ''; $UI->breadcrumbs = array ('Admin setup' => null ,); $UI->head(); $UI->body(); $UI->content_start(); // 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.'");'; $DB->_process_query($sql); ?> <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> <?php }else{ ?> <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%"> <tr> <th><label for="question1">Question 1</label></th> <td><input type="text" name="question1" id="question1" maxlength="30" size="30" value=""/></td> </tr> <tr> <th><label for="question2">Question 2</label></th> <td><input type="text" name="question2" id="question2" maxlength="30" size="30" value="" /></td> </tr> <tr> <th><label for="question3">Question 3</label></th> <td><input type="text" name="question3" id="question3" maxlength="30" size="30" value="" /></td> </tr> <tr> <th><label for="question4">Question 4</label></th> <td><input type="text" name="question4" id="question4" maxlength="30" size="30" value="" /></td> </tr> <tr> <th><label for="question5">Question 5</label></th> <td><input type="text" name="question5" id="question5" maxlength="30" size="30" value="" /></td> </tr> <tr> <th><label for="username"></label></th> <td><input type="hidden" value="none"name="username" id="username" maxlength="16" size="10" value="" /></td> </tr> <tr> <th><label for="password"></label></th> <td><input type="hidden" value="none" name="password" id="password" maxlength="16" size="10" value="" /></td> </tr> </table> <div class="form_button_bar"> <input class="safe_button" type="submit" name="submit" value="Set up" /> </div> </div> </form> </div> <?php } $UI->content_end(false); ?>
and result.php
php Syntax (Toggle Plain Text)
<?php ob_start(); $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 $myquestion1=$_POST['myquestion1']; $myquestion2=$_POST['myquestion2']; $myquestion3=$_POST['myquestion3']; $myquestion4=$_POST['myquestion4']; $myquestion5=$_POST['myquestion5']; //$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and //password='$mypassword'"; //$result=mysql_query($sql); //$sql=("SELECT * FROM $tbl_name WHERE question1='$myquestion1' and question2='$myquestion2' and question3 ='$myquestion3' and question4='$myquestion4' and question5='$myquestion5'"); //$result=mysql_query($sql); // Mysql_num_row is counting table row //$count=mysql_num_rows($result); // 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"; //ob_end_flush(); ?>
Please help me out!!!!
Last edited by peter_budo; Mar 6th, 2008 at 8:17 pm. Reason: Just editing closing tag on first code example
on lines 44 and 45 of questions.php
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 )';
php Syntax (Toggle Plain Text)
$sql = 'INSERT INTO questions(question1, question2, question3, question4, question5, username, password) VALUES ("'.$question1.'", "'.$question2.'", "'.$question3.'", "'.$question4.'", "'.$question5.'", "'.$username.'", "'.$password.'");';
php Syntax (Toggle Plain Text)
$sql = 'INSERT INTO questions(question1, question2, question3, question4, question5, username, password) VALUES ("'.$question1.'", "'.$question2.'", "'.$question3.'", "'.$question4.'", "'.$question5.'", "'.$username.'", "'.$password.'")';
Hi,
Try removing the
at the top of your code.
Also, shouldn't your variables be this:
intead of
Try removing the
php Syntax (Toggle Plain Text)
ob_start();
Also, shouldn't your variables be this:
php Syntax (Toggle Plain Text)
$myquestion1=$_POST['question1']; $myquestion2=$_POST['question2']; $myquestion3=$_POST['question3']; $myquestion4=$_POST['question4']; $myquestion5=$_POST['question5'];
php Syntax (Toggle Plain Text)
$myquestion1=$_POST['myquestion1'];$myquestion2=$_POST['myquestion2'];$myquestion3=$_POST['myquestion3'];$myquestion4=$_POST['myquestion4'];$myquestion5=$_POST['myquestion5'];
I keep hitting "escape", but I'm still here!!!!
:}
:}
![]() |
Similar Threads
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- Question regarding Access database sql. (MS Access and FileMaker Pro)
- How to display my sql 'Count' result... (VB.NET)
- Storing dynamic form values in Arrays for display & insert (PHP)
- Easy Qu - Getting data with PHP (PHP)
- Ms Access Help Please (MySQL)
- Web Form & Database!!! PLEASE (MS SQL)
- php wont submit data into the database (PHP)
- over heating (Cases, Fans and Power Supplies)
- Processor (Windows NT / 2000 / XP)
Other Threads in the PHP Forum
- Previous Thread: Error Checking Validation
- Next Thread: Trouble with Array Delete in PHP , MySQL
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code codingproblem cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select send server sessions sms snippet soap source space speed sql static structure syntax system table tutorial up-to-date update upload url validation validator variable video web wordpress xml youtube





