PHP - One Question Shared Answers (issue)
Ok here it is, seems like it is an easy problem but my developers are having some issue with this, I hope you guys can help.
Basic question and answer problem, where I am developing a website that uses Items and questions like " How many of this Item do you need?" the answer seems to simple. Lets say the answer Is "1". The display is given to the Item list and we move on. Here is the Problem: When selecting Muiltiple Items in the List and they all have the same question associated to each Item: "How Many Items do you need?" the the answer is shared between the Items, Again, sounds simple so far, However, when the USER selects Multiple Items on a list say 30 Items then the Question should only be dispalyed one time, not 30 times, then the answer is shared 30 times. Thats what I have now being displayed on my website, 30 of the same questions over and over again. The USER will get frustrated and leave the site never to return. Question: How can I get the Question to be displayed only once, but shared between several items on a list? This is a very serious problem fo my website because I will have not have just one Item on a list but 300 to 400 items, and if I get the answer to the problem I have just wasted 1 year of my life developing something undevelopable (is that a word?). Any Help you can give me would greatly be appricated. Thank you in advance. Similar Tutorials
Not experienced coding PHP and need help doing something which is probably very easy but looks like Mt Everest to me. FOO = 123456 BAR = abc Then, write URLs with those variables and have them work the same in a browser:
http://webpage1.com/?var1=FOO&var2=BAR
http://webpage2.com/?var1=FOO&var2=BAR
http://webpage3.com/?var1=FOO&var2=BAR If I update the fields in my local webpage and refresh browser, would like the new value(s) to be used instead. Any help with this greatly appreciated. If someone will put a file together think that I can edit and modify from there for my specific application. Thank you. Edited December 1, 2020 by XcloneHello - I have usually run my own servers, and always drop my .php files with MYSQL connection strings in a directory like /var, with webroot being /var/www/mysite. I now find myself in a shared hosting environment for a client and wondering the safety of my connection string .php files. Unfortunately they are sitting in a folder in the root of my hosting directory right now, and they feel vulnerable. It seems the only thing I could do would be to put the root of my hosting into a subdirectory, point the site there, and then put my connection strings on directory back. But seems the problem is they are still in my shared hosting. What's the best way to secure this type of sensitive info in a shared environment? I'm also getting ready to explore credit card processing via an API, and wondering if shared hosting is even worth it. Thanks!! Right now my application only displays the answers and problems when the user hits the score button. But when the user hits the score button I want my application to only display the problems that the user got wrong in the test. Here is my code for this applicaiton.. it is small and simple, just not sure how to do this? Code: [Select] <!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>Lab 5</title> </head> <body> <?php define ('ROWS', 3); define ('COLS', 3); define ('MAX_NUMBER', 12); date_default_timezone_set('America/New_York'); if (isset($_POST['btn_score'])) { //print_r ($_POST); $time1 = $_POST['ts']; $time1_object = new DateTime($time1); $now = new DateTime(); $time_span = $now->diff($time1_object); $minutes = $time_span->format('%i'); $seconds = $time_span->format('%s'); $seconds+= $minutes * 60; echo "It took $seconds seconds to complete the test<hr />"; foreach ($_POST as $problem => $answer) { if ($problem <> "btn_score" && $problem <> "ts") { //echo "$problem -- $answer <br />"; $problem = explode('_', $problem); $num1 = $problem[2]; $num2 = $problem[3]; echo "$num1 * $num2 === $answer <br />"; } } } ?> <h1>Lab 5</h1> <form name="lab5" method="post" action="lab5b.php"> <?php $now = new DateTime(); //echo $now->format('Y-m-d H:i:s'); echo "<input type='hidden' name='ts' value='" . $now->format('Y-m-d H:i:s') . "'>"; ?> <table border="1" cellspacing="5" cellpadding="5"> <?php $no_of_problems = 0; for ($row=0; $row<ROWS; $row++) { echo "<tr>"; for ($col=0; $col<COLS; $col++) { $num1 = mt_rand(1,MAX_NUMBER); $num2 = mt_rand(1,MAX_NUMBER); echo "<td>$num1 * $num2 </td>"; echo "<td><input type='text' size='2' name=${no_of_problems}_mult_${num1}_${num2}></td>"; $no_of_problems++; } echo "</tr>"; } $colspan = 2 * COLS; echo "<tr><td colspan=$colspan align='right'><input type='submit' value='Score' name='btn_score'></td></tr>"; ?> </table> </form> </body> </html> On my application there is 10 math questions. What I want to do when the test is finished is for it to tell the user how many they got right out of 10. Also how to put this into the database. I have everything else working fine on this application, I just would like to further enhance it by doing this. This is the code to my application. It is a small application. Code: [Select] <!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>Multiplication Test</title> </head> <body> </body> <?php require_once('database.php'); session_start(); define ('ROWS', 2); define ('COLS', 5); define ('MAX_NUMBER', 12); date_default_timezone_set('America/New_York'); if (isset($_POST['btn_score'])) { $result_name= $_POST['result_name']; $correct = 0; //print_r ($_POST); $time1 = $_POST['ts']; $time1_object = new DateTime($time1); $now = new DateTime(); $time_span = $now->diff($time1_object); $minutes = $time_span->format('%i'); $seconds = $time_span->format('%s'); $seconds+= $minutes * 60; echo "It took $seconds seconds to complete the test<hr />"; foreach ($_POST as $problem => $answer) { if ($problem <> "btn_score" && $problem <> "ts" && $problem <> "result_name") { //echo "$problem -- $answer <br />"; $problem = explode('_', $problem); $num1 = $problem[2]; $num2 = $problem[3]; $right = $num1 * $num2; if ($answer != $right) { echo "$num1 * $num2 = $answer , The right answer is $right<br />"; }else { $correct = $correct + 1; } } } $result_score= 0; $result_score= ($correct / 10) * 100; echo "your score is <br/>$result_score<br/>"; } { $sql = "INSERT INTO results (result_name, result_score, result_date_time) VALUES ('$result_name','$result_score', NOW());"; $db->exec($sql); } $query = "SELECT * FROM results WHERE result_name = :result_name "; $statement = $db->prepare($query); $statement->bindValue (':result_name', $result_name); $statement->execute(); $results = $statement->fetchAll(); $statement->closeCursor(); echo "<h1>Show Grades for $result_name </h1>"; foreach ($results as $result) { echo $result['result_name'] . " " . $result['result_score']. " " . $result['result_date_time']; echo '<br />'; } ?> <h1>Multiplication Test</h1> <form name="lab5" method="post" action="lab5b.php"> <?php $now = new DateTime(); //echo $now->format('Y-m-d H:i:s'); echo "<input type='hidden' name='ts' value='" . $now->format('Y-m-d H:i:s') . "'>"; ?> <table border="1" cellspacing="5" cellpadding="5"> <?php $no_of_problems = 0; for ($row=0; $row<ROWS; $row++) { echo "<tr>"; for ($col=0; $col<COLS; $col++) { $num1 = mt_rand(1,MAX_NUMBER); $num2 = mt_rand(1,MAX_NUMBER); echo "<td>$num1 * $num2 </td>"; echo "<td><input type='text' size='2' name=${no_of_problems}_mult_${num1}_${num2}></td>"; $no_of_problems++; } echo "</tr>"; } $colspan = 2 * COLS; echo "<tr><td colspan=$colspan align='right'><input type='submit' value='Score' name='btn_score'></td></tr>"; ?> </table> <br> <br> <label for="result_name">Student Name:</label> <input type="text" id="result_name" name="result_name" /><br /> </form> <br> <br> </body> </html> I am on a shared hosting server running CentOS. I have copied a PHP extension (imagick.so) that was built on similar server to my shared hosting server. I have resolved most of the dependencies by placing the missing files in ~/lib but I have one that I can't figure out how to cope with. I am getting the following error: What I'm trying to do is have it select the answers that are associated to that poll so that I can make a poll form out of this. Code: [Select] function getpoll($dbc) { $query = " SELECT polls.ID, polls.question, polls.totalVotes, (SELECT pollAnswers.ID, pollAnswers.answer FROM pollAnswers WHERE pollAnswers.pollID = polls.ID) FROM polls INNER JOIN pollAnswers ON polls.ID = pollAnswers.pollID WHERE polls.statusID = '1' ORDER BY polls.ID DESC LIMIT 1"; $result = mysqli_query($dbc, $query); $numrows = mysqli_num_rows($result); if ($numrows > "0") { } else { print "<p class=none>There are currently no open polls."; } } Hi Everyone, I will have a web application that users fill out and submit. I also have the same form in PDF format. I would like users to be able to click a print preview button, then open up FoxIt or Adobe and display the PDF, with their answers mapped to the correct location. I have no code, just looking for a direction and didn't know what to search for. Thanks. I have one array, called for example $MainImages : - Code: [Select] Array ( [0] => Array ( [widgetID] => 143 [image] => image_a.jpg ) [1] => Array ( [widgetID] => 147 [image] => image_b.jpg ) [2] => Array ( [widgetID] => 73 [image] => image_c.jpg ) ) and a second array, we'll call it $widgets: - Code: [Select] Array ( [0] => Array ( [widgetID] => 147 [seo_title] => An excellent class B Widget [name] => Widget B [categoryID] => 1 ) [1] => Array ( [widgetID] => 73 [seo_title] => An excellent class C Widget [name] => Widget C [categoryID] => 1 ) [2] => Array ( [widgetID] => 143 [seo_title] => An excellent class A Widget [name] => Widget A [categoryID] => 1 ) ) I want to merge the value from the [][image] key from the first array into a new [][image] key / value in the second, using a shared value as a reference...so the desired result array is: - Code: [Select] Array ( [0] => Array ( [widgetID] => 147 [seo_title] => An excellent class B Widget [name] => Widget B [categoryID] => 1 [image] => image_b.jpg ) [1] => Array ( [widgetID] => 73 [seo_title] => An excellent class C Widget [name] => Widget C [categoryID] => 1 [image] => image_c.jpg ) [2] => Array ( [widgetID] => 143 [seo_title] => An excellent class A Widget [name] => Widget A [categoryID] => 1 [image] => image_a.jpg ) ) Obviously the order is different and so they need to be merged based on the widgetID values. Also, the same widgetID may be in each array more than once. I've looked at a lot of help but can't find anything to do exactly what I need....any help would be greatly appreciated! Hi,
I'm newbie. My requirement is to open network shared folder from PHP.
This works fine in IE but not in Chrome.
Can anyone please help me ....
Thanks
Hi, I have Code: [Select] $to = 'rberbe2002@msn.com'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com'; mail($to, $subject, $message, $headers); which works fine on a shared hosting website I have, but not on a website I have on my dedicated server. Any ideas or suggestions please? I've just learned the basics of MySQL last night and made a simple app (where a user enters a song name, song title, and rating (out of 5) and it displays the list of songs with the highest rated songs first). So I decided I wanted to make something similar yet slightly more complicated and I'm not sure if I'm on the right track. Basically it's a "flash card" game whe - The user gets to input their own questions and answers into a simple form, which would then go into an MySQL table with 2 columns, questions and answers - A new page where the user see's random question, must input an answer, if the answer matches goes to next question otherwise gives error Now I'm confused as to how to go about making this. I was thinking of making some session variables and then do something along the lines of Code: [Select] $display_query = "SELECT * FROM questions"; $display = mysqli_query($connection, $display_query); while ($row = mysqli_fetch_array($display)) { $_SESSION['question'] = $row[0]; }[/syntax] //and then make some PHP that might do something like this: if ($_SESSION['answer'] != $row[1]) { echo "error, try again" } else { // I would write something here to grab the next question } So am I just completely off the wall with this, how would I make such an app? How would I make it, for example, fetch new questions? Hi,
I would like to ask if someone knows a trick to know if the script is running on a shared hosting or a vps or a dedicated server.
Regards
I implemented google's reCAPTCHA V2 on http:// on the remote apache shared server and it worked 100%. I then changed the protocol to my shared server SSL using the same PHP script as the non-SSL script. The older version of reCaptcha had an SSL 'false' to 'true' SSL parameter, whereas I can't find one for V2. I had to use htaccess to redirect the example.com to the shared SSL server https://serverid.net/example/ which works perfectly without recCAPTCHA. I incorporated reCAPTCHA V2 and the error message where the reCAPTCHA image should be shows "ERROR: Invalid domain for site key". This topic has been moved to PHP Installation & Configuration. http://www.phpfreaks.com/forums/index.php?topic=317008.0 Hi all i was wondering if someone knows a way to make sure an image which is uploaded isn't infected by a virus. I have read about avclam, but if your on a shared host your mostly not allowed to add own software. Isn't there maybe a php trick to resize the image which would magically remove a virus? If anyone knows a nice way or tricks to limit the virus breating space to a certain folder please let me know. Hi guys, first post here from a relative newbie I'm working on my final project for php and I'm running into a bit of a road block. The error is I'm trying to validate which radio button is checked to run a corresponding function to either add a car, drop a car, or display a car. Everything seems to work fine but my if statement won't pick up the change and therefore my function won't run. This is the output that I receive from the code. [taken from the bottom of the php when I select Add Car(s) on the form] input = 11112111421 add_status=add_status unchecked=unchecked Here's the script and htm form. Code: [Select] <html> <head> <title>Final Project</title> </head> <body> <form action="final.php" method="post"> <input type="radio" name="query" value="add_status" /> Add Car(s) <br /> <input type="radio" name="query" value="delete_status" /> Delete Car(s) <br /> <input type="radio" name="query" value="display_status" /> Display Car(s) <br /> <input type="text" name="Input_Car_ID" /> Car ID <br /> <input type="text" name="Input_Car_Make" /> Car Make <br /> <input type="text" name="Input_Car_Model" /> Car Model <br /> <input type="text" name="Input_Car_Vin" /> Car Vin <br /> <input type="text" name="Input_Car_Color" /> Car Color <br /> <input type="text" name="Input_Car_Mileage" /> Car Mileage <br /> <input type="Submit" value="Query" /> </form> </body> </html> <!-- Radio button selects which functions to run. Leave blank to view all --> <?php /* final.php Name: Peter Cort Date: 4/25/2012 Script: Final Project */ $add_status = "unchecked"; $drop_status = "unchecked"; $display_status = "unchecked"; extract($_POST, EXTR_SKIP); if (isset ($Submit)){ if ($query == "add_status") { $add_status = "checked"; } else if ($query == "drop_status") { $drop_status = "checked"; } else if ($query == "display_status") { $display_status = "checked"; } } function runsql(){ /*mysql_connect("sftweb01", "cort", "peter");*/ mysql_connect("localhost", "peter", "cort"); mysql_select_db("cort"); } runsql(); if ( empty($Input_Car_ID)) { $Input_Car_ID = ""; } if ( empty($Input_Car_Make)) { $Input_Car_Make = ""; } if ( empty($Input_Car_Model)) { $Input_Car_Model = ""; } if ( empty($Input_Car_Vin)) { $Input_Car_Vin = ""; } if ( empty($Input_Car_Color)) { $Input_Car_Color = ""; } if ( empty($Input_Car_Mileage)) { $Input_Car_Mileage = ""; } class car{ private $Car_ID; private $Car_Make; private $Car_Model; private $Car_Vin; private $Car_Color; private $Car_Mileage; public $Input_Car_ID; public $Input_Car_Make; public $Input_Car_Model; public $Input_Car_Vin; public $Input_Car_Color; public $Input_Car_Mileage; /* function for setting no input values to null (will be able to delete on multiple paramaters) */ /* function needs to get values from the .htm form */ function __construct($Input_Car_ID, $Input_Car_Make, $Input_Car_Model, $Input_Car_Vin, $Input_Car_Color, $Input_Car_Mileage) { $this->Car_ID = $Input_Car_ID; $this->Car_Make = $Input_Car_Make; $this->Car_Model = $Input_Car_Model; $this->Car_Vin = $Input_Car_Vin; $this->Car_Color = $Input_Car_Color; $this->Car_Mileage = $Input_Car_Mileage; } function add_vehicle() { if (($Car_ID == "") && ($Car_Make == "") && ($Car_Model == "") && ($Car_Vin == "") && ($Car_Color == "") && ($Car_Mileage == "")) { print "Please provide information about the car you wish to add"; } else mysql_query("INSERT INTO Car_T (Car_ID, Car_Make, Car_Model, Car_Vin, Car_Color, Car_Mileage) VALUES ('$this->Car_ID', '$this->Car_Make','$this->Car_Model', '$this->Car_Vin', '$this->Car_Color', '$this->Car_Mileage')"); } function drop_vehicle() { if (($Car_ID == "") && ($Car_Make == "") && ($Car_Model == "") && ($Car_Vin == "") && ($Car_Color == "") && ($Car_Mileage == "")) { print "Please provide information about the car you wish to delete"; } else mysql_query("DELETE FROM Car_T WHERE Car_ID = '$this->Car_ID' AND Car_Make='$this->Car_Make' AND Car_Model='$this->Car_Model' AND Car_Vin='$this->Car_Vin' AND Car_Color='$this->Car_Color' AND Car_Mileage='$this->Car_Mileage'"); } function display_vehicle() { if (($Car_ID == "") && ($Car_Make == "") && ($Car_Model == "") && ($Car_Vin == "") && ($Car_Color == "") && ($Car_Mileage == "")) { $display_query = mysql_query("SELECT * FROM Car_T"); } else $display_query = mysql_query("SELECT * FROM Car_T WHERE (Car_ID = '$this->Car_ID' OR Car_Make = '$this->Car_Make' OR Car_Model = '$this->Car_Model' OR Car_Vin = '$this->Car_Vin' OR Car_Color = '$this->Car_Color' OR Car_Mileage = '$this->Car_Mileage')"); while($row = mysql_fetch_row($display_query)){ echo $row['$this->Car_ID']; print "<br />"; } } function display_stuff() { echo $this->Car_ID; echo $this->Car_Make; echo $this->Car_Model; echo $this->Car_Vin; echo $this->Car_Color; echo $this->Car_Mileage; } } $new_entry = new car($Input_Car_ID, $Input_Car_Make, $Input_Car_Model, $Input_Car_Vin, $Input_Car_Color, $Input_Car_Mileage); if ($add_status == 'checked'){ $new_entry->add_vehicle(); } if ($drop_status == 'checked'){ $new_entry->drop_vehicle(); } if ($display_status == 'checked'){ $new_entry->display_vehicle(); } print "<br />"; print "input = "; $new_entry->display_stuff(); print "<br />"; print "$query"; print "="; print $query; print "<br />"; print "$add_status"; print "="; print $add_status; /* $Car_ID, $Car_Make, $Car_Model, $Car_Vin, $Car_Color, $Car_Mileage print $Input_Car_ID; print $Input_Car_Make; print $Input_Car_Model; print $Input_Car_Vin; print $Input_Car_Color; print $Input_Car_Mileage; print "<br />"; */ ?> My second part of this is wondering how to construct my display query to run right. I'd like to be able to run it on any possible input from the text box. I basically want to do something like (WHERE LIKE '%') where there isn't an input from the htm form. My thought was to build the query on a series of concatenations through a function, but that seems like a lot of work. I just feel like it's important to give that functionality to the program. Thanks for looking, and hopefully I don't confuse you readers that much :3 Also I know that the mysql_query(); is going out of style but just go with it for the sake of my sanity My table has 250 rows, but COUNT only seems to see 162 of them. In phpMyAdmin, for instance, there is a notice in the browse tab: "Showing rows 0-161 (162 total, Query took 0.0030 sec)". On one of my php pages, I get the same 162 result from this attempt to count the number of entries to my auto-incrementing "id" column :
$result = mysql_query('SELECT COUNT(id) AS id_count FROM MyTable)';Can anyone suggest the kinds of things I should check/adjust to understand why about 90 rows are not being counted? Many thanks in advance for any help anyone can offer. please help me in php i want that when a user clicks on add click a new box will be appeared for question consider user is doing work with questions and options he first gives a question after it he clicks on ADD button so a input box will appear den he clicks again to ADD button den aggain new box appears at last he clicks save then they would be inserted into database reply mee.. please I think this is a simple question, but I'm just starting out and can't figure out how to do this exactly. I'm making a demo site for a flower shop. The structure is as such (only listing the particular files in question - once this is done, the rest will be easy) index.php -> inc_show_colors.php -> showColors.php The index is to be standard through the site, loading include files into a main content area. Clicking on a link loads inc_by_color.php (index.php -> index.php?page=by_color ) From there, one of the four colors is selected. showColors.php contains switch statements for each color. I want to load showColors.php into the main content window when a color is selected, and I need to have it work for all four colors. I'm not sure how to do this, as you can't pass a variable to an include from what I understand. What's the easiest way to go about this? Keep in mind this is an intro class and "best practices" are not necessary yet, just the simplest solution to get it working. I want each of these colors to link to another include file, which will load in its place in index.php. index.php: Code: [Select] <div id="maincontent"> <?php if (isset($_GET['page'])) { switch ($_GET['page']) { case 'by_color': include('includes/inc_by_color.php'); break; case 'by_type': include('includes/inc_by_type.php'); break; case 'by_occasion': include('includes/inc_by_occasion.php'); break; case 'view_cart': include('includes/inc_view_cart.php'); break; case 'payment_options': include('includes/inc_payment_options.php'); break; case 'home_page': default: include('includes/inc_home.php'); break; } } else include('includes/inc_home.php'); ?> </div> inc_by_color.php: The first link I tried doing in the way I thought would work, but it doesn't. It can't find the include file. The second one works, kind of - but it just loads the page by itself, not into the maincontent div in index.php. Code: [Select] <h1>Flowers Categorized by Color</h1> <div class="picdivcontainer"> <div class="picdiv"><a href="index.php?page=red"><img src="images/image.png" width="90" height="90" alt="Red Flowers" /> <p>Red</a></p></div> <div class="picdiv"><a href="showColors.php?color=white"><img src="images/image.png" width="90" height="90" alt="White Flowers" /></a> <p><a href="showColors.php?color=white">White</a></p></div> </div> and showColors.php: Code: [Select] if (isset($_GET['color'])) { switch ($_GET['color']) { case 'red': $result = mysql_query("SELECT * FROM flowers WHERE color='red'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { // Set and trim strings and show the resulting flowers from query $flowername = $row['name']; $flowerimage = $row['image']; $image_path = "images/"; $flowername = str_replace('_', ' ', $flowername); $flowername = ucwords($flowername); ?> <div class="picdiv"><p><?php echo $flowername."<br />"; $flowerimage = str_replace(' ', '_', $flowerimage); echo "<img src='images/" . $row['image'] . "' />"; ?></p></div> <?php } break; I realize that showColors.php is probably a really messy way of doing this, but I just need to get it functioning ASAP for now. Hey, friends. I have some trouble on the server front. My sites have been hacked, and I need to make sure I've eradicated every trace of this exploit. I'm looking for a way to search for any and all php files contained in multiple directories with specific names. For instance, I have found a commonality in relation to where these malicious files are placed, such as: Code: [Select] /some/dir/img/somename.phpor: Code: [Select] /some/dir/js/somename.php Is there a way I can easily (e.g. using ssh and the "find" command) locate all files ending in php but only found in directories named "img"? I can't seem to find anything that would allow me to do this with find, or with a combination of find and grep. I can't go directory by directory, as some of these img directories are created many levels deep, some even in .svn directories. Any and all help is appreciated. Hackers suck. |