Welcome Guest.   Make a donation to an author on the site November 21, 2014, 10:31:05 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
View the new Member Awards and Badges page.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: I'm trying to figure out this tutorial (phP database driven website)  (Read 1929 times)
h0meopathic
Participant
*
Posts: 24

View Profile Give some DonationCredits to this forum member
« on: March 08, 2009, 09:53:42 PM »

http://www.devx.com/webdev/Article/27175/0/page/2

Formatted for PHP with the GeSHI Syntax Highlighter [copy or print]
  1. <?php
  2. // Connect to the database server Make sure not to use a 'blank' root password
  3. // the way that I am doing here! :)
  4. $dbconn = @mysql_connect('mysql6.000webhost.com', 'a8784371_kyle', 'xxx');
  5. if (!$dbconn)
  6. {
  7. die('Error connecting to DB!');
  8. }
  9. // Find the surveys db
  10. if (! @mysql_select_db('a8784371_surveys') )
  11. {
  12. die( '<p>Unable to locate the main database at this time.</p>' );
  13. }
  14.  
  15. // This page requires a URL parameter with the QuestionID.
  16. if(isset($_GET["QuestionID"]))
  17. $Qid = $_GET["QuestionID"];
  18. else
  19. die("Please set a question id in the URL");
  20.  
  21. // Get the Question text corresponding to this ID
  22. $Sql = "Select * from Questions where QuestionID=" . $Qid;
  23. $result= mysql_query($Sql) or die(mysql_error());
  24. $row = mysql_fetch_row($result);
  25. // The text of the Question is in Column 1
  26. $QText = $row[1];
  27.  
  28. // Get the options for this question.
  29. $Sql2 = "Select * from Options where QuestionID=" . $Qid;
  30. $OptResult = mysql_query($Sql2) or die(mysql_error());
  31. // Write out the HTML for the page
  32. ?>
  33. <html>
  34. <head>
  35. <meta http-equiv="Content-Language" content="en-us">
  36. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  37. <title>Test 1</title>
  38. <style>
  39. <!--
  40. .BulletText  
  41. { font-family: Verdana; font-size: 8pt;
  42.  text-align: left; line-height: 100%;
  43.  word-spacing: 0; margin-top: 0; margin-bottom: 0 }
  44. -->
  45. </style>
  46. </head>
  47.  
  48. <body>
  49. <!-- ---------------------------------------------------------------
  50. The question is going to be a HTML form. The form will be generated by
  51. this PHP script. It will be a paragraph of text containing the question
  52. followed by n radio buttons, with each being the options associated with
  53. the question. Finally, there will be a hidden button containing the
  54. Question ID (so it can be passed onto the form processor)
  55. ------------------------------------------------------------------>
  56. <form method="POST" action="process.php">
  57. <!-- Write out the question Text -->
  58. <p><?php echo($QText)?></p>
  59. <?
  60. $nVal = 0;
  61. while  ($optrow = mysql_fetch_array($OptResult))
  62.  {
  63.   if($nVal==0)
  64.   // The First Option will be checked.
  65.   echo("<p class='BulletText'><input type='radio' value='" .
  66.     $nVal . "' checked name='Q' id='Q'>" . $optrow[2] . "</p>");
  67.   else
  68.   // The Others Won't
  69.   echo("<p class='BulletText'><input type='radio' value='" . $nVal
  70.     . "' name='Q' id='Q'>" . $optrow[2] . "</p>");
  71.  $nVal++;
  72.  }
  73. ?>
  74. <p><input type="hidden" value="<?php echo($Qid); ?>" name="QID"/></p>
  75. <p><input type="submit" value="Submit" name="B1">
  76. <input type="reset" value="Reset" name="B2"></p>
  77. </form>
  78. </body>
  79. </html>
I view my php file in the browser using http://istem.comyr.com/survey.php (this is were the file is stored)

The code is executed until the php requests the "questionid" and I get the controlled error message, "Please set a question id in the URL".

By the code above I'm pretty sure that I'm getting into the database correctly.

The tutorial site tells me that I should call the page using example, http://yourserver/survey.php?questionid=1.

So I do http://istem.comyr.com/survey.php?questionid=1

I don't know what is wrong because I'm an relatively new to php.

This is how I created the my fields.

Formatted for SQL with the GeSHI Syntax Highlighter [copy or print]
  1. CREATE TABLE `answers` (
  2.  `AnswerID` int(11) NOT NULL AUTO_INCREMENT,
  3.  `AnswerValue` int(11) DEFAULT '0',
  4.  `AnswerIP` text,
  5.  `QuestionID` int(11) DEFAULT '0',
  6.  PRIMARY KEY  (`AnswerID`)
  7. ) TYPE=MyISAM;
  8.  
  9. CREATE TABLE `options` (
  10.  `OptionID` int(11) NOT NULL AUTO_INCREMENT,
  11.  `QuestionID` int(11) DEFAULT '0',
  12.  `OptionText` text,
  13.  `OptionValue` int(11) DEFAULT '0',
  14.  PRIMARY KEY  (`OptionID`)
  15. ) TYPE=MyISAM;
  16.  
  17. CREATE TABLE `questions` (
  18.  `QuestionID` int(11) NOT NULL AUTO_INCREMENT,
  19.  `QuestionText` text NOT NULL,
  20.  PRIMARY KEY  (`QuestionID`)
  21. ) TYPE=MyISAM;


Also, I added a record in 'questions' with id being 1, and text being 'What's your favorite color'.
and for options I connected each option to questionid=1.

I'm pretty sure my database is correct because everything makes sense and everything is spelled the same.

Please take a look and give me a few suggestions

Logged
justice
Supporting Member
**
Posts: 1,889



Solve issues simply.

View Profile WWW Give some DonationCredits to this forum member
« Reply #1 on: March 09, 2009, 05:55:38 AM »

Looks like you need to call the link as QuestionID not questionid.  Becuase you are asking for QuestionID on line 16.
http://istem.comyr.com/survey.php?QuestionID=1

Also at the moment you are just passing the query string to the database (i could ask for question 1 and the names of your tables) .  Before you promote it or put it live read through http://www.acunetix.com/w...curity/php-security-1.htm

« Last Edit: March 09, 2009, 06:01:50 AM by justice » Logged

h0meopathic
Participant
*
Posts: 24

View Profile Give some DonationCredits to this forum member
« Reply #2 on: March 09, 2009, 07:49:15 AM »

Oh wow! I had no idea it was case sensitive and to think I spent hours looking at it before I posted the problem here.

Thanks a lot justice. When I graduate college I'm definitely going to pass the buck (literal) because everyone here always helps and with a timely manner.
Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.115s | Server load: 0.15 ]