I want to convert a report into a form - php

I'm doing a project using php and mySQL and what I want to do is take a report I've generated, (Scholarships.php) and allow me to submit data from it.
Specifically,
I have a giant table of scholarships that can be added to. In a form page where people can apply for these scholarships, I included an iFrame that displays Scholarships.php. What I want to do is set up check boxes next to each scholarship so that an applying student could select various scholarships, hit submit, and the results dump into a Junction table I've created.
The part I don't know how to do is converting the report I've generated, and converting it into a form I can use for the check boxes.
while ($row = mysql_fetch_array($result)) {
echo "<h2>";
echo "ID - $row[0]";
echo "</h2>";
echo "<p>";
echo "$row[1].";
echo "</p>";
echo "<h2>";
echo "$row[2].";
echo "</h2>";
echo "<p>";
echo $row[3]."";
echo "</p>";
echo "<p>";
echo $row[4]."";
echo "</p>";
echo "<p>";
echo $row[5]."";
echo "</p>";
}
How from this snippet would I place checkboxes that post to another table?

Related

PHP: How do I code a link for a specific array stored in a text file without hardcoding it?

This question may have been answered, but I have been Googling and searching this site for over a week now and have not come across anything that applies to this situation. Yes, this is a homework assignment, and I have exhausted my resources (the entire class is confused). Any help or links to relevant resources would be appreciated.
Problem: I have a program where the user can submit "bug reports". These bug reports are all written to the same text file and are each treated as an array. Each report is also displayed with a "Details" link. I need to write a hyperlink that will essentially assign the link to the index value of the array without hardcoding it (because the link will need to work for future updates) and then have that specific report displayed in a separate page. I'm submitting a photo of the display table with the link in it so that there's a visual of this allow with the specific code for the display table.
Image of display table
$count = count($ReportArray);
for($i = 0; $i < $count; ++$i) {
$CurReport = explode("~", $ReportArray[$i]);
//bug description line and details link
echo "<tr>";
echo "<td><p style='text-align: center;'><strong>Bug Description: </strong></td>";
echo "<td colspan='6' style='text-align: center;'>".htmlentities($CurReport[0])."<br/></td>\n";
//$CurArray = implode("~", $CurReport);
//assign details link an array - no idea how
$num = count($ReportArray); //total number of reports
echo '<td style="text-align: center;">';
echo '<p>Details</p>';
echo "</td></tr>\n";
//other bug report fields
echo "<tr>";
echo "<td></td>";
echo "<td style=\"text-align:center;\">".htmlentities($CurReport[1])."<br /></td>\n";
echo "<td style=\"text-align:center;\">".htmlentities($CurReport[2])."<br /></td>\n";
echo "<td style=\"text-align:center;\">".htmlentities($CurReport[3])."<br /></td>\n";
echo "<td style=\"text-align:center;\">".htmlentities($CurReport[4])."<br /></td>\n";
echo "<td style=\"text-align:center;\">".htmlentities($CurReport[5])."<br /></td>\n";
echo "<td style=\"text-align:center;\">".htmlentities($CurReport[6])."<br /></td>\n";
echo "<td></td>";
echo "</tr>\n";
//display updates
echo "<tr>";
$line_count = count($ReportArray);
if($line_count > 7) {
echo "<tr>";
echo '<td style="text-align:center; text-weght:bold;">Update</td><td>';
echo htmlentities($CurReport[$line_count - 1]).'<br/>\n';
echo "</td>";
echo "</tr>\n";
}
}
So here's how the program works:
bug_List.php: Has the form for bug reports and then a table to
display the submitted and validated reports. These reports all
written and read from the same text file. BugReportCreate.php:
This file validates the input and writes it the text file. BugReport.php: This file is used to display each individual report and allows the user to submit updates for the report currently displayed. BugReportUpdate.php: writes/appends the update to the specific report from BugReport and displays the updated report. bug_List.php will also display the updated report(s)

How can I use hyperlinks in PHP to display data on the page it sends you to?

I have this piece of code below. It displays the image and name of all the entries in a table in my database. The name is set up to become a hyperlink.Is it possible to make it so when one specific name is clicked that data for only that specific name will be displayed on the page you are sent to?
So for example if I select the first entry that is displayed back "mealname1" and it takes me to the showrecipe.php page, can I make it so I can display all the data I have for "mealname1" and only "mealname1". I'm really lost, I have scoured the internet and my php books but can't find anything to that is relevant.
If there is no way of doing it is there an obvious solution that I am missing?... I am very much a novice to this... thanks for your help guys.
<?php
require("db.php");
$prodcatsql = "SELECT * FROM recipes";
$prodcatres = mysql_query($prodcatsql);
$numrows = mysql_num_rows($prodcatres);
if($numrows == 0)
{
echo "<h1>No Products</h1>";
echo "There are no recipes available right now.";
}
else
{
echo "<table id='recipetable'>";
while($prodrow = mysql_fetch_assoc($prodcatres))
{
echo "<tr>";
if(empty($prodrow['image'])){
echo "<td><img
src='./images/No_image.png' alt='"
. $prodrow['mealname'] . "'></td>";
}
else {
echo "<td><img src='./images/".$prodrow['image']
. "' alt='"
. $prodrow['mealname'] . "'></td>";
}
echo "<td>";
echo ''.$prodrow['mealname'].'';
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
?>
Change the query to
SELECT * FROM recipes WHERE mealname='$mealname' LIMIT 1;
You can remove "LIMIT 1" if you want but this makes sure you will only get 1 or 0 row back. Don't forget to escape the string.

Save items from a shopping basket into a php session variable for later use - using an array

Firstly, we have a session which runs throughout all of the php webpages.
We also have a sql database were using check boxes we can select items from the database and enter them into a shopping cart. This works.
On the shopping basket webpage we have an array from another page that hold reference numbers to items in our database. we are getting this array by using POST , we have been trying to save this array to our session, as a session variable so it will keep all the reference numbers till the user logs out which will kill the session and also the cart is updated when more items are added at a later date
Below is the table in the shopping basket in php surrounds.
echo "<table border='1'>";
echo "<tr>";
echo "<th>Manafacturer</th>";
echo "<th>Model</th>";
echo "<th>OS</th>";
echo "<th>Colour</th>";
echo "<th>Screen size</th>";
echo "<th>Price(&pound)</th>";
echo "<th>Decription</th>";
echo "<th>Remove</th>";
echo "</tr>";
while ($c = pg_fetch_array($res))
{
if ( isset($_POST[$c['ref']])) {
$newRes = pg_query ($conn, "select * from phones where ref = " . $c['ref'] . "");
$a = pg_fetch_array ($newRes);
The post above needs to be saved into a session variable array list so we can go back to it at a later date
echo "<tr>";
echo "<td>".$a["manufacturer"]."</td>";
echo "<td>".$a["model"]."</td>";
echo "<td>".$a["os"]."</td>";
echo "<td>".$a["colour"]."</td>";
echo "<td>".$a["screen"]."</td>";
echo "<td>"."&pound".$a["price"]."</td>";
echo "<td>".$a["description"]."</td>";
echo "<td>"."<input type='button' name='".$a["ref"]."' value='Remove'>"."</td>";

dynamic php page calls

So I have looked through many of the other questions posted but none seemed to properly answer my question.
I currently have a php script that reads rows from a database and runs a loop to display the info of each row in a html div.
The issue I am now having is that in each "card" of info previously loaded there has a picture. And when the picture is clicked I need to load a different file names listing.html. The problem is that depending on which picture is clicked on I want to load different information based on which listing was clicked on. I looked into using sessions but since i dynamically load all of the pictures in one loop I do not know a way to differentiate between them.
here is the code I currently have that loads all the info from the database.
$query = "SELECT * FROM Listings ORDER BY OrderNumber";
if ($result = mysqli_query($con, $query))
{
while ($row = mysqli_fetch_row($result))
{
echo "<div class ='listing'>";
echo "<a href='listing.html'>";
echo "<img src=$row[2] alt='' width='60%' align='left' >";
echo "</a>";
echo "<span style = 'font-size: 25px;'>";
echo $row[4];
echo "</span>";
echo "<br>";
echo "<br>";
echo "MLS Number: #";
echo $row[1];
echo "<br>";
echo "<br>";
echo "<b>Open House Details: </b>";
echo $row[6];
echo "<br>";
echo "<br>";
echo $row[5];
echo "<br>";
echo "<br>";
echo "<a href='";
echo $row[9];
echo "' style='color: #8a0b0b; font-weight: bold; font-style: italic; font-size: 18px;' target='_blank'>Virtual Tour</a>";
echo "<div class='listingPrice'>";
echo "$ ";
echo $row[7];
echo "</div>";
echo "</div>";
}
mysqli_free_result($result);
}
I need some way that when the a tag is clicked to first be able to discern which picture was clicked then probably make a session variable with the corresponding row.
When you output the link, include a query string value from the row in the data. Something like this:
echo "<a href='listing.html?id=" . row[0] . "'>";
(I'm just guessing on the row[0] part, it would be any identifier which uniquely identifies that record.) That way all of the links would have the data you need on the listing.html page embedded directly in them. (Shouldn't it be listing.php?)
So on the page being referenced, the value would then be available in the query string. Something like this:
$_GET["id"]
There really isn't a need for session state in this case, if all you need to know is which record was clicked then that information can be placed directly in the link. This reduces coupling in the code, keeps the links a little more RESTful, even lets people bookmark the link directly if they want to.

Ifstatement used to make a functionality button appear?

I am on my 2nd day(16th hour) of trying to get my delete button to do what I want with PHP. I have a site that is a social network that has user profiles. Users can leave comments on another users profile. I am trying to put a delete link in a designated area that only shows up if you are viewing your own profile and goes away when you are viewing someone elses profile. I am also not wanting to make a delete confirm page. I want the page to reload with the comment selected to delete gone, and be sent to my db marked as dead. This is what I have so far:
<?php
$query = "SELECT * FROM `ProfileComments` WHERE `ToUserID` = '".$prof->id."' ORDER BY `date` DESC, `time` DESC LIMIT 10";
$request = mysql_query($query,$connection);
while($result = mysql_fetch_array($request)) {
$poster = new User($result['FromUserID']);
echo "<div id='CommentProfile'>";
echo "<div id='CommentPhotoProfile'>";
echo "<a href='http://www.blah.org/Profile.php?id=".$poster->id."'>";
echo "<img src='" . $poster->img('mini') . "' border='0'/>";
echo "</a>";
echo "</div>";
echo "<div id='ProfileCommentBody' class= 'round_10px'>";
echo "<div id='CommentNameProfile'>";
echo "<div class='ProfileCommentTail'> </div>";
echo "<a href='http://www.blah.org/Profile.php?id=".$poster->id."'>";
echo $poster->first_name. " ". $poster->last_name. " <span style='font-weight:normal'>says...</span>";
echo "</a>";
echo "</div>";
echo stripslashes(nl2br($result['commentProfileBody']));
echo "<div id='CommentInfoProfile'>";
echo date('M d, Y',strtotime($result['date']));
echo " at " . date('g:i A',strtotime($result['time']));
if ($poster->id == $prof->id)
echo "<a href='http://www.blah.org/DeleteComment.php?id=".$prof->id."'>";
echo " delete";
echo "</a>";
echo "</div>";
echo "</div>";
echo "</div>";
}
?>
do I need to make a seperate query underneath the one I already have that is for the composition of the comments?
do I need to add on to that query?
how do I make the delete button only appear when the user is looking at their own page?
how do I make the page reload with the comment gone after I selected it deleted and mark it dead in the db?
thank you in advance
Be careful if all you do after authorization of the delete privilege is then hide or not hide a button.
If users figure out another way to invoke the delete action, that kind of authorization checking won't work. For example, if your implementation uses a "delete URL" that encodes the delete command, and your button merely POSTs to that URL, then when the button is hidden, a user could manually post the delete command.
Fill in your variables:
if ($current_user_id == $profile_user_id)
echo 'delete';
This is toatlly lame, code, but just a random thought since you are really giving us nothing to work with.
Take it for what it is:
function getPageUserID()
{
return $_GET['userID'];
}
if ($user->userID == getPageUserID())
{
//show delete button
echo '<button value="Delete">Delete</button>';
}

Categories