I have a form that allows a user to create and store quiz questions in the database for later use, I have ran across error messages on each question that has a ' . The tables are all set up as VARCHAR() so I dont know whats going on. Here is the code.
$testname = trim($_POST['testname']);
echo $testname;
$question = mysql_escape_string($_POST['question']);
$option1 = mysql_escape_string($_POST['option1']);
$option2 = mysql_escape_string($_POST['option2']);
$option3 = mysql_escape_string($_POST['option3']);
$option4 = mysql_escape_string($_POST['option4']);
$answer = mysql_escape_string($_POST['correct']);
$question1 = preg_replace("/'/", "", $question);
$option1a = preg_replace("/'/", "", $option1);
$option2a = preg_replace("/'/", "", $option2);
$option3a = preg_replace("/'/", "", $option3);
$option4a = preg_replace("/'/", "", $option4);
echo $question1;
echo $option1a;
echo $option2a;
echo $option3a;
echo $option4a;
$select = mysql_query("INSERT INTO pq_crtp_quiz SET question = '$question1', option1 = '$option1a', option2 = '$option2a', option3 = '$option3a', option4 = '$option4a', answer = '$answer', testname = '$testname'");
echo mysql_error();
echo "Question Added Successfully";
echo "<meta http-equiv=Refresh content=20;url=quizadd.php>";
[code=html]
<table>
<tr><th>Add a question to a test</th></tr>
<form action="" method="post" name="Add Question">
<tr><td>Select a test <?php echo '<SELECT name="testname">';
foreach ($showtest as $key => $value) {
echo '<OPTION value="' . $value . '"> ' . $value . '';
}
echo '</select>'; ?></td></tr>
<tr><td>Question</td><tr>
<tr><td><textarea name="question" cols="120" rows="20" wrap="virtual"></textarea></td></tr>
<tr><th>Input the answer options</th></tr>
<tr><td>Option 1 <input name="option1" type="text" size="40" maxlength="160" /></td></tr>
<tr><td>Option 2 <input name="option2" type="text" size="40" maxlength="160" /></td></tr>
<tr><td>Option 3 <input name="option3" type="text" size="40" maxlength="160" /></td></tr>
<tr><td>Option 4 <input name="option4" type="text" size="40" maxlength="160" /></td></tr>
<p>
<tr><th>Select the correct answer: </th></tr>
<label>
<tr><td><input type="radio" name="correct" value="Option 1" id="correct_0" />
option1</label></td></tr>
<br />
<label>
<tr><td> <input type="radio" name="correct" value="Option 2" id="correct_1" />
option2</label></td></tr>
<br />
<label>
<tr><td><input type="radio" name="correct" value="Option 3" id="correct_2" />
option3</label></td></tr>
<br />
<label>
<tr><td><input type="radio" name="correct" value="Option 4" id="correct_3" />
option4</label></td></tr>
<br />
</p>
<tr><td><input type="submit" name="submitquestion" value="Next"></td></tr>
</form>
</table>
[/CODE]
An example would be...
Question :What does it mean if an agent’s license is inactive?
Error: Incorrect string value: '\x92s lic...' for column 'question' at row 1
I tested my preg_replace code on a seperate page and it strips ' like its supposed to, but not here. I figured, if my database wont take ', then just get rid of em. So now I have 2 problems lol...