943,769 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2359
  • PHP RSS
Mar 6th, 2008
0

Getting information from database and display on the screen

Expand Post »
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
php Syntax (Toggle Plain Text)
  1. <?php
  2. /**
  3.  *
  4.  * Install setup page to allow the inital user to be set up
  5.  *
  6.  */
  7.  
  8. require_once("include/inc_global.php");
  9.  
  10.  
  11.  
  12.  
  13. //build the page
  14. $UI->page_title = 'Web-PA Admin Setup';
  15. $UI->menu_selected = '';
  16. $UI->breadcrumbs = array ('Admin setup' => null ,);
  17.  
  18.  
  19. $UI->head();
  20.  
  21. $UI->body();
  22. $UI->content_start();
  23.  
  24. // see if any of the settings have been sent
  25. $question1 = (string) fetch_POST('question1', null);
  26. $question2 = (string) fetch_POST('question2', null);
  27. $question3 = (string) fetch_POST('question3', null);
  28. $question4 = (string) fetch_POST('question4', null);
  29. $question5 = (string) fetch_POST('question5', null);
  30. $username = (string) fetch_POST('username', null);
  31. $password = (string) fetch_POST('password', null);
  32.  
  33. //if we have at least the username and the password then we can say that we are processing
  34. if ($username and $password){
  35.  
  36. // Sanitize the username/password data
  37. $username = substr($username,0,32);
  38. $password = substr($password,0,32);
  39.  
  40. //hash the password
  41. //$password = md5($password);
  42.  
  43. //add this information to the database
  44. $sql = 'INSERT INTO questions(question1, question2, question3, question4, question5, username, password)
  45. VALUES ("'.$question1.'", "'.$question2.'", "'.$question3.'", "'.$question4.'", "'.$question5.'", "'.$username.'", "'.$password.'");';
  46. $DB->_process_query($sql);
  47. ?>
  48. <div class="content_box">
  49. <p> Your details have been set up on the server and a new Administrator account has been created.</p>
  50. <p> To ensure that no other administrator accounts can be created we recomend that you remove this file from the server</p>
  51. </div>
  52. <?php
  53. }else{
  54.  
  55. ?>
  56.  
  57. <div class="content_box">
  58. <p>You can enter your details as required below.</p>
  59. <p>If you are intending to use the Database Authentication then you will need to enter a passsword. If you are using the LDAP
  60. Authentication then you still need to enter all the information, but the password is not required. </p>
  61. <form action="result.php" method="post" name="login_form" style="margin-bottom: 2em;">
  62. <div style="width: 300px;">
  63. <table class="form" cellpadding="2" cellspacing="1" width="100%">
  64. <tr>
  65. <th><label for="question1">Question 1</label></th>
  66. <td><input type="text" name="question1" id="question1" maxlength="30" size="30" value=""/></td>
  67. </tr>
  68. <tr>
  69. <th><label for="question2">Question 2</label></th>
  70. <td><input type="text" name="question2" id="question2" maxlength="30" size="30" value="" /></td>
  71. </tr>
  72. <tr>
  73. <th><label for="question3">Question 3</label></th>
  74. <td><input type="text" name="question3" id="question3" maxlength="30" size="30" value="" /></td>
  75. </tr>
  76. <tr>
  77. <th><label for="question4">Question 4</label></th>
  78. <td><input type="text" name="question4" id="question4" maxlength="30" size="30" value="" /></td>
  79. </tr>
  80. <tr>
  81. <th><label for="question5">Question 5</label></th>
  82. <td><input type="text" name="question5" id="question5" maxlength="30" size="30" value="" /></td>
  83. </tr>
  84. <tr>
  85. <th><label for="username"></label></th>
  86. <td><input type="hidden" value="none"name="username" id="username" maxlength="16" size="10" value="" /></td>
  87. </tr>
  88. <tr>
  89. <th><label for="password"></label></th>
  90. <td><input type="hidden" value="none" name="password" id="password" maxlength="16" size="10" value="" /></td>
  91. </tr>
  92. </table>
  93.  
  94. <div class="form_button_bar">
  95. <input class="safe_button" type="submit" name="submit" value="Set up" />
  96. </div>
  97. </div>
  98. </form>
  99. </div>
  100. <?php
  101. }
  102.  
  103. $UI->content_end(false);
  104. ?>

