0
?php session_start(); 
$Body = "";
$errors = 0;

if (!isset($_SESSION['internID'])) {
    $Body .= "<p>You have not logged in or registered. Please return to the <a href='InternLogin.php'>Registration / Log In page</a>.</p>\n";
    ++$errors;
}

if ($errors == 0) {
    if (isset($_GET['opportunityID']))
        $OpportunityID =  $_GET['opportunityID'];
    else {
        $Body .= "<p>You have not selected an opportunity. Please return to the <a href='AvailableOpportunities.php? . SID'>" . 
        "Available Opportunities page</a>.</p>\n";
        ++$errors;
    }
}

/* $DBConnect = FALSE; */
if ($errors == 0){
    $DBConnect = @mysql_connect("localhost", "FAKE", "HELLO");

    if($DBConnect === FALSE) {
        $Body .= "<p>Unable to connect to the database server. Error code " . mysql_errno() .": " . mysql_error() . "</p>\n";
        ++$errors;
 }

 else {
    $DBName = "rac218_internships";
    $result = @mysql_select_db($DBName, $DBConnect);

        if ($result === FALSE) {
        $Body .= "<p>Unable to select the database. Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>\n";
        ++$errors;
        }
    }
}

if ($errors == 0) {
    $TableName = "assigned_opportunities";
    $SQLstring = "DELETE FROM $TableName WHERE opportunityID=$OpportunityID AND internID=$_SESSION['internID'] AND date_approved IS NULL";
    $QueryResult = @mysql_query($SQLstring, $DBConnect);
}
if ($QueryResult === FALSE) {
    $Body .= "<p>Unable to execute the query. Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>\n";
    ++$errors;
}
else {
    $AffectedRows = mysql_affected_rows($DBConnect);

    if ($AffectedRows == 0)
        $Body .= "<p>You had not previously selected opportunity # " . $OpportunityID . ".</p>\n";
    else
        $Body .= "<p>Your request for opportunity # " . $OpportunityID . " has been removed.</p>\n";
}
    mysql_close($DBConnect);

}

 if ($_SESSION['internID'] > 0)
    $Body .= "<p>Return to the <a href='AvailableOpportunities.php? . SID'>Available Opportunities</a> page.</p>\n";
 else
    $Body .= "<p>Please <a href='InternLogin.php'>Register or Log In</a> to use this page.</p>\n";
?>

<!DOCTYPE html>
<html lang="en-US">
<head>
    <title>Cancel Selection</title>
    <meta charset="utf-8">
</head>
<body>
<h1>College Internship</h1>
<h2>cancel Selection</h2>

<?php echo $Body; ?>
</body>
</html>

It keep saying, "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /****/CancelSelection.php on line 42 "

I have looked through the homework 5 times and don't see anything that is missing or mistyped. Can someone tell me what's wrong with the code or point me in the right direct as to how I can solve problems like this? Thanks!

user3579754
  • 837
  • 2
  • 7
  • 10
  • 1
    Let me know if you could solve your problem or got stuck anywhere. But first read the dupe! – Rizier123 Jul 14 '15 at 22:21
  • remove the single quotes from `$_SESSION['internID']` on line 42 you don't need them. Also you have an unnecessary `}` on line 59. Get yourself a decent IDE then you won't encounter such syntax errors – andrew Jul 14 '15 at 22:36
  • Why would you remove the quotes from the session variable @Andrew? Removing the quotes makes `internID` a constant. What needs to happen in this case would be proper concatenation. A better solution all around would be prepared statements. – Jay Blanchard Jul 15 '15 at 11:30
  • If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jul 15 '15 at 11:31
  • @JayBlanchard in this case: `$SQLstring = "DELETE FROM $TableName WHERE internID=$_SESSION['internID'] AND date_approved IS NULL";` Where `$_SESSION['internID']` is inside a string, removing the single quotes is fine as php's string parser will consume it. It is not greedy though so `$_SESSION[internID][foo]` would require quotes with curly braces or the string would need to be concatenated. please see the [example](http://php.net/manual/en/language.types.string.php#example-92) in the manual – andrew Jul 15 '15 at 11:49
  • @JayBlanchard but I do agree a prepared statement would be the correct approach – andrew Jul 15 '15 at 11:55

0 Answers0