Jump to content

[SOLVED] $end error?


Sparrow

Recommended Posts

I get this error message when I run this php script in my web browser: unexpected $end on line 51. What is the solution?

 

here is the code (line 51 is bolded, last line)

 

<?php

session_start();

 

include 'session_checker.php';

session_checker();

 

include 'db.php';

 

//Convert posted info to variables

 

$route_number = $_POST['route_number'];

$username = $_POST['username'];

 

//Get info from flights

 

$sql = "SELECT * FROM flights WHERE route_number = $route_number";

 

$result = mysql_query($sql);

 

$array = mysql_fetch_array($result);

 

//Turn into variables

$type = $array['type'];

$dep_airport = $array['dep_airport'];

$arr_airport = $array['arr_airport'];

$aircraft = $array['aircraft'];

$Rank = $array['Rank'];

$dep_day = $array['dep_day'];

$duration = $array['duration'];

$route_number = $array['route_number'];

 

// Enter info into booked_flights.

$info2 = htmlspecialchars($info);

$sql = mysql_query("INSERT INTO booked_flights (type, dep_airport, arr_airport, aircraft, Rank, dep_day, duration, route_number)

VALUES('$type', '$dep_airport', '$arr_airport', '$aircraft', '$Rank', '$dep_day', '$duration', '$route_number')") or die (mysql_error());

 

if(!$sql){

echo 'There has been an error in booking your flight. Please try again.';

 

} else {

$route_number = mysql_insert_id();

 

 

 

//Delete info from flights to prevent double booking

mysql_query("DELETE FROM flights WHERE route_number = '$route_number'");

 

mysql_close($connection);

 

include 'flight_booked.php';

?>

Link to comment
Share on other sites

This has no closing } to it

 

{
   $route_number = mysql_insert_id();



//Delete info from flights to prevent double booking
mysql_query("DELETE FROM flights WHERE route_number = '$route_number'");

mysql_close($connection);

include 'flight_booked.php';

Link to comment
Share on other sites

Thanks that problem is solved but now I get this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/unitedai/public_html/book_flight.php on line 20

Duplicate entry '' for key 1

 

here is the new code: (line 20 is bolded)

 

<?php

session_start();

 

include 'session_checker.php';

session_checker();

 

include 'db.php';

 

//Convert posted info to variables

 

$route_number = $_POST['route_number'];

$username = $_POST['username'];

 

//Get info from flights

 

$sql = "SELECT * FROM flights WHERE route_number = $route_number";

 

$result = mysql_query($sql);

 

$array = mysql_fetch_array($result);

 

//Turn into variables

$type = $array['type'];

$dep_airport = $array['dep_airport'];

$arr_airport = $array['arr_airport'];

$aircraft = $array['aircraft'];

$Rank = $array['Rank'];

$dep_day = $array['dep_day'];

$duration = $array['duration'];

$route_number = $array['route_number'];

 

// Enter info into booked_flights.

$info2 = htmlspecialchars($info);

$sql = mysql_query("INSERT INTO booked_flights (type, dep_airport, arr_airport, aircraft, Rank, dep_day, duration, route_number)

VALUES('$type', '$dep_airport', '$arr_airport', '$aircraft', '$Rank', '$dep_day', '$duration', '$route_number')") or die (mysql_error());

 

if(!$sql){

echo 'There has been an error in booking your flight. Please try again.';

 

} else {

$route_number = mysql_insert_id();

}

 

 

 

//Delete info from flights to prevent double booking

mysql_query("DELETE FROM flights WHERE route_number = '$route_number'");

 

mysql_close($connection);

 

include 'flight_booked.php';

echo "<p> </p>";

?>

Link to comment
Share on other sites

PLEASE use code tags when posting code on the forums, as it makes it much more readable.  Anyway, change:

$result = mysql_query($sql);

To:

$result = mysql_query($sql) or die(mysql_error());

 

The error that you got usually means that your query failed, so this adds rudimentary error checking and should be used on ALL queries during the development stage.  Show us the new output please.

 

P.S: For anyone who wants to correct me, I know that it's better handled by exceptions or error handlers, but he's clearly just developing.

Link to comment
Share on other sites

I fixed my problem by putting ' '  around $route_number.  No errors anymore.  However I noticed that the delete msql query that is supposed to delete the entriee from the flights table dosen't seem to work and that the username of the user who booked that flight isn't recorded. Any way to fix these problems?

Link to comment
Share on other sites

I modified the code slightly so that the username of the person who is logged in gets recorded on the booked flights table.  But now I get this error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/unitedai/public_html/book_flight.php on line 36.  Why?

 

Here is the new code: (line 36 is bolded)

<?php
session_start();

include 'session_checker.php';
session_checker();

include 'db.php';

//Convert posted info to variables

$route_number = $_POST['route_number'];
$username = $_POST['username'];

//Get info from flights 

$sql = "SELECT * FROM flights WHERE route_number = '$route_number'";

$result = mysql_query($sql) or die(mysql_error());

$array = mysql_fetch_array($result) or die(mysql_error());

//Turn into variables
$type = $array['type'];
$dep_airport = $array['dep_airport'];
$arr_airport = $array['arr_airport'];
$aircraft = $array['aircraft'];
$Rank = $array['Rank'];
$dep_day = $array['dep_day'];
$duration = $array['duration'];
$route_number = $array['route_number']; 
$username = $array['username'];

// Enter info into booked_flights.
$info2 = htmlspecialchars($info);
$sql = mysql_query("INSERT INTO booked_flights (type, dep_airport, arr_airport, aircraft, Rank, dep_day, duration, route_number, username)
VALUES('$type', '$dep_airport', '$arr_airport', '$aircraft', '$Rank', '$dep_day', '$duration', '$route_number', '.$_SESSION['$username'].')") or die (mysql_error()); // line 36

if(!$sql){
echo 'There has been an error in booking your flight. Please try again.';

} else {
$route_number = mysql_insert_id();
}	
//Delete info from flights to prevent double booking
mysql_query("DELETE FROM flights WHERE route_number = '$route_number'");

mysql_close($connection);

include 'flight_booked.php';
echo "<p> </p>";
?>

Link to comment
Share on other sites

$sql = mysql_query("INSERT INTO booked_flights (type, dep_airport, arr_airport, aircraft, Rank, dep_day, duration, route_number, username)
VALUES('$type', '$dep_airport', '$arr_airport', '$aircraft', '$Rank', '$dep_day', '$duration', '$route_number', '{$_SESSION['$username']}')") or die (mysql_error()); 

Link to comment
Share on other sites

Thank-you very much ;).  One last problem.  At the end of my code as you may have noticed I have a MSQL query to (after the entriee has been added to the booked flights table) delete the entriee from the flights table. however it dosen't seem to be working.  because after I try the script out yes the "flight" is added to the booked flights table but it is not deleted from the flights table.  Any idea why?

 

here is the new code:

 

<?php
session_start();

include 'session_checker.php';
session_checker();

include 'db.php';

//Convert posted info to variables

$route_number = $_POST['route_number'];
$username = $_POST['username'];

//Get info from flights 

$sql = "SELECT * FROM flights WHERE route_number = '$route_number'";

$result = mysql_query($sql) or die(mysql_error());

$array = mysql_fetch_array($result) or die(mysql_error());

//Turn into variables
$type = $array['type'];
$dep_airport = $array['dep_airport'];
$arr_airport = $array['arr_airport'];
$aircraft = $array['aircraft'];
$Rank = $array['Rank'];
$dep_day = $array['dep_day'];
$duration = $array['duration'];
$route_number = $array['route_number']; 
$username = $array['username'];

// Enter info into booked_flights.
$info2 = htmlspecialchars($info);
$sql = mysql_query("INSERT INTO booked_flights (type, dep_airport, arr_airport, aircraft, Rank, dep_day, duration, route_number, username)
VALUES('$type', '$dep_airport', '$arr_airport', '$aircraft', '$Rank', '$dep_day', '$duration', '$route_number', '{$_SESSION['username']}')") or die (mysql_error());

if(!$sql){
echo 'There has been an error in booking your flight. Please try again.';

} else {
$route_number = mysql_insert_id();
}

//Delete info from flights to prevent double booking
mysql_query("DELETE FROM flights WHERE route_number = '$route_number'");

mysql_close($connection);

include 'flight_booked.php';
echo "<p> </p>";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.