and result.php
php Syntax (Toggle Plain Text)
  1. <?php
  2. ob_start();
  3. $host="localhost"; // Host name
  4. $username=""; // Mysql username
  5. $password=""; // Mysql password
  6. $db_name="pa"; // Database name
  7. $tbl_name="questions"; // Table name
  8. // Get info from the session
  9.  
  10. // Connect to server and select databse.
  11. $db_handle= mysql_connect("$host", "$username", "$password")or die("cannot connect");
  12. //$db_found = mysql_select_db("$db_name")or die("cannot select DB");
  13.  
  14.  
  15. $db_found = mysql_select_db($db_name, $db_handle);
  16.  
  17. // Define $myquestion1 and $myquestion2 and $myquestion3 and $myquestion4 and $myquestion5
  18. $myquestion1=$_POST['myquestion1'];
  19. $myquestion2=$_POST['myquestion2'];
  20. $myquestion3=$_POST['myquestion3'];
  21. $myquestion4=$_POST['myquestion4'];
  22. $myquestion5=$_POST['myquestion5'];
  23.  
  24.  
  25.  
  26.  
  27. //$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and //password='$mypassword'";
  28. //$result=mysql_query($sql);
  29.  
  30.  
  31. //$sql=("SELECT * FROM $tbl_name WHERE question1='$myquestion1' and question2='$myquestion2' and question3 ='$myquestion3' and question4='$myquestion4' and question5='$myquestion5'");
  32.  
  33. //$result=mysql_query($sql);
  34.  
  35.  
  36. // Mysql_num_row is counting table row
  37. //$count=mysql_num_rows($result);
  38. // If result matched $myquestion1 and $myquestion2 and $myquestion3 and $myquestion4 and $myquestion5, table row must be 1 row
  39.  
  40. //if ($db_found) {
  41.  
  42. $sql = "SELECT * FROM tb_questions";
  43. $result = mysql_query($sql);
  44. $rowdetail = mysql_fetch_array($result);
  45. //while ($db_field = mysql_fetch_array($result)) {
  46. //echo $db_field['question1'] . "<BR>";
  47. //echo $db_field['question2'] . "<BR>";
  48. //print $db_field['question3'] . "<BR>";
  49. //print $db_field['question4'] . "<BR>";
  50. //print $db_field['question5'] . "<BR>";
  51. print "<p>Name: ".$rowdetail['firstname']." ".$rowdetail['surname']."<br />\n";
  52. print "Address: ".$rowdetail['address']."<br />\n";
  53. print "<input name= password id=password maxlength=316 size=110 />cxvbcv</td>"
  54.  
  55. //print "Postcode: ".$rowdetail['postcode']."\n";
  56.  
  57.  
  58.  
  59. //ob_end_flush();
  60. ?>

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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
dami06 is offline Offline
90 posts
since Oct 2006
Mar 7th, 2008
0

Re: Getting information from database and display on the screen

on lines 44 and 45 of questions.php
php Syntax (Toggle Plain Text)
  1. $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 )';
php Syntax (Toggle Plain Text)
  1. $sql = 'INSERT INTO questions(question1, question2, question3, question4, question5, username, password) VALUES ("'.$question1.'", "'.$question2.'", "'.$question3.'", "'.$question4.'", "'.$question5.'", "'.$username.'", "'.$password.'")';
Reputation Points: 232
Solved Threads: 137
Practically a Master Poster
buddylee17 is offline Offline
665 posts
since Nov 2007
Mar 7th, 2008
0

Re: Getting information from database and display on the screen

Hi,
Try removing the
php Syntax (Toggle Plain Text)
  1. ob_start();
at the top of your code.
Also, shouldn't your variables be this:
php Syntax (Toggle Plain Text)
  1. $myquestion1=$_POST['question1'];
  2. $myquestion2=$_POST['question2'];
  3. $myquestion3=$_POST['question3'];
  4. $myquestion4=$_POST['question4'];
  5. $myquestion5=$_POST['question5'];
intead of
php Syntax (Toggle Plain Text)
  1. $myquestion1=$_POST['myquestion1'];$myquestion2=$_POST['myquestion2'];$myquestion3=$_POST['myquestion3'];$myquestion4=$_POST['myquestion4'];$myquestion5=$_POST['myquestion5'];
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
JeniF is offline Offline
52 posts
since Aug 2007
Mar 7th, 2008
0

Re: Getting information from database and display on the screen

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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
dami06 is offline Offline
90 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Error Checking Validation
Next Thread in PHP Forum Timeline: Trouble with Array Delete in PHP , MySQL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC