PHP - Moved: Quiz Script Integrated With An Existing Template
This topic has been moved to Third Party PHP Scripts.
http://www.phpfreaks.com/forums/index.php?topic=315539.0 Similar TutorialsThis topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=315590.0 I'm trying to use this script known as SimpleImage.php that can be found here <a href="http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php">link</a> I'm trying to include what is on the bottom of the page to my existing script can anyone help me I've tried several ways but its not working. Code: [Select] <?php session_start(); error_reporting(E_ALL); ini_set('display_errors','On'); //error_reporting(E_ALL); // image upload folder $image_folder = 'images/classified/'; // fieldnames in form $all_file_fields = array('image1', 'image2' ,'image3', 'image4'); // allowed filetypes $file_types = array('jpg','gif','png'); // max filesize 5mb $max_size = 5000000; //echo'<pre>';print_r($_FILES);exit; $time = time(); $count = 1; foreach($all_file_fields as $fieldname){ if($_FILES[$fieldname]['name'] != ''){ $type = substr($_FILES[$fieldname]['name'], -3, 3); // check filetype if(in_array(strtolower($type), $file_types)){ //check filesize if($_FILES[$fieldname]['size']>$max_size){ $error = "File too big. Max filesize is ".$max_size." MB"; }else{ // new filename $filename = str_replace(' ','',$myusername).'_'.$time.'_'.$count.'.'.$type; // move/upload file $target_path = $image_folder.basename($filename); move_uploaded_file($_FILES[$fieldname]['tmp_name'], $target_path); //save array with filenames $images[$count] = $image_folder.$filename; $count = $count+1; }//end if }else{ $error = "Please use jpg, gif, png files"; }//end if }//end if }//end foreach if($error != ''){ echo $error; }else{ /* -------------------------------------------------------------------------------------------------- SAVE TO DATABASE ------------------------------------------------------------------------------------ -------------------------------------------------------------------------------------------------- */ ?> Hi, My name is Karel van der Veen. I am trying to creat a script for a quiz on my website but I am stuck. I was hoping you might have an idea for the solution. The idea is a page with a picture and multiple choice questions about that picture. For example a picture of a bike. Question 1: what colour is the bike? --> choices are green, red, blue. Question 2: what shape are the wheels? --> round, square. I have made a script that compares the answers given by the student, with the correct answers I put in the database corresponding with the bike on the picture. If the student has it right, than after clicking on "next", the "correct answer" page will load. If he made a mistake a "wrong answer" page will load. So far the script works. But what I would like to happen is if the student gives a wrong answer, that after clicking on the `next` button, he will go back to the front page where the picture and the questions are with a sign or mark around the question he answered wrong, so he knows what question he had wrong and has to answer again. Below is the script I have so far. Do you know what I have to change or to add to the script? regards Karel Code: [Select] script of the question page: <?php $array_vorm = Array("rond","vierkant"); $array_kleur= array("rood","blauw","groen"); $array_grootte = array("4x4","8x8"); ?> <form method="post" action="results.php"><br /> <div id="vorm"> <div id="vorm1"><img src="images/vorm.gif" alt="vorm" width="75" height="75" class="vorms" /></div> <div id="vorm2"> <table> <tr><td> <label class="vormhead">VORM</label><br> <select name="form_vorm[]" class="randmenu" size="4" multiple > <option><?php echo implode("</option><option>",$array_vorm); ?></option> </select> </td></tr> </table> </div> </div> <div id="kleur"> <div id="kleur1"><img src="images/kleur.gif" alt="vorm" width="75" height="75" class="kleur" /></div> <div id="kleur2"> <table> <tr><td> <label class="kleurhead">KLEUR</label><br> <select name="form_kleur[]" class="randmenu" size="4" multiple > <option><?php echo implode("</option><option>",$array_kleur); ?></option> </select> </td></tr> </table> </div> </div> <div id="grootte"> <div id=" grootte 1"><img src="images/ grootte .gif" alt="vorm" width="75" height="75" class=" grootte " /></div> <div id=" grootte2"> <table> <tr><td> <label class=" grootte head">GROOTTE</label><br> <select name="form_ grootte []" class="randmenu" size="4" multiple > <option><?php echo implode("</option><option>",$array_ grootte ); ?></option> </select> </td></tr> </table> </div> </div> <input type="submit" class="zoekbalk" value="zoeken" /> And this is the script of the result page: <?php error_reporting ( E_ALL | E_STRICT ); ini_set ( 'display_errors', 1 ); ?> <?php include 'connect.php'; ?> <?php $geenbeschrijving = "De beschrijving is onjuist. $geenselectie = "Je hebt geen selectie gemaakt, maak eerst een selectie en klik dan op zoeken. <br/><br/> $antwoord = "Antwoord: "; $diagnose = "Beschrijving: "; $diagnose2 = "Diagnose: "; $vormeggo = "Vorm: "; $kleureggo = "Kleur: "; $grootteeggo = "Grootte: "; $array_vorm = array("rond","vierkant"); $array_kleur= array("rood","blauw","groen"); $array_grootte = array("4x4","8x8"); if($_SERVER['REQUEST_METHOD'] == 'POST' ) { $query = "select * from foto1 where "; $query_init = $query; $first_option = true; if (isset($_POST["form_vorm"])){ if ($first_option == false){ $query .= " AND "; } else{ $first_option = false; } $query .= "("; for ($i=0; $i<=count($_POST["form_vorm"])-1; $i++){ if ($i == 0){ $query .= "(vorm LIKE '%".$_POST["form_vorm"][$i]."%') "; }else{ $query .= " OR (vorm LIKE '%".$_POST["form_vorm"][$i]."%') "; } } $query .= ")"; } if (isset($_POST["form_ kleur "])){ if ($first_option == false){ $query .= " AND "; } else{ $first_option = false; } $query .= "("; for ($i=0; $i<=count($_POST["form_ kleur "])-1; $i++){ if ($i == 0){ $query .= "( kleur LIKE '%".$_POST["form_ kleur "][$i]."%') "; }else{ $query .= " AND (kleur LIKE '%".$_POST["form_ kleur "][$i]."%') "; } } $query .= ")"; } if (isset($_POST["form_ grootte "])){ if ($first_option == false){ $query .= " AND "; } else{ $first_option = false; } $query .= "("; for ($i=0; $i<=count($_POST["form_ grootte "])-1; $i++){ if ($i == 0){ $query .= "( grootte LIKE '%".$_POST["form_ grootte "][$i]."%') "; }else{ $query .= " AND (grootte LIKE '%".$_POST["form_ grootte "][$i]."%') "; } } $query .= ")"; } if ($query == $query_init){ echo "<div class=\"geenbeschrijving\">" . $geenselectie . "</div>"; }else{ //echo $query."<br><br>"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)<>0) { while ( $row = mysql_fetch_assoc ( $result ) ) { echo "<div class=\"beschrijving\">" . $antwoord . "</div>"; echo "<div class=\"keuze\">" . $vormeggo . $row["VORM"]. "</div>"; echo "<div class=\"keuze2\">" . $kleureggo . $row["KLEUR"]. "</div>"; echo "<div class=\"keuze2\">" . $grootteeggo . $row["GROOTTE"]. "</div>"; </div>"; $beschrijvingquery = "select BESCHRIJVING from beschrijving where Catalog_ID=".$row["ID"]; if ($beschrijvingresult = mysql_query($beschrijvingquery)) { if (mysql_num_rows($beschrijvingresult)<>0) { while ( $beschrijvingrow = mysql_fetch_assoc ( $beschrijvingresult ) ) { echo "<div class=\"beschrijving\">" . $diagnose . "</div>"; echo "<div class=\"beschrijving2\">" . $beschrijvingrow["BESCHRIJVING"]."</div></br>"; } } else { echo "geen beschrijving<br />"; } } $diagnosequery = "select DIAGNOSE from diagnose where Catalog_ID=".$row["ID"]; if ($diagnoseresult = mysql_query($diagnosequery)) { if (mysql_num_rows($diagnoseresult)<>0) { while ( $diagnoserow = mysql_fetch_assoc ( $diagnoseresult ) ) { echo "<div class=\"beschrijving\">" . $diagnose2 . "</div>"; echo "<div class=\"beschrijving2\">".$diagnoserow["DIAGNOSE"]."<br /><br />"; } } else { echo "geen beschrijving<br />"; } } $fotoquery = "select FOTOthumb, FOTObig from foto where Catalog_ID=".$row["ID"]; if ($fotoresult = mysql_query($fotoquery)) { if (mysql_num_rows($fotoresult)<>0) { while ( $fotorow = mysql_fetch_assoc ( $fotoresult ) ) { echo "<div class=\"beschrijving4\">" .'<a title="' . $fotorow['FOTObig'] . '" href="images/big/' . $fotorow['FOTObig'] . '" rel="lightbox"><img src="images/thumb/' . $fotorow['FOTOthumb'] . '"></a></br></br><hr><hr> '; } } else { echo "<img src='geenfoto.jpg' alt='geen foto' /><br />"; } } } } else { echo "<div class=\"geenhuidaandoeningen\">" . $geenhuidaandoeningen . "</div>"; } } } } ?> He, I am builing some kind of quiz script. I got 10 images people see and they have to say if they agree or not. Simply by clicking yes / no. First i used a submit button, but now i want it to submit whem people click yes/no. tried some stuff already but cant find the correct way. Please help here is the code: <?php session_start(); $thispage = 'test.php'; $img = array( '1','2','3','4','5','6','7','8','9','10' ); function getQuestion( $q ) { global $img; $curImg = $img[$q]; return "Do you agree? <br> <img src=\"images/{$curImg}.jpg\">"; } if ( isset( $_GET['reset'] ) ) { unset( $_SESSION['q'] ); unset( $_SESSION['answer'] ); header("Location: {$thispage}"); } if ( !isset( $_SESSION['q'] ) ) { $_SESSION['q'] = 0; } if ( !isset( $_SESSION['answer'] ) ) { $_SESSION['answer'] = array(); } if ( isset( $_POST['answer'] ) ) { $answer = $_POST['submit']; if ( $answer == '1' || $answer == '2' ) { $next = $_SESSION['q'] + 1 ; if ( array_key_exists( $next,$img ) ) { $_SESSION['answer'][$_SESSION['q']] = $answer; } $_SESSION['q'] = $next ; } } if ( $_SESSION['q'] >= count( $img ) ) { $html = ''; foreach( $_SESSION['answer'] as $q => $value ) { $html .= getQuestion( $q ) . " Answer: {$value}<br />"; } $html .= "<br /><br /><a href=\"{$thispage}?reset=Y\">Reset Quiz</a>"; } else { $question = getQuestion( $_SESSION['q'] ); $html =<<<HTML <html> <body> <h1>{$question}</h1> <input type="submit" value="Yes" name="answer" />Yes<br /> <input type="submit" value="No" name="answer" />No<br /> </form> </body> </html> HTML; } echo $html; ?> Hello All! I was hoping one of you phpFreaks could help me out I have the following code that produces links from a database. Certain sets of results have over 3000 links. I can currently set the amount of links to display per page but that's it. I would like to be able to truncate the links to all the pages using pagination. Any help would be greatly appreciated! Here is the code: <?php echo "Results<br><HR WIDTH=100% SIZE=1><br>"; mysql_connect("mysite.com", "mysite_mysite", "mysitepassword") or die(mysql_error()); mysql_select_db("user_database") or die(mysql_error()); if (isset($_GET['pagenum'])) { $pagenum = $_GET['pagenum']; } else { $pagenum = 1; } $rpg = $pagenum; $data = mysql_query("SELECT * FROM mydb WHERE mfg='golf'") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 80; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM mydb WHERE mfg='golf' $max") or die(mysql_error()); while($info = mysql_fetch_array( $data_p )) { $page=$info['link']; echo "<a href='$page' class='blue1'>". $info['title'] . "</a><br>"; } echo "<p>"; if ($pagenum > $last) {$pagenum=1;} else { echo "<HR WIDTH=100% SIZE=1><br>"; $pagenum = 1; while ($pagenum <= $last) { $next = $pagenum; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next' class='g5'>$pagenum</a> "; $pagenum = $pagenum+1; } Echo "<br><br>Page $rpg of $last <br>"; } ?> Simple insertion of pagination would be GREAT! Thanks guys.... Hello Everyone, I've successfully created a form script to check to make sure all my fields are filled out. However, I wanted to create an if statement to check and see if the email address is valid and it contains both and "@", "." symbols. If not then echo '' This is not a Valid email address " if its not correct. Could someone tell me the proper way to write this and incorporate this into my existing script below. Thank you all Again for your Help thanks mrjap1 Code: [Select] // Confirm All feild were filled out when submit button was pressed if($name && $email && $username && $password && $confirm_password) { // Confirm that the NAME that you used is NOT greater than 30 characters if(strlen($name)>24) { echo "<h2><center>YOUR NAME IS TOO LONG!!!!</center></h2><br>"; } // Confirm that the EMAIL that you used is NOT greater than 25 characters if(strlen($email)>25) { echo "<h2><center>YOUR EMAIL IS TOO LONG!!!!</center></h2><br>"; } // Confirm that the USERNAME that you used is NOT greater than 10 characters if(strlen($username)>10) { echo "<h2><center>YOUR USERNAME IS TOO LONG!!!!</center></h2><br>"; } else { // Confirm that the PASSWORD that you used MATCH & Between 6 and 15 characters if(strlen($password)>10 || strlen($password)<6) { echo "<h2><center>YOUR PASSWORD MUST BE BETWEEN 6 and 15 CHARACTERS!!!!</center></h2><br>"; } if($password == $confirm_password) {
Hello! I found this code from github. https://github.com/gburtini/Learning-Library-for-PHP and I want to know if its possible to add variables to it and what changes needed to be done to the whole script. $xs and $ys I want replace them and add two more. The whole code is he <?php require_once 'function.php'; function ll_nn_predict($xs, $ys, $row, $k) { $distances = ll_nearestNeighbors($xs, $row); $distances = array_slice($distances, 0, $k); $predictions = array(); foreach($distances as $neighbor=>$distance) { $predictions[$ys[$neighbor]]++; } asort($predictions); return $predictions; } function ll_nearestNeighbors($xs, $row) { $testPoint = $xs[$row]; $distances = _ll_distances_to_point($xs, $testPoint); return $distances; } function _ll_distances_to_point($xs, $x) { $distances = array(); foreach($xs as $index=>$xi) { $distances[$index] = ll_euclidean_distance($xi, $x); } asort($distances); array_shift($distances); return $distances; } and the function.php that is required is this: <?php function ll_transpose($rows) { $columns = array(); for($i=0;$i<count($rows);$i++) { for($k = 0; $k<count($rows[$i]); $k++) { $columns[$k][$i] = $rows[$i][$k]; } } return $columns; } function ll_mean($array) { return array_sum($array)/($array); } function ll_variance($array) { $mean = ll_mean($array); $sum_difference = 0; $n = count($array); for($i=0; $i<$n; $i++) { $sum_difference += pow(($array[$i] - $mean),2); } $variance = $sum_difference / $n; return $variance; } function ll_euclidean_distance($a, $b) { if(count($a) != count($b)) return false; $distance = 0; for($i=0;$i<count($a);$i++) { $distance += pow($a[$i] - $b[$i], 2); } return sqrt($distance); } I just want to know where is the variables in those 2 scripts and add more as I'm not well versed in using PHP. Thank you! This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358003.0 This topic has been moved to Editor Help (Dreamweaver, Zend, etc). http://www.phpfreaks.com/forums/index.php?topic=306796.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=348130.0 I'm trying to get my php form to send a simple auto responder to the persons email that submitted the form. Something like "Thanks we received your info". I don't know how to integrate that into my existing script. Below are the configurable parts of the php. The form works perfectly ... just want to add the auto respond function. Thanks! _________________________________________________ _________________________________________________ _____ <?php $d = date("m-d-y H:i:s"); /* ************* Begin Configuration ************* */ $relocate = "http://www.xxxxx.com/"; // insert your relocation url here $home = "http://www.xxxxx.com/"; $MOVE_TO_PATH = '/home/content/xxxxx/html/FileUpload/'; $PATH_TO_DIR = 'http://www.xxxxx.com/FileUpload/'; $sender_name = "Order"; $sender_email = "me@xxxxx.com"; $mailheaders = "Content-Type: text/plain; charset=us-ascii\nFrom: $sender_name <$sender_email>\nReply-To: <$sender_email>\nReturn-Path: <$sender_email>\nX-Mailer: PHP"; //$to = "me@xxxxx.com"; $to = "me@xxxxx.com"; $subject = "Order"; $success_block = "<p>Thank you for submitting your information. We will review your information and get back to you within a day or two.</p><br><br>"; /* ************* End Configuration ************* */ if ($send != "false") { mail($to, $subject, $msg, $mailheaders); // mail sent to admin header("Location: $relocate"); } ?> I am pretty new to using php and mysql and am struggling to understand how to go about processing a multiple choice quiz script to check if the answer given by the user is right or wrong and give the user the final result . I understand how to write and process register pages and login scripts and the like but for some reason I just can't understand what i need to do for this type of script So far my thinking has been 1) When the page is submitted have a query that compares the answer selected to the answer in the database. 2) Have php variables for correct and and incorrect both initialised to 0 and which will change depending on the answers given. 3) Use an if else statement similar to the code below to add up the score : - if($result['answer']==$_POST[$result['id']]){ $correct_answer++; }else{ $incorrect_answer++; } 4) Have a query that enters the person taking the quiz's grade in to the database. I would really appreciate it someone could give me some guidance for the best way to do this. I have included below my code for selecting the questions form the database. <?php // Starts the session session_start(); /* */ if (!isset($_SESSION['user_level']) or ($_SESSION['user_level'] != 0)) { header("Location: error_page.php"); exit(); } ?> <?php require_once ('mysqli_connect.php'); $email_address = ['email_address']; $quizGradeBegan=("INSERT INTO learner_grade_db( email_address, score, )VALUES ('$email_address',0) "); $result=@mysqli_query($dbcon, $submittedAnswerQuery); if(isset($_SESSION['email_address'])){ ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Q-Quiz: Learner Homepage</title> <link rel="stylesheet" href="sdnt.css" /> </head> <body> <div class="wrapper"> <!-- Start of wrapper div --> <div class="header"> <!-- Start of header div --> <h1>e-Quiz: <br> Learner Homepage</h1> <?php //Makes a call to includes/leaner_nav.php in order to show The Learner Navigation Bar require_once("includes/learner_nav.php"); //Makes a call to includes/welcome_name.php in order to show the Learners name. require_once("includes/welcome_name.php"); /*Makes a call to includes/current_date in order to shows the current date. Will appear in the Day Month Year Format.*/ require_once("includes/current_date.php"); ?> <!-- Shows the Change text size images --> <div id="textSizer"><!-- Start of the textSizer div --> <img id="smallStyler" class="textSize" src="imgs/fontSmall.jpg" height="18" width="18" alt="Smallest" /> <img id="mediumStyler" class="textSize" src="imgs/fontMedium.jpg" height="18" width="18" alt="Default" /> <img id="largeStyler" class="textSize" src="imgs/fontLarge.jpg" height="18" width="18" alt="Biggest" /> </div> <!-- End of textsizer div --> </div><!-- End of Header div --> <div class="article"> <!-- Start of the article div --> <?php $query=("SELECT question_id, question, distractor_1, distractor_2, distractor_3, distractor_4 FROM multiplechoice_db ORDER BY RAND() LIMIT 3 " ); $result = @mysqli_query ($dbcon, $query); // Run the query. while($row = mysqli_fetch_array($result, MYSQL_BOTH)):?> <br> <form action="gradepage.php" method="post"> <?php echo $row['question_id'];?> <br> <?php echo $row['question'];?> <br> <input type="radio" value="1" id=' distractor <?php echo $row['question_id'];?>' name ='<?php echo $row['question_id'];?>'/><?php echo $row['distractor_1'];?> <br> <input type="radio" value="2" id=' distractor <?php echo $row['question_id'];?>' name ='<?php echo $row['question_id'];?>'/><?php echo $row['distractor_2'];?> <br> <input type="radio" value="3" id=' distractor <?php echo $row['question_id'];?>' name ='<?php echo $row['question_id'];?>'/><?php echo $row['distractor_3'];?> <br> <input type="radio" value="4" id=' distractor <?php echo $row['question_id'];?>' name ='<?php echo $row['question_id'];?>'/><?php echo $row['distractor_4'];?> <br> <?php endwhile;?> <p> <input id="submit" type="submit" name="submit" value="Click To Submit Completed Quiz "></> </div> <!-- End of the article div --> <div class="aside"> <!-- Start of the aside div --> <ul class="nav2"> <?php //Makes a call to includes/leanersidebar1.php in order to show The Learner Sidebar require_once("includes/learnersidebar1.php"); ?> </ul> <br><br><br><br><br> </div> <!-- End of the aside div --> <div class="footer "><!-- Start of the footer div --> <?php //Makes a call to includes/footer.php in order to show the Footer require_once("includes/footer.php"); ?> </div><!-- End of the footer div --> </div><!-- End of the wrapper div --> </body> <html> I get this response when I try to install Download Courier Deprixa Pro v3.2.6.2 – Integrated Web System on my website; Warning: Cannot modify header information - headers already sent by (output started at /home/speedora/public_html/Tracking/setup/index.php:68) in /home/speedora/public_html/Tracking/setup/index.php on line 71. Please I really need help with this This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=347856.0 Hi there, I purchased an admin template, and I've been trying to implement my existing login php script into their template. Their template is AJAX based, but with some PHP mixed in, so let me know if you feel I should re-post it under the AJAX category. I've attached the template file "login_template.php", as well as a page with just my regular login script on it "login_standard.php", if anyone could assist me in making the two of them work together, and explain to me what you did (for my own future reference/education), it would be greatly appreciated! Thanks in advance, Eric [attachment deleted by admin] This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=321218.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=317600.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=349834.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=359002.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358619.0 |