e the same code with a different logic make sure you have the same output. ";    exit(); } include "dbconfig.php"; $conn = new mysqli($hostname, $username, $password, $dbname) or die($conn->connect_error); $name = $_POST['name']; $description = mysqli_real_escape_string($conn

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
  • Rewrite the same code with a different logic make sure you have the same output.

<?php
$cookie_name = "user";
$userID = $_COOKIE[$cookie_name];
if(!isset($_COOKIE[$cookie_name])){
   echo "Please login in first!<br>";
   exit();
}

include "dbconfig.php";
$conn = new mysqli($hostname, $username, $password, $dbname) or die($conn->connect_error);
$name = $_POST['name'];
$description = mysqli_real_escape_string($conn, $_POST['description']);
$term = mysqli_real_escape_string($conn, $_POST['term']);
$enrollment = $_POST['enrollment'];
//Query course name
$Rid = '';
$userGivenFacultyID = $_POST['Fid'];
$userGivenRoom = $_POST['Rid'];
$queryRid = "SELECT Rid FROM TECH3740.Rooms WHERE CONCAT(Building,Number) like '%$userGivenRoom%' ";
$resultRid = mysqli_query($conn, $queryRid);
$rid_row_ct = $resultRid->num_rows;
if($rid_row_ct = 1){
while($ridRow = $resultRid->fetch_assoc()){
$Rid = $ridRow['Rid'];
}
}

$queryRoomSize = "SELECT Size FROM TECH3740.Rooms WHERE Rid = $Rid";
$resultRoomSize = mysqli_query($conn, $queryRoomSize);
$roomSize_row_ct = $resultRoomSize->num_rows;
if($roomSize_row_ct = 1){
while($roomSizeRow = $resultRoomSize->fetch_assoc()){
$roomSize = $roomSizeRow['Size'];
}
}
if($enrollment <= 0){
   echo "Enrollment has to be greater than 0" ;
}

else if ($enrollment > $roomSize) {
   echo "Room size has to be greater than Enrollment Size" ;
}

else if($userGivenFacultyID == NULL){
   echo "Please select faculty";
}

else if($ _POST['Rid'] == NULL){
   echo "Please select Room";
}

else {
   //Query course name
   $queryCourseName = "SELECT name FROM TECH3740_2021F.Courses_joe WHERE name like '%$name%' ";
   $resultCourse = mysqli_query($conn, $queryCourseName);
   $course_row_ct = $resultCourse->num_rows;
   //Checks if course name exist
   if($course_row_ct > 0){
       echo "Cannot have the same Course name";
   }
   else{
       echo "<a href = 'logout.php'>Logout</a><br>";
       $insert = "INSERT into TECH3740_2021F.Courses_joe (name, description, term, enrollment, Fid, Rid, aid) Values ('$name', '$description', '$term','$enrollment', '$userGivenFacultyID', '$Rid', '$userID') ";
       $enter = mysqli_query($conn, $insert);
       if($enter){
           echo "Course $name has been added successfully";
       }
       else{
       echo "Course $name has not been added successfully <br> Description: $description <br> Term: $term <br> Enrollment: $enrollment <br> FID: $userGivenFacultyID <br> RID: $Rid <br> AID: $userID";
       }
      
   }
}
mysqli_close($conn);

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY