http://www.devx.com/...ticle/27175/0/page/2<?php
// Connect to the database server Make sure not to use a 'blank' root password
// the way that I am doing here! :)
$dbconn = @mysql_connect('mysql6.000webhost.com', 'a8784371_kyle', 'xxx'); if (!$dbconn)
{
die('Error connecting to DB!'); }
// Find the surveys db
{
die( '<p>Unable to locate the main database at this time.</p>' ); }
// This page requires a URL parameter with the QuestionID.
if(isset($_GET["QuestionID"])) $Qid = $_GET["QuestionID"];
else
die("Please set a question id in the URL");
// Get the Question text corresponding to this ID
$Sql = "Select * from Questions where QuestionID=" . $Qid;
// The text of the Question is in Column 1
$QText = $row[1];
// Get the options for this question.
$Sql2 = "Select * from Options where QuestionID=" . $Qid;
// Write out the HTML for the page
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Test 1</title>
<style>
<!--
.BulletText
{ font-family: Verdana; font-size: 8pt;
text-align: left; line-height: 100%;
word-spacing: 0; margin-top: 0; margin-bottom: 0 }
-->
</style>
</head>
<body>
<!-- ---------------------------------------------------------------
The question is going to be a HTML form. The form will be generated by
this PHP script. It will be a paragraph of text containing the question
followed by n radio buttons, with each being the options associated with
the question. Finally, there will be a hidden button containing the
Question ID (so it can be passed onto the form processor)
------------------------------------------------------------------>
<form method="POST" action="process.php">
<!-- Write out the question Text -->
<p><?php echo($QText)?></p>
<?
$nVal = 0;
{
if($nVal==0)
// The First Option will be checked.
echo("<p class='BulletText'><input type='radio' value='" .
$nVal . "' checked name='Q' id='Q'>" . $optrow[2] . "</p>");
else
// The Others Won't
echo("<p class='BulletText'><input type='radio' value='" . $nVal
. "' name='Q' id='Q'>" . $optrow[2] . "</p>");
$nVal++;
}
?>
<p><input type="hidden" value="<?php echo($Qid); ?>" name="QID"/></p>
<p><input type="submit" value="Submit" name="B1">
<input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</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/su...vey.php?questionid=1.
So I do
http://istem.comyr.c...vey.php?questionid=1I don't know what is wrong because I'm an relatively new to php.
This is how I created the my fields.
CREATE TABLE `answers` (
`AnswerID` int(11) NOT NULL auto_increment,
`AnswerValue` int(11) default '0',
`AnswerIP` text,
`QuestionID` int(11) default '0',
PRIMARY KEY (`AnswerID`)
) TYPE=MyISAM;
CREATE TABLE `options` (
`OptionID` int(11) NOT NULL auto_increment,
`QuestionID` int(11) default '0',
`OptionText` text,
`OptionValue` int(11) default '0',
PRIMARY KEY (`OptionID`)
) TYPE=MyISAM;
CREATE TABLE `questions` (
`QuestionID` int(11) NOT NULL auto_increment,
`QuestionText` text NOT NULL,
PRIMARY KEY (`QuestionID`)
) 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