Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Trying to store information using $_COOKIE autoglobal. PLEASE READ MY EXPLANATION BEFORE RESPONDING. Here's how the pages should work: AvailableOpportunities.php displays a list of open

Trying to store information using $_COOKIE autoglobal.

PLEASE READ MY EXPLANATION BEFORE RESPONDING.

Here's how the pages should work: AvailableOpportunities.php displays a list of open internships options, each with it's own "Available" link. Clicking a link will take you to RequestOpportunity.php that displays "Your request for opportunity # $OpportunityID has been entered on $DisplayDate." So the $OpportunityID is either 1, 2, 3, 4, or 5 depending on which link was clicked ($DisplayDate is the date that the link was clicked). Below that is a link back to the AvailabilitiesOpportunities.php page. Upon returning to the original page, the link should now say "Selected" and there should be a message over the top of the internships table that says "You last requested an internship opportunity on $LastRequestDate." $LastRequestDate is what is being stored/sent by the cookie.

The problem is that the cookie is not working so the AvailableOpportunities.php is not being updated. I've included the code for both pages below.

AvailableOpportunities.php:

Available Opportunities

College Internship

Available Opportunities

//complete Exercise #3 (for AvailableOpportunities.php) on Page 509 here --------------------- if(isset($_REQUEST['internID'])) $InternID = $_REQUEST['internID']; else $InternID = -1;

//exercise #2 from page 527 if(isset($_COOKIE['LastRequestDate'])) $LastRequestDate = $_COOKIE['LastRequestDate']; else $LastRequestDate = "";

$errors = 0;

include("../config.php"); $DBConnect = new mysqli ($config['db_host'], $config['db_user'], $config['db_password'], $config['db_name']);

if ($DBConnect === FALSE) { echo "

Unable to connect to the database server. " . "Error code " . mysqli_errno() . ": " . mysqli_error() . "

"; ++$errors; } else { $DBName = "internships"; $result = mysqli_select_db($DBConnect, $DBName); if ($result === FALSE) { echo "

Unable to select the database. " . "Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect) . "

"; ++$errors; } } $TableName = "interns"; if ($errors == 0) { // complete Exercise #5 Page 510 here. $SQLstring = "SELECT * FROM $TableName WHERE internID='$InternID'"; $QueryResult = mysqli_query($DBConnect, $SQLstring); if ($QueryResult === FALSE) { echo "

Unable to execute the query. " . "Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect) . "

"; ++$errors; } else { if (mysqli_num_rows($QueryResult) == 0) { echo "

Invalid Intern ID!

"; ++$errors; } } } if ($errors == 0) { $Row = mysqli_fetch_assoc($QueryResult); $InternName = $Row['first'] . " " . $Row['last']; } else $InternName = ""; $TableName = "assigned_opportunities"; $ApprovedOpportunities = 0;

//complete Exercise #7 on page 511 here------------------------------- $SQLstring = "SELECT COUNT(opportunityID) FROM $TableName "."WHERE internID='$InternID' ". "AND date_approved IS NOT NULL"; $QueryResult = mysqli_query($DBConnect, $SQLstring); if (mysqli_num_rows($QueryResult) > 0) { $Row = mysqli_fetch_row($QueryResult); $ApprovedOpportunities = $Row[0]; mysqli_free_result($QueryResult); } $SelectedOpportunities = array(); $SQLstring = "SELECT opportunityID FROM $TableName " . " WHERE internID='$InternID'"; $QueryResult = mysqli_query($DBConnect, $SQLstring); if(mysqli_num_rows($QueryResult) > 0) { $Row = mysqli_fetch_row($QueryResult); do { $SelectedOpportunities[] = $Row; $Row = mysqli_fetch_row($QueryResult); } while($Row); mysqli_free_result($QueryResult); }

/*if (mysqli_num_rows($QueryResult) > 0) { while (($Row = mysqli_fetch_row($QueryResult)) !== FALSE) $SelectedOpportunities[] = $Row[0]; mysqli_free_result($QueryResult); }*/

$AssignedOpportunities = array(); $SQLstring = "SELECT opportunityID FROM $TableName " . " WHERE date_approved IS NOT NULL"; $QueryResult = mysqli_query($DBConnect, $SQLstring); if (mysqli_num_rows($QueryResult) > 0) { while (($Row = mysqli_fetch_row($QueryResult)) !== FALSE) $AssignedOpportunities[] = $Row[0]; mysqli_free_result($QueryResult); } $TableName = "opportunities"; $Opportunities = array(); //complete Exercise #10 on Page-512 ------------------- $SQLstring = "SELECT opportunityID, company, city, start_date, end_date, position, description "."FROM $TableName"; $QueryResult = mysqli_query($DBConnect, $SQLstring); if(mysqli_num_rows($QueryResult) > 0) { $Row = mysqli_fetch_assoc($QueryResult); do { $Opportunities[] = $Row; $Row = mysqli_fetch_assoc($QueryResult); } while($Row); //mysqli_free_result($QueryResult); }

mysqli_close($DBConnect); /*if (mysqli_num_rows($QueryResult) > 0) { while (($Row = mysqli_fetch_assoc($QueryResult)) !== FALSE) $Opportunities[] = $Row; mysqli_free_result($QueryResult); } mysqli_close($DBConnect);*/

//step 3 from page 528 if(!empty($LastRequestDate)) echo "

You last requested an internship opportunity on $LastRequestDate.

";

$Row = mysqli_fetch_assoc($QueryResult); do { echo "{$Row['subscriberID']}"; echo "{$Row['name']}"; echo "{$Row['email']}"; echo "{$Row['subscribe_date']}"; echo "{$Row['confirmed_date']} "; $Row = mysqli_fetch_assoc($QueryResult); } while($Row);

echo "

"; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; foreach ($Opportunities as $Opportunity) { if (!in_array($Opportunity['opportunityID'], $AssignedOpportunities)) { echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; } } echo "
CompanyCityStart DateEnd DatePositionDescriptionStatus
" . htmlentities($Opportunity['company']) . "" . htmlentities($Opportunity['city']) . "" . htmlentities($Opportunity['start_date']) . "" . htmlentities($Opportunity['end_date']) . "" . htmlentities($Opportunity['position']) . "" . htmlentities($Opportunity['description']) . ""; if (in_array($Opportunity['opportunityID'], $SelectedOpportunities)) echo "Selected"; else { if ($ApprovedOpportunities>0) echo "Open"; else echo "Available"; } echo "
"; echo "

Log Out

";

?>

RequestOpportunities.php:

//complete exercise #4 on page 522-523 here-----------------------

if(isset($_GET['internID'])) $InternID = $_GET['internID']; else { $Body .= "

You have not logged in or registered. Please return to the Registration/Log In page

"; ++$errors; }

if($errors == 0) { if(isset($_GET['opportunityID'])) $OpportunityID = $_GET['opportunityID']; else { $Body .= "

You have not selected an opportunity. Please return to the ". "Available Opportunities page

"; ++$errors; } }

if ($errors == 0) { include("../config.php"); $DBConnect = new mysqli ($config['db_host'], $config['db_user'], $config['db_password'], $config['db_name']); if ($DBConnect === FALSE) { $Body .= "

Unable to connect to the database " . " server. Error code " . mysqli_errno() . ": " . mysqli_error() . "

"; ++$errors; } else { $DBName = "internships"; $result = mysqli_select_db($DBConnect, $DBName); if ($result === FALSE) { $Body .= "

Unable to select the database. " . "Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect) . "

"; ++$errors; } } } //complete exercise #6,7,8 on page 523-524 here

$DisplayDate = date("l, F j, Y, g: i A"); $DatabaseDate = date("Y-m-d H:i:s"); if($errors == 0) { $TableName = "assigned_opportunities"; $SQLstring = "INSERT INTO $TableName (opportunityID, internID, date_selected) VALUES ('$OpportunityID', '$InternID', '$DatabaseDate')"; $QueryResult = mysqli_query($DBConnect, $SQLstring); if(!$QueryResult) { $Body .= "

Unable to execute the query. Error code ".mysqli_errno($DBConnect).": ".mysqli_error($DBConnect)."

"; ++$errors; } else { $Body .= "

Your request for opportunity # $OpportunityID has been entered on $DisplayDate.

"; } mysqli_close($DBConnect); }

if($InternID > 0) $Body .= "

Return to the Available Opportunities page.

"; else $Body .= "

Please Register or Log In to use this page.

";

if($errors == 0) @setcookie("LastRequestDate", urlencode($DisplayDate), time()+60*60*24*7, "/"); /*

The @ is not causing the issue. I have tested the program without it. It's here because my instructor wants us to include a file so he can just change the variables once when looking at our code. Unfortunately, the include statement is read as a header by the server and causes an error. The @ is the only compromise given is requirments. */ ?> Request Opportunity

College Internship

Opportunity Requested

echo $Body; ?>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logic In Databases International Workshop Lid 96 San Miniato Italy July 1 2 1996 Proceedings Lncs 1154

Authors: Dino Pedreschi ,Carlo Zaniolo

1st Edition

3540618147, 978-3540618140

More Books

Students also viewed these Databases questions

Question

4. How is culture a contested site?

Answered: 1 week ago