Question: The problem is 8-5 of PHP Programming with MySQL (2nd Edition) I tried this solution but it didn't work as expected: https://www.chegg.com/homework-help/PHP-Programming-with-MySQL-2nd-edition-chapter-8-problem-5RE-solution-9780538745840 I need it
The problem is 8-5 of PHP Programming with MySQL (2nd Edition)
I tried this solution but it didn't work as expected:
https://www.chegg.com/homework-help/PHP-Programming-with-MySQL-2nd-edition-chapter-8-problem-5RE-solution-9780538745840
I need it to look like the next 3 pictures:



Please help me fix this code:
First File:
$DBConnect = mysql_connect("localhost", "root", "root");
if($DBConnect === FALSE){
die("Unable to connect.");
}
$DBName = "airlinesurvey";
$SQLstring = "CREATE DATABASE $DBName";
if(mysql_query($SQLstring, $DBConnect)){
echo "
Database created successfully.
";
} else {
echo "
Database exists.
";
}
$DBConnect = mysql_connect("localhost", "root", "root", "airlinesurvey");
if($DBConnect === FALSE){
die("Could not connect.");
}
$TableName = "surveyreport";
$SQLstring = "SELECT * FROM $TableName";
$QueryResult = @mysql_query($SQLstring, $DBConnect);
if(@mysql_num_rows($QueryResult) > 0){
echo "$TableName table already exists";
} else {
$SQLstring = "CREATE TABLE $TableName (Survey_ID
SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
flightDate VARCHAR(20),flightTime VARCHAR(10),
flightNumber VARCHAR(10), startCity VARCHAR(50),
endCity VARCHAR(50), friendliness TINYINT,
luggageSpace TINYINT, seatComfort TINYINT,
cleanliness TINYINT, noiseLevel TINYINT)";
if(mysql_query($SQLstring, $DBConnect)){
echo "
Table created successfully.";
?>
Go to the Survey Page
}else {
echo mysql_error($DBConnect);
}
}
mysql_close($DBConnect);
?>
Second File:
$ShowForm = FALSE;
$Values = array('flightDate', 'flightTime', 'flightNumber',
'startCity', 'endCity', 'friendliness', 'luggageSpace',
'seatComfort', 'cleanliness', 'noiseLevel');
$Ratings = array('0', '1_star', '2_star', '3_star', '4_star', '5_star');
$Survey = array();
foreach($Values as $Value)
$Survey[$Value] = "";
if(isset($_POST['submit'])){
foreach($Values as $Value){
if((!isset($_POST[$Value])) || strlen(trim($_POST[$Value])) == 0 ){
echo "$Value is a required field. ";
$ShowForm = TRUE;
} else if(($Value == 'flightDate') && (preg_match('/^\d{4}-\d{1,2}$/', $_POST[$Value]) == 0)){
echo "'$Value' must be in the form yyyy-mm-dd! ";
$ShowForm = TRUE;
} else if(($Value == 'flightTime') && (preg_match('/^\d{1,2}:\d{2}*[ap]m$/i', $_POST[$Value]) == 0)){
echo "'$Value' must be in the form hh:mm AM/PM! ";
$ShowForm = TRUE;
} else {
$Survey[$Value] = stripslashes(trim($_POST[$Value]));
}
}
if($ShowForm === FALSE){
$DBConnect = mysql_connect("localhost", "root", "root", "airlinesurvey");
if($DBConnect === FALSE){
die("Unable to connect to the database");
} else {
$Date = stripslashes($_POST['flightDate']);
$Time = stripslashes($_POST['flightTime']);
$Number = stripslashes($_POST['flightNumber']);
$StartCity = stripslashes($_POST['startCity']);
$EndCity = stripslashes($_POST['endCityn']);
$Friend = stripslashes($_POST['friendliness']);
$Space = stripslashes($_POST['luggageSpace']);
$Comfort = stripslashes($_POST['seatComfort']);
$Clean = stripslashes($_POST['cleanliness']);
$Level = stripcslashes($_POST['noiseLevel']);
$SQLstring = "INSERT INTO surveyreport (flightDate, flightTime, flightNumber,
startCity, endCity, friendliness, luggageSpace, seatComfort, cleanliness,
noiseLevel) VALUES ($Date, $Time, $Number, $StartCity, $EndCity, Friend,
$Space, $Comfort, $Clean, $Level";
if(mysql_query($SQLstring, $DBConnect)){
echo "Records inserted successfully.";
} else {
echo "Records not inserted.";
}
}
mysql_close($DBConnect);
}
} else {
$ShowForm = TRUE;
}
if($ShowForm === TRUE){
?>
}
for($i=1;$i
echo "".$Ratings[$i]." ";
}
echo " ";
?>
Friendliness of customer staff
for($i=1;$i
if($Survey['friendliness'] == $i){
echo "checked='checked'";
echo "/> ";
}
echo " ";
}
?>
Space for luggage storage
for($i=1;$i
if($Survey['friendliness'] == $i){
echo "checked='checked'";
echo "/> ";
}
echo " ";
}
?>
Comfort of seating
for($i=1;$i
if($Survey['friendliness'] == $i){
echo "checked='checked'";
echo "/> ";
}
echo " ";
}
?>
Cleanliness of aircraft
for($i=1;$i
if($Survey['friendliness'] == $i){
echo "checked='checked'";
echo "/> ";
}
echo " ";
}
?>
Noise level of aircraft
for($i=1;$i
if($Survey['friendliness'] == $i){
echo "checked='checked'";
echo "/> ";
}
echo " ";
}
?>
View All Surveys
Third File:
$ShowForm = FALSE;
$Values = array('Survey_ID');
$Survey = array();
foreach($Values as $Value)
$Survey[$Value]="";
if(isset($_POST['submit'])){
foreach($Values as $Value){
if((!isset($_POST[$Value])) || (strlen(trim($_POST[$Value]))) == 0 ){
echo "'$Value' is a required value. ";
$ShowForm = TRUE;
} else {
$Survey[$Value]=stripslashes(trim($_POST[$Value]));
}
}
if($ShowForm === FALSE){
if(empty($_POST['Survey_ID']))
echo "Enter all the values. Click your browser's Back button to return to the form.";
} else {
$DBConnect = mysql_connect("localhost", "root", "root", "airlinesurvey");
if($DBConnect === FALSE){
die("Unable to connect to the database.");
} else {
$ID = stripslashes($_POST['Survey_ID']);
$SQLstring = "SELECT * FROM surveyreport WHERE Survey_ID = '$ID'";
$QueryResult = @mysql_query($SQLstring, $DBConnect);
if(@mysql_num_rows($QueryResult) > 0){
while(($Row = mysql_fetch_assoc($QueryResult))){
echo "Flight Date: ".$Row['flightDate']."";
echo "Flight Time: ".$Row['flightTime']."";
echo "Flight Number: ".$Row['flightNumber']."";
echo "Start City: ".$Row['startCity']."";
echo "End City: ".$Row['endCity']."";
echo "Friendliness: ".$Row['friendliness']."_star";
echo "Luggage Space: ".$Row['luggageSpace']."_star";
echo "Seat Comfort: ".$Row['seatComfort']."_star";
echo "Cleanliness: ".$Row['cleanliness']."_star";
echo "Noise Level: ".$Row['noiseLevel']."_star";
}
} else {
echo "No results found.";
}
}
mysql_close($DBConnect);
}
} else {
$ShowForm = TRUE;
}
?>
I tried using the solution provided by Chegg but it wasn't working for me.
Enter a New Airline Survey Airline Suivev Entrv Notice: Undefined offset 5 in C:lwamp wwwEnterAirlineSuveyData php on line 104 Flight Date 2010-12-23 Flight Time 10:30 AMmust be in the form hhzmm AMPM) (must be in the form yyy-mm-dd) Flight Number 325 Airline SunCoast Starting City Denver Ending City Chicago Poor Fair Good Excellent Friendliness of customer staf C Space for luggage storage C Comfort of seating Cleanliness of aircraft C Noise level of aircraft Clear Form Submit View All Surveys
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
