Jump to content

morocco-iceberg

Members
  • Posts

    100
  • Joined

Everything posted by morocco-iceberg

  1. Just wondering how to preset radio buttons dynamically using php. Say, pull data from a database table and use that to select which radio button of a group should be automatically checked?
  2. I keep getting this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE paragraph_one='a'' at line 1 But I've gone through my code and can't find what is wrong... the code is quite long so I've only posted what I think are the relevant sections. (The error occurs whilst trying to process if(isset($_POST["update"])).) <?php if(isset($_POST["update"])){ $x = mysql_real_escape_string($_POST["update"]); $paragraph_one = mysql_real_escape_string($_POST["paragraph_one"]); $paragraph_two = mysql_real_escape_string($_POST["paragraph_two"]); $paragraph_three = mysql_real_escape_string($_POST["paragraph_three"]); $paragraph_four = mysql_real_escape_string($_POST["paragraph_four"]); $question_one = mysql_real_escape_string($_POST["question_one"]); $question_one_correct = mysql_real_escape_string($_POST["question_one_correct"]); $answer_one_a = mysql_real_escape_string($_POST["answer_one_a"]); $answer_one_b = mysql_real_escape_string($_POST["answer_one_b"]); $answer_one_c = mysql_real_escape_string($_POST["answer_one_c"]); $answer_one_d = mysql_real_escape_string($_POST["answer_one_d"]); $question_two = mysql_real_escape_string($_POST["question_two"]); $question_two_correct = mysql_real_escape_string($_POST["question_two_correct"]); $answer_two_a = mysql_real_escape_string($_POST["answer_two_a"]); $answer_two_b = mysql_real_escape_string($_POST["answer_two_b"]); $answer_two_c = mysql_real_escape_string($_POST["answer_two_c"]); $answer_two_d = mysql_real_escape_string($_POST["answer_two_d"]); $question_three = mysql_real_escape_string($_POST["question_three"]); $question_three_correct = mysql_real_escape_string($_POST["question_three_correct"]); $answer_three_a = mysql_real_escape_string($_POST["answer_three_a"]); $answer_three_b = mysql_real_escape_string($_POST["answer_three_b"]); $answer_three_c = mysql_real_escape_string($_POST["answer_three_c"]); $answer_three_d = mysql_real_escape_string($_POST["answer_three_d"]); $question_four = mysql_real_escape_string($_POST["question_four"]); $question_four_correct = mysql_real_escape_string($_POST["question_four_correct"]); $answer_four_a = mysql_real_escape_string($_POST["answer_four_a"]); $answer_four_b = mysql_real_escape_string($_POST["answer_four_b"]); $answer_four_c = mysql_real_escape_string($_POST["answer_four_c"]); $answer_four_d = mysql_real_escape_string($_POST["answer_four_d"]); $question_five = mysql_real_escape_string($_POST["question_five"]); $question_five_correct = mysql_real_escape_string($_POST["question_five_correct"]); $answer_five_a = mysql_real_escape_string($_POST["answer_five_a"]); $answer_five_b = mysql_real_escape_string($_POST["answer_five_b"]); $answer_five_c = mysql_real_escape_string($_POST["answer_five_c"]); $answer_five_d = mysql_real_escape_string($_POST["answer_five_d"]); $question_six = mysql_real_escape_string($_POST["question_six"]); $question_six_correct = mysql_real_escape_string($_POST["question_six_correct"]); $answer_six_a = mysql_real_escape_string($_POST["answer_six_a"]); $answer_six_b = mysql_real_escape_string($_POST["answer_six_b"]); $answer_six_c = mysql_real_escape_string($_POST["answer_six_c"]); $answer_six_d = mysql_real_escape_string($_POST["answer_six_d"]); $question_seven = mysql_real_escape_string($_POST["question_seven"]); $question_seven_correct = mysql_real_escape_string($_POST["question_seven_correct"]); $answer_seven_a = mysql_real_escape_string($_POST["answer_seven_a"]); $answer_seven_b = mysql_real_escape_string($_POST["answer_seven_b"]); $answer_seven_c = mysql_real_escape_string($_POST["answer_seven_c"]); $answer_seven_d = mysql_real_escape_string($_POST["answer_seven_d"]); $question_eight = mysql_real_escape_string($_POST["question_eight"]); $question_eight_correct = mysql_real_escape_string($_POST["question_eight_correct"]); $answer_eight_a = mysql_real_escape_string($_POST["answer_eight_a"]); $answer_eight_b = mysql_real_escape_string($_POST["answer_eight_b"]); $answer_eight_c = mysql_real_escape_string($_POST["answer_eight_c"]); $answer_eight_d = mysql_real_escape_string($_POST["answer_eight_d"]); $question_nine = mysql_real_escape_string($_POST["question_nine"]); $question_nine_correct = mysql_real_escape_string($_POST["question_nine_correct"]); $answer_nine_a = mysql_real_escape_string($_POST["answer_nine_a"]); $answer_nine_b = mysql_real_escape_string($_POST["answer_nine_b"]); $answer_nine_c = mysql_real_escape_string($_POST["answer_nine_c"]); $answer_nine_d = mysql_real_escape_string($_POST["answer_nine_d"]); $question_ten = mysql_real_escape_string($_POST["question_ten"]); $question_ten_correct = mysql_real_escape_string($_POST["question_ten_correct"]); $answer_ten_a = mysql_real_escape_string($_POST["answer_ten_a"]); $answer_ten_b = mysql_real_escape_string($_POST["answer_ten_b"]); $answer_ten_c = mysql_real_escape_string($_POST["answer_ten_c"]); $answer_ten_d = mysql_real_escape_string($_POST["answer_ten_d"]); mysql_query("UPDATE reading SET paragraph_one='$paragraph_one', paragraph_two='$paragraph_two', paragraph_three='$paragraph_three', paragraph_four='$paragraph_four', question_one='$question_one', question_one_correct='$question_one_correct', answer_one_a='$answer_one_a', answer_one_b='$answer_one_b', answer_one_c='$answer_one_c', answer_one_d='$answer_one_d', question_two='$question_two', question_two_correct='$question_two_correct', answer_two_a='$answer_two_a', answer_two_b='$answer_two_b', answer_two_c='$answer_two_c', answer_two_d='$answer_two_d', question_three='$question_three', question_three_correct='$question_three_correct', answer_three_a='$answer_three_a', answer_three_b='$answer_three_b', answer_three_c='$answer_three_c', answer_three_d='$answer_three_d', question_four='$question_four', question_four_correct='$question_four_correct', answer_four_a='$answer_four_a', answer_four_b='$answer_four_b', answer_four_c='$answer_four_c', answer_four_d='$answer_four_d', question_five='$question_five', question_five_correct='$question_five_correct', answer_five_a='$answer_five_a', answer_five_b='$answer_five_b', answer_five_c='$answer_five_c', answer_five_d='$answer_five_d', question_six='$question_six', question_six_correct='$question_six_correct', answer_six_a='$answer_six_a', answer_six_b='$answer_six_b', answer_six_c='$answer_six_c', answer_six_d='$answer_six_d', question_seven='$question_seven', question_seven_correct='$question_seven_correct', answer_seven_a='$answer_seven_a', answer_seven_b='$answer_seven_b', answer_seven_c='$answer_seven_c', answer_seven_d='$answer_seven_d', question_eight='$question_eight', question_eight_correct='$question_eight_correct', answer_eight_a='$answer_eight_a', answer_eight_b='$answer_eight_b', answer_eight_c='$answer_eight_c', answer_eight_d='$answer_eight_d', question_nine='$question_nine', question_nine_correct='$question_nine_correct', answer_nine_a='$answer_nine_a', answer_nine_b='$answer_nine_b', answer_nine_c='$answer_nine_c', answer_nine_d='$answer_nine_d', question_ten='$question_ten', question_ten_correct='$question_ten_correct', answer_ten_a='$answer_ten_a', answer_ten_b='$answer_ten_b', answer_ten_c='$answer_ten_c', answer_ten_d='$answer_ten_d', WHERE paragraph_one='$x' ") or die(mysql_error()); $success_message = "Question was edited."; } echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <title>Edit Reading Questions & Answers | Online Placement Test | Viva College</title> <link rel=\"stylesheet\" type=\"text/css\" href=\"css.css\" /> </head> <body> <div id=\"timer\"> </div> <div id=\"wrap\"> <div id=\"mainheader\"> </div> <div id=\"editcontent\"> <div id=\"orangeheader\"><br/> Edit Reading Questions & Answers </div> <div id=\"text\"> " . $success_message; if(isset($_POST["edit"])){ $paragraph_one = mysql_real_escape_string($_POST["edit"]); $sql = mysql_query("SELECT * FROM reading WHERE paragraph_one='$paragraph_one'") or die($error_message); while($row = mysql_fetch_array($sql)){ $paragraph_one = $row["paragraph_one"]; $paragraph_two = $row["paragraph_two"]; $paragraph_three = $row["paragraph_three"]; $paragraph_four = $row["paragraph_four"]; $question_one = $row["question_one"]; $question_one_correct = $row["question_one_correct"]; $answer_one_a = $row["answer_one_a"]; $answer_one_b = $row["answer_one_b"]; $answer_one_c = $row["answer_one_c"]; $answer_one_d = $row["answer_one_d"]; $question_two = $row["question_two"]; $question_two_correct = $row["question_two_correct"]; $answer_two_a = $row["answer_two_a"]; $answer_two_b = $row["answer_two_b"]; $answer_two_c = $row["answer_two_c"]; $answer_two_d = $row["answer_two_d"]; $question_three = $row["question_three"]; $question_three_correct = $row["question_three_correct"]; $answer_three_a = $row["answer_three_a"];; $answer_three_b = $row["answer_three_b"]; $answer_three_c = $row["answer_three_c"]; $answer_three_d = $row["answer_three_d"]; $question_four = $row["question_four"]; $question_four_correct = $row["question_four_correct"]; $answer_four_a = $row["answer_four_a"]; $answer_four_b = $row["answer_four_b"]; $answer_four_c = $row["answer_four_c"]; $answer_four_d = $row["answer_four_d"]; $question_five = $row["question_five"]; $question_five_correct = $row["question_five_correct"]; $answer_five_a = $row["answer_five_a"]; $answer_five_b = $row["answer_five_b"]; $answer_five_c = $row["answer_five_c"]; $answer_five_d = $row["answer_five_d"]; $question_six = $row["question_six"]; $question_six_correct = $row["question_six_correct"]; $answer_six_a = $row["answer_six_a"]; $answer_six_b = $row["answer_six_b"]; $answer_six_c = $row["answer_six_c"]; $answer_six_d = $row["answer_six_d"]; $question_seven = $row["question_seven"]; $question_seven_correct = $row["question_seven_correct"]; $answer_seven_a = $row["answer_seven_a"]; $answer_seven_b = $row["answer_seven_b"]; $answer_seven_c = $row["answer_seven_c"]; $answer_seven_d = $row["answer_seven_d"]; $question_eight = $row["question_eight"]; $question_eight_correct = $row["question_eight_correct"]; $answer_eight_a = $row["answer_eight_a"]; $answer_eight_b = $row["answer_eight_b"]; $answer_eight_c = $row["answer_eight_c"]; $answer_eight_d = $row["answer_eight_d"]; $question_nine = $row["question_nine"]; $question_nine_correct = $row["question_nine_correct"]; $answer_nine_a = $row["answer_nine_a"]; $answer_nine_b = $row["answer_nine_b"]; $answer_nine_c = $row["answer_nine_c"]; $answer_nine_d = $row["answer_nine_d"]; $question_ten = $row["question_ten"]; $question_ten_correct = $row["question_ten_correct"]; $answer_ten_a = $row["answer_ten_a"]; $answer_ten_b = $row["answer_ten_b"]; $answer_ten_c = $row["answer_ten_c"]; $answer_ten_d = $row["answer_ten_d"]; } echo "<form action=\"edit_reading.php\" method=\"post\"> <strong>Edit/Update Question</strong><br/> <table> <tr> <td> Paragraph One:<br/> <textarea name=\"paragraph_one\" cols=\"30\" rows=\"5\">" . $paragraph_one . "</textarea> </td> <td> Paragraph Two:<br/> <textarea name=\"paragraph_two\" cols=\"30\" rows=\"5\">" . $paragraph_two . "</textarea> </td> <td> Paragraph Three:<br/> <textarea name=\"paragraph_three\" cols=\"30\" rows=\"5\">" . $paragraph_three . "</textarea> </td> <td> Paragraph Four:<br/> <textarea name=\"paragraph_four\" cols=\"30\" rows=\"5\">" . $paragraph_four . "</textarea> </td> </tr> </table> <table> <tr> <td> Question One:<br/> <textarea name=\"question_one\" cols=\"20\" rows=\"2\">" . $question_one . "</textarea><br/> Option A:<br/> <input type=\"radio\" name=\"question_one_correct\" value=\"a\"> <input type=\"text\" name=\"answer_one_a\" value=\"" . $answer_one_a . "\"/><br/> Option B:<br/> <input type=\"radio\" name=\"question_one_correct\" value=\"b\"> <input type=\"text\" name=\"answer_one_b\" value=\"" . $answer_one_b . "\"/><br/> Option C:<br/> <input type=\"radio\" name=\"question_one_correct\" value=\"c\"> <input type=\"text\" name=\"answer_one_c\" value=\"" . $answer_one_c . "\"/><br/> Option D:<br/> <input type=\"radio\" name=\"question_one_correct\" value=\"d\"> <input type=\"text\" name=\"answer_one_d\" value=\"" . $answer_one_d . "\"/><br/> </td> <td> Question Two:<br/> <textarea name=\"question_two\" cols=\"20\" rows=\"2\">" . $question_two . "</textarea><br/> Option A:<br/> <input type=\"radio\" name=\"question_two_correct\" value=\"a\"> <input type=\"text\" name=\"answer_two_a\" value=\"" . $answer_two_a . "\"/><br/> Option B:<br/> <input type=\"radio\" name=\"question_two_correct\" value=\"b\"> <input type=\"text\" name=\"answer_two_b\" value=\"" . $answer_two_b . "\"/><br/> Option C:<br/> <input type=\"radio\" name=\"question_two_correct\" value=\"c\"> <input type=\"text\" name=\"answer_two_c\" value=\"" . $answer_two_c . "\"/><br/> Option D:<br/> <input type=\"radio\" name=\"question_two_correct\" value=\"d\"> <input type=\"text\" name=\"answer_two_d\" value=\"" . $answer_two_d . "\"/><br/> </td> <td> Question Three:<br/> <textarea name=\"question_three\" cols=\"20\" rows=\"2\">" . $question_three . "</textarea><br/> Option A:<br/> <input type=\"radio\" name=\"question_three_correct\" value=\"a\"> <input type=\"text\" name=\"answer_three_a\" value=\"" . $answer_three_a . "\"/><br/> Option B:<br/> <input type=\"radio\" name=\"question_three_correct\" value=\"b\"> <input type=\"text\" name=\"answer_three_b\" value=\"" . $answer_three_b . "\"/><br/> Option C:<br/> <input type=\"radio\" name=\"question_three_correct\" value=\"c\"> <input type=\"text\" name=\"answer_three_c\" value=\"" . $answer_three_c . "\"/><br/> Option D:<br/> <input type=\"radio\" name=\"question_three_correct\" value=\"d\"> <input type=\"text\" name=\"answer_three_d\" value=\"" . $answer_three_d . "\"/><br/> </td> <td> Question Four:<br/> <textarea name=\"question_four\" cols=\"20\" rows=\"2\">" . $question_four . "</textarea><br/> Option A:<br/> <input type=\"radio\" name=\"question_four_correct\" value=\"a\"> <input type=\"text\" name=\"answer_four_a\" value=\"" . $answer_four_a . "\"/><br/> Option B:<br/> <input type=\"radio\" name=\"question_four_correct\" value=\"b\"> <input type=\"text\" name=\"answer_four_b\" value=\"" . $answer_four_b . "\"/><br/> Option C:<br/> <input type=\"radio\" name=\"question_four_correct\" value=\"c\"> <input type=\"text\" name=\"answer_four_c\" value=\"" . $answer_four_c . "\"/><br/> Option D:<br/> <input type=\"radio\" name=\"question_four_correct\" value=\"d\"> <input type=\"text\" name=\"answer_four_d\" value=\"" . $answer_four_d . "\"/><br/> </td> <td> Question Five:<br/> <textarea name=\"question_five\" cols=\"20\" rows=\"2\">" . $question_five . "</textarea><br/> Option A:<br/> <input type=\"radio\" name=\"question_five_correct\" value=\"a\"> <input type=\"text\" name=\"answer_five_a\" value=\"" . $answer_five_a . "\"/><br/> Option B:<br/> <input type=\"radio\" name=\"question_five_correct\" value=\"b\"> <input type=\"text\" name=\"answer_five_b\" value=\"" . $answer_five_b . "\"/><br/> Option C:<br/> <input type=\"radio\" name=\"question_five_correct\" value=\"c\"> <input type=\"text\" name=\"answer_five_c\" value=\"" . $answer_five_c . "\"/><br/> Option D:<br/> <input type=\"radio\" name=\"question_five_correct\" value=\"d\"> <input type=\"text\" name=\"answer_five_d\" value=\"" . $answer_five_d . "\"/><br/> </td> </tr> <tr> <td> Question Six:<br/> <textarea name=\"question_six\" cols=\"20\" rows=\"2\">" . $question_six . "</textarea><br/> Option A:<br/> <input type=\"radio\" name=\"question_six_correct\" value=\"a\"> <input type=\"text\" name=\"answer_six_a\" value=\"" . $answer_six_a . "\"/><br/> Option B:<br/> <input type=\"radio\" name=\"question_six_correct\" value=\"b\"> <input type=\"text\" name=\"answer_six_b\" value=\"" . $answer_six_b . "\"/><br/> Option C:<br/> <input type=\"radio\" name=\"question_six_correct\" value=\"c\"> <input type=\"text\" name=\"answer_six_c\" value=\"" . $answer_six_c . "\"/><br/> Option D:<br/> <input type=\"radio\" name=\"question_six_correct\" value=\"d\"> <input type=\"text\" name=\"answer_six_d\" value=\"" . $answer_six_d . "\"/><br/> </td> <td> Question Seven:<br/> <textarea name=\"question_seven\" cols=\"20\" rows=\"2\">" . $question_seven . "</textarea><br/> Option A:<br/> <input type=\"radio\" name=\"question_seven_correct\" value=\"a\"> <input type=\"text\" name=\"answer_seven_a\" value=\"" . $answer_seven_a . "\"/><br/> Option B:<br/> <input type=\"radio\" name=\"question_seven_correct\" value=\"b\"> <input type=\"text\" name=\"answer_seven_b\" value=\"" . $answer_seven_b . "\"/><br/> Option C:<br/> <input type=\"radio\" name=\"question_seven_correct\" value=\"c\"> <input type=\"text\" name=\"answer_seven_c\" value=\"" . $answer_seven_c . "\"/><br/> Option D:<br/> <input type=\"radio\" name=\"question_seven_correct\" value=\"d\"> <input type=\"text\" name=\"answer_seven_d\" value=\"" . $answer_seven_d . "\"/><br/> </td> <td> Question Eight:<br/> <textarea name=\"question_eight\" cols=\"20\" rows=\"2\">" . $question_eight . "</textarea><br/> Option A:<br/> <input type=\"radio\" name=\"question_eight_correct\" value=\"a\"> <input type=\"text\" name=\"answer_eight_a\" value=\"" . $answer_eight_a . "\"/><br/> Option B:<br/> <input type=\"radio\" name=\"question_eight_correct\" value=\"b\"> <input type=\"text\" name=\"answer_eight_b\" value=\"" . $answer_eight_b . "\"/><br/> Option C:<br/> <input type=\"radio\" name=\"question_eight_correct\" value=\"c\"> <input type=\"text\" name=\"answer_eight_c\" value=\"" . $answer_eight_c . "\"/><br/> Option D:<br/> <input type=\"radio\" name=\"question_eight_correct\" value=\"d\"> <input type=\"text\" name=\"answer_eight_d\" value=\"" . $answer_eight_d . "\"/><br/> </td> <td> Question Nine:<br/> <textarea name=\"question_nine\" cols=\"20\" rows=\"2\">" . $question_nine . "</textarea><br/> Option A:<br/> <input type=\"radio\" name=\"question_nine_correct\" value=\"a\"> <input type=\"text\" name=\"answer_nine_a\" value=\"" . $answer_nine_a . "\"/><br/> Option B:<br/> <input type=\"radio\" name=\"question_nine_correct\" value=\"b\"> <input type=\"text\" name=\"answer_nine_b\" value=\"" . $answer_nine_b . "\"/><br/> Option C:<br/> <input type=\"radio\" name=\"question_nine_correct\" value=\"c\"> <input type=\"text\" name=\"answer_nine_c\" value=\"" . $answer_nine_c . "\"/><br/> Option D:<br/> <input type=\"radio\" name=\"question_nine_correct\" value=\"d\"> <input type=\"text\" name=\"answer_nine_d\" value=\"" . $answer_nine_d . "\"/><br/> </td> <td> Question Ten:<br/> <textarea name=\"question_ten\" cols=\"20\" rows=\"2\">" . $question_ten . "</textarea><br/> Option A:<br/> <input type=\"radio\" name=\"question_ten_correct\" value=\"a\"> <input type=\"text\" name=\"answer_ten_a\" value=\"" . $answer_ten_a . "\"/><br/> Option B:<br/> <input type=\"radio\" name=\"question_ten_correct\" value=\"b\"> <input type=\"text\" name=\"answer_ten_b\" value=\"" . $answer_ten_b . "\"/><br/> Option C:<br/> <input type=\"radio\" name=\"question_ten_correct\" value=\"c\"> <input type=\"text\" name=\"answer_ten_c\" value=\"" . $answer_ten_c . "\"/><br/> Option D:<br/> <input type=\"radio\" name=\"question_ten_correct\" value=\"d\"> <input type=\"text\" name=\"answer_ten_d\" value=\"" . $answer_ten_d . "\"/> </td> </tr> </table> <br/> <div id=\"center\"><button type=\"submit\" name=\"update\" value=\"" . $paragraph_one . "\">Update</button></div> </form>"; }
  3. Oh yay! It works now, thank you and I'll make sure to escape it as well
  4. I have been trying to create a page that gives administration the ability to add, edit and delete questions. Adding and editing work fine, and deleting does work, just not the way I want it to. Each row has an edit and delete button contained in a seperate form. My problem is that the delete button deletes everything in the table when I only want it to delete one row. I've tried putting all the buttons into a single form rather than seperate forms and a whole bunch of other things but nothing seems to work. Help? <?php session_start(); if(!isset($_SESSION['loggedin'])){ die("To access this page, you need to <a href=\"login.php\">login</a>."); } mysql_connect("", "", "") or die("Could not connect to database, please try again."); mysql_select_db("") or die("Could not connect to database, please try again."); $error_message = "There was an error, please <a href=\"edit_writing.php\">try again</a>."; $success_message = ""; if(isset($_POST["delete"])){ $a = $_POST["delete"]; mysql_query("DELETE FROM writing WHERE a=$a") or die($error_message); $success_message = "Question was deleted."; } if(isset($_POST["update"])){ $z = $_POST["update"]; $a = $_POST["a"]; $b = $_POST["b"]; $c = $_POST["c"]; $d = $_POST["d"]; $e = $_POST["e"]; if(!$a || !$b || !$c || !$d || !$e) { die("Please <a href=\"edit_writing.php\">try again</a> and ensure the form is completed properly."); } mysql_query("UPDATE writing SET a='$a', b='$b', c='$c', d='$d', e='$e' WHERE a='$z'") or die($error_message); $success_message = "Question was edited."; } if(isset($_POST["add"])){ $a = mysql_real_escape_string($_POST["a"]); $b = mysql_real_escape_string($_POST["b"]); $c = mysql_real_escape_string($_POST["c"]); $d = mysql_real_escape_string($_POST["d"]); $e = mysql_real_escape_string($_POST["e"]); if(!$a || !$b || !$c || !$d || !$e) { die("Please <a href=\"edit_writing.php\">try again</a> and ensure the form is completed properly."); } mysql_query("INSERT INTO writing (a, b, c, d, e) VALUES ('$a', '$b', '$c', '$d', '$e')") or die($error_message); $success_message = "Question was added."; } echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <title>Title</title> <link rel=\"stylesheet\" type=\"text/css\" href=\"css.css\" /> </head> <body> <div id=\"timer\"> </div> <div id=\"wrap\"> <div id=\"mainheader\"> </div> <div id=\"content\"> <div id=\"orangeheader\"><br/> Title </div> <div id=\"text\"> " . $success_message; if(isset($_POST["edit"])){ $a = $_POST["edit"]; $sql = mysql_query("SELECT * FROM writing WHERE a='$a'") or die($error_message); while($row = mysql_fetch_array($sql)){ $b = $row["b"]; $c = $row["c"]; $d = $row["d"]; $e = $row["e"]; } echo "<form action=\"edit_writing.php\" method=\"post\"> <table> <tr> <td><label for=\"a\">Question One</label></td> <td><label for=\"b\">Question Two</label></td> <td><label for=\"c\">Question Three</label></td> <td><label for=\"d\">Question Four</label></td> <td><label for=\"e\">Question Five</label></td> </tr> <tr> <td><input type=\"text\" name=\"a\" value=\"" . $a . "\" /></td> <td><input type=\"text\" name=\"b\" value=\"" . $b . "\" /></td> <td><input type=\"text\" name=\"c\" value=\"" . $c . "\" /></td> <td><input type=\"text\" name=\"d\" value=\"" . $d . "\" /></td> <td><input type=\"text\" name=\"e\" value=\"" . $e . "\" /></td> </tr> </table> <button type=\"submit\" name=\"update\" value=\"" . $a . "\">Update</button> </form>"; } echo "<table> <tr> <td><strong>Question One</strong></td> <td><strong>Question Two</strong></td> <td><strong>Question Three</strong></td> <td><strong>Question Four</strong></td> <td><strong>Question Five</strong></td> </tr>"; $result = mysql_query("SELECT * FROM writing"); $number = mysql_numrows($result); $counter = 0; while ($counter<$number){ $a = mysql_result($result, $counter,"a"); $b = mysql_result($result, $counter,"b"); $c = mysql_result($result, $counter,"c"); $d = mysql_result($result, $counter,"d"); $e = mysql_result($result, $counter,"e"); echo "<tr> <td>" . $a . "</td> <td>" . $b . "</td> <td>" . $c . "</td> <td>" . $d . "</td> <td>" . $e . "</td> <form action=\"edit_writing.php\" method=\"post\"> <td><button type=\"submit\" name=\"edit\" value=\"" . $a . "\">Edit</button></td> <td><button type=\"submit\" name=\"delete\" value=\"" . $a . "\">Delete</button></td> </form> </tr>"; $counter++; } ?> </table> <form action="edit_writing.php" method="post"> <table> <tr> <td><label for="a">Question One</label></td> <td><label for="b">Question Two</label></td> <td><label for="c">Question Three</label></td> <td><label for="d">Question Four</label></td> <td><label for="e">Question Five</label></td> </tr> <tr> <td><input type="text" name="a" /></td> <td><input type="text" name="b" /></td> <td><input type="text" name="c" /></td> <td><input type="text" name="d" /></td> <td><input type="text" name="e" /></td> </tr> </table> <input type="submit" name="add" value="Add Question"/> </form> </body> </html>
  5. Oh cool, I've never seen that before. How exactly would I use it? =/
  6. This code has options for adding and deleting data from a table. Adding data works, my problem arises when trying to echo out the current data with a delete button for each row. The data echos out fine, but the delete buttons do not work. Help? if(isset($_POST["add"])){ $a = mysql_real_escape_string($_POST["a"]); $b = mysql_real_escape_string($_POST["b"]); $c = mysql_real_escape_string($_POST["c"]); $d = mysql_real_escape_string($_POST["d"]); $e = mysql_real_escape_string($_POST["e"]); if(!$a || !$b || !$c || !$d || !$e) { die("Please <a href=\"edit_writing.php\">try again</a> and ensure the form is completed properly."); } mysql_query("INSERT INTO writing (a, b, c, d, e) VALUES ('$a', '$b', '$c', '$d', '$e')") or die($error_message); $success_message = "Question was added."; } echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <title>Title</title> <link rel=\"stylesheet\" type=\"text/css\" href=\"css.css\" /> </head> <body> <div id=\"timer\"> </div> <div id=\"wrap\"> <div id=\"mainheader\"> </div> <div id=\"content\"> <div id=\"orangeheader\"><br/> Grammar Test </div> <div id=\"text\"> " . $success_message . " <table> <tr> <td><strong>Question One</strong></td> <td><strong>Question Two</strong></td> <td><strong>Question Three</strong></td> <td><strong>Question Four</strong></td> <td><strong>Question Five</strong></td> </tr>"; $result = mysql_query("SELECT * FROM writing"); $number = mysql_numrows($result); $counter = 0; while ($counter<$number){ $a = mysql_result($result, $counter,"a"); $b = mysql_result($result, $counter,"b"); $c = mysql_result($result, $counter,"c"); $d = mysql_result($result, $counter,"d"); $e = mysql_result($result, $counter,"e"); echo "<tr> <td>" . $a . "</td> <td>" . $b . "</td> <td>" . $c . "</td> <td>" . $d . "</td> <td>" . $e . "</td> <td> <form action=\"edit_writing.php\" method=\"post\"> <input type=\"submit\" name=\"" . $counter . "\" value=\"Delete\"/> </form> </td> </tr>"; if(isset($_POST["$counter"])){ $a = mysql_real_escape_string($_POST["a"]); mysql_query("DELETE FROM writing WHERE question='$a'") or die($error_message); $success_message = "Question was deleted."; } $counter++; } ?> </table> <form action="edit_writing.php" method="post"> <table> <tr> <td><label for="a">Question One</label></td> <td><label for="b">Question Two</label></td> <td><label for="c">Question Three</label></td> <td><label for="d">Question Four</label></td> <td><label for="e">Question Five</label></td> </tr> <tr> <td><input type="text" name="a" /></td> <td><input type="text" name="b" /></td> <td><input type="text" name="c" /></td> <td><input type="text" name="d" /></td> <td><input type="text" name="e" /></td> </tr> </table> <input type="submit" name="add" value="Add Question"/> </form> </body> </html>
  7. This is my code, but it only outputs the first character of the data string... how can I fix it so that the entire data string is outputted? $question = $_SESSION["listening_question"]; $sql = mysql_query("SELECT * FROM listening WHERE question_one = '{$question}'") or die($error_message); while($row = mysql_fetch_array($sql)){ $paragraph_one = $row["paragraph_one"]; $i++; }
  8. Actually the problem only occurs when I try to echo it in PHP code. It works fine until there is PHP in the same document. Argghhh this is confusing me so much
  9. <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <title>Title</title> <script type="text/javascript"> var x=0; var y=10; function count() { y=y-1; document.getElementById('txt').innerHTML=x+":"+y; if (y<=0) { y=60; x=x-1; } if (y<10) { document.getElementById('txt').innerHTML=x+":0"+y; } if(x<5) { document.getElementById('txt').style.color = "#FF0000"; } if (x<0) { y=1; x=0; document.forms["myform"].submit(); } } setInterval('count()',1000); </script> </head> <body onload="count()"> <div id="txt"></div> <form id="myform" action="www.news.com.au" method="post"> </form> </body> </html> So that code works, but when I use the same code on a form with actual input boxes it doesn't. How can I fix this?
  10. Hmm, I changed it to the utf8_general_ci but it still didn't work... Thanks for the help though
  11. I changed the database character set/encoding thing to utf8-bin (there was no option for just utf8), but it hasn't solved anything :/ and now in the database it shows these: [bLOB - 46B] instead of the data.
  12. I've used php and mysql to populate this exam, and used " double quotations so that apostrophes won't cause trouble, however, as you can see in the image, random apostrophes come through as question marks with black diamonds while others on the page work normally... ANyone know why and how I can fix this?
  13. Nevermind... for some reason my head wasn't working very well, did it a different way than I wanted to but got the same result.
  14. How can I make it so that these both pull information from the same row, whilst still making sure the row chosen is random? Everything I have tried hasn't worked. *mysql database row... function vocabularyAnswers($table){ $$table = mysql_query('SELECT * FROM '.$table.' ORDER BY RAND()') or die(mysql_error()); $i = 0; $row = mysql_fetch_array($$table); $answer_a[$i] = $row['a']; $answer_b[$i] = $row['b']; $answer_c[$i] = $row['c']; $answer_d[$i] = $row['d']; $answer_e[$i] = $row['e']; echo "<option value=\"".$answer_a[$i]."\">".$answer_a[$i]."</option>"; echo "<option value=\"".$answer_b[$i]."\">".$answer_b[$i]."</option>"; echo "<option value=\"".$answer_c[$i]."\">".$answer_c[$i]."</option>"; echo "<option value=\"".$answer_d[$i]."\">".$answer_d[$i]."</option>"; echo "<option value=\"".$answer_e[$i]."\">".$answer_e[$i]."</option>"; $i++; } function vocabularyQuestions($table){ $$table = mysql_query('SELECT * FROM '.$table.' ORDER BY RAND()') or die(mysql_error()); $i = 0; while($row = mysql_fetch_array($$table)){ $question_a[$i] = $row['a']; $question_b[$i] = $row['b']; $question_c[$i] = $row['c']; $question_d[$i] = $row['d']; $question_e[$i] = $row['e']; $i++; } echo "<input type=\"hidden\" name=\""; echo $table; echo "_q0\" value=\""; echo $question_a[0]; echo "\">"; echo "<input type=\"hidden\" name=\""; echo $table; echo "_q1\" value=\""; echo $question_a[1]; echo "\">"; echo "<tr><td>"; echo $question_a[0]; echo " / "; echo $question_b[0]; echo " / "; echo $question_c[0]; echo " / "; echo $question_d[0]; echo " / "; echo $question_e[0]; echo "</td><td><select name=\""; echo $table; echo "_a0\">"; echo "<option value=\"0\">Please select an answer...</option>"; vocabularyAnswers($table); echo "</select></td></tr><tr><td>"; echo $question_a[1]; echo " / "; echo $question_b[1]; echo " / "; echo $question_c[1]; echo " / "; echo $question_d[1]; echo " / "; echo $question_e[1]; echo "</td><td><select name=\""; echo $table; echo "_a1\">"; echo "<option value=\"0\">Please select an answer...</option>"; vocabularyAnswers($table); echo "</select></td></tr>"; }
  15. Lol, I'm still learning what I can and can't do syntax wise thanks for the help! I took the function outside and its perfect.
  16. I don't really understand what you mean.. I can't see where the function is in a while loop? I'm probably blind...
  17. *I've removed the echo commands from before options(); but that hasn't fixed it..
  18. Hey guys, I'm having some trouble with this function (well, the function within the function really). I need the function to echo out a random question from the designated table, this is working fine, but then I need a function within this function to pull out all the answer options and echo them into a dropdown menu. The dropdown menu shows, but there is no data found within it, although there is definitely data contained in the table. I keep getting the error "Fatal error: Cannot redeclare options()". I've attempted to also do it using mysql_num_rows but that didn't work so I thought I would try something simpler... Here's the code: function retrieveData($data){ $$data = mysql_query('SELECT * FROM '.$data.' ORDER BY RAND()') or die(mysql_error()); $counter = 0; while($row = mysql_fetch_array($$data)){ $question[$counter] = $row['question']; $counter++; } function options($data){ $i = 0; while($row = mysql_fetch_array($$data)){ $answer[$i] = $row['answer']; $i++; } echo "<option value=\"".$answer[$i]."\">".$answer[$i]."</option>"; } echo $question[0]; echo "<select name=\"0\">"; echo "<option value=\"0\">Please select an answer...</option>"; echo options(); echo "</select>"; echo "<br/>"; echo $question[1]; echo "<select name=\"1\">"; echo "<option value=\"0\">Please select an answer...</option>"; echo options(); echo "</select>"; echo "<br/>"; } Any help would be awesome
  19. My brain hurts.. I've been trying to find a tutorial or something to teach me how to create a Javascript timer (I don't know much Javascript at all, I tend to despise it for most things but I can't avoid it for this project), but I can't find what I'm looking for. Basically, I'm creating an online exam, which requires a visible countdown timer that begins at 45min with an alert at 15min and another alert at 5min. Once the timer is finished I need the page to automatically send the form and move onto the next section of the exam, or if the user moves onto the next part of the exam before the timer finishes I need to take note of how much time they spent on that section. Could someone please point me to either a code generator, tutorial or help me get it started?
  20. I'm currently constructing an online exam which requires a timer, and when the timer is finished it needs to submit the form on the current page and move to the next page, without allowing the user to go backwards... wondering if this is possible in PHP and if so where should I start? I've been trying to figure this out for a few hours and have done quite a bit of research and attempted a few things, but the only conclusion I can come to is that I will have to use JavaScript, but I would prefer to do it in PHP if it is possible.
  21. Ohh, I was able to do it a better way and now its working, thank you! =)
  22. But if I run that function multiple times with a different argument, I won't be able to use the variables I'm creating inside it because it will change each time... Its not in the code that I've posted but I've declared them as global variables... the reason I used variable variables is because if I run organise ('ABC'); I need to be able to use $ABC_ROW later on...
  23. I'm writing a function that will gather and organise data into an array. For some reason I keep getting "syntax error, unexpected '=' " when testing it... function organise($d){ while($$d._ROW = mysql_fetch_array($$d)){ $$d._START[$$d._COUNTER] = $$d._ROW['start']; $$d._END[$$d._COUNTER] = $$d._ROW['end']; $$d._ANSWER[$$d._COUNTER] = $$d._ROW['answer']; $$d._COUNTER++; } }
  24. Don't worry... my database was all screwed up. Thanks for the help though.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.