<LINK REL=StyleSheet HREF="style/style.css" TYPE="text/css">
<p class="normal">
Question data will show here
</p>
<p class="normal">
<?php
//Set the asked question into a variable
$question = $_GET['question'];
//Get config variables
include "config.php";
//Set connection to database
mysql_connect("$databaseurl","$uname","$pword") or die("Could not connect");
//Select the_answer database
mysql_select_db("theanswer_theanswer") or die("Could not select");
//Create query to check for the qustion
$result = mysql_query("SELECT * FROM questions where question LIKE '$question'") or die("Invalid query: " . mysql_error());
//Run the query and check if there are results
if(mysql_num_rows($result) == 1)
{
$found = "1";
}
else
{
$found = "0";
}
//If results found
if($found == 1)
{
//Check if question has been answered
if($vars['answered'] == 1){
//Create an array of the MySql result
$vars = mysql_fetch_array($result);
//display question
echo $vars['question'];
//display answer
echo $vars['answer'];
}
//Check if question is unanswered
if($vars['answered'] == 0)
{
//Create an array of the MySql result
$vars = mysql_fetch_array($result);
Print "This question has been asked ";
echo $vars['asked'];
Print " times, but has not yet been answered.";
$asked = ($vars['asked'] + 1);
$id = $vars['id'];
$update = mysql_query("UPDATE questions SET (asked) VALUES ($asked) WHERE (id = '$id')") or die("Invalid query: " . mysql_error());
}
}
//If no results found
if($found == 0)
{
$question = $_GET['question'];
//Add the question to the database
$insert = mysql_query("INSERT INTO questions (question, answer, asked) VALUES ('$question','',1)") or die("Invalid query: " . mysql_error());
//Give message saying the question was not found and added
?>
You asked -<br>
<?php
echo $question;
?>
<br>
This is the first time this question has been asked. It has been added to our database
of unanswered questions and will be answered as soon as possible
<?php
}
?>
</p>