Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using this code, create a php file that inserts the results to this survey into

ID: 3861872 • Letter: U

Question

using this code, create a php file that inserts the results to this survey into a table (mysql database) called studsurv1. The table has the column names of: college, cclass, cyear, havetv, havecable, havephone, havewindows, haveapple, havelinux, haveoffice, q1, q2 , q3   

<html>

<head>

<title> Survey Project 3 </title>

<link rel = "stylesheet" type= "text/css" href="main.css">

<form method="post" action="survey_Results.php">

</head>

<body>

<h1> Student Computing and Communication Equipment Survey </h1>

<div id= "Para1">

<p> Your feedback on the kind of devices that students use helps us understand computing and networking needs. Please answer all questions thoughtfully. </p>

</div>

College/University Name:

<input type="text" name="college">

Class:

<select name= "cclass">

<option value= "freshman">Freshman</option>

<option value= "sophomore">Sophomore</option>

<option value= "junior">Junior</option>

<option value= "senior">Senior</option>

</select>

Expected Graduation Year:

<select name="cyear">

<option value="year1">2017</option>

<option value="year2">2018</option>

<option value="year3">2019</option>

<option value="year4">2020</option>

</select>

<br>

<br>

<div id="para2">

<p> <center> What kind of media and computers do you have at home? </center> </p>

</div>

<input type="checkbox" name= "havetv" value="cable"> Cable, FIOS, or SatelliteTV<br>

<input type="checkbox" name= "havecable" value="internet"> High speed internet (e.g. cable, FIOS)<br>

<input type="checkbox" name= "havephone" value= "smartphone"> Smartphone<br>

<input type="checkbox" name= "havewindows" value= "windows"> Windows Computer<br>

<input type="checkbox" name= "havepaple" value= "apple"> Apple Computer<br>

<input type="checkbox" name= "haveoffice" value= "office"> MS Office 2010

<br>

<br>

<div id= "Para3">

<p> Please Select the number which most accurately expresses your degree of agreement with each of the following statements </p>

</div>

1. I like my computer <br>

<input type="radio" name= "q1" value = "Strongly Agree"> Strongly Agree

<input type="radio" name= "q1" value= "Agree"> Agree

2. I would rather use my smartphone or a tablet instead of a computer <br>

<input type="radio" name="q2" value= "Strongly Agree"> Strongly Agree

<input type="radio" name="q2" value= "Agree"> Agree

<input type= "radio" name= "q2" value= "Undecided"> Undecided

<input type="radio" name= "q2" value= "Disagree"> Disagree

<input type="radio" name= "q2" value= "Strongly Disagree"> Strongly Disagree<br>

3. I like the Operating System on my computer whether it's MAC, Linux, or Windows <br>

<input type= "radio" name= "q3" value= "Strongly Agree"> Strongly Agree

<input type= "radio" name= "q3" value= "Agree"> Agree

<input type= "radio" name= "q3" value= "Undecided"> Undecided

<input type="radio" name= "q3" value= "Disagree"> Disagree

<input type="radio" name= "q3" value= "Strongly Disagree"> Strongly Disagree<br>

</form>

<input type="submit" value="Submit">

</form>

</html>

Explanation / Answer

survey_Results.php

<?php
if($_POST['college']=' '){
   $college = '--';
} else {
   $college = $_POST['college'];
}

if($_POST['cclass']=' '){
   $cclass = '--';
} else {
   $cclass = $_POST['cclass'];
}
if($_POST['cyear']=' '){
   $cyear = '--';
} else {
   $cyear = $_POST['cyear'];
}
if($_POST['havetv']=' '){
   $havetv = '--';
} else {
   $havetv = $_POST['havetv'];
}
if($_POST['havecable']=' '){
   $havecable = '--';
} else {
   $havecable = $_POST['havecable'];
}
if($_POST['havephone']=' '){
   $havephone = '--';
} else {
   $havephone = $_POST['havephone'];
}
if($_POST['havewindows']=' '){
   $havewindows = '--';
} else {
   $havewindows = $_POST['havewindows'];
}

if($_POST['havepaple']=' '){
   $havepaple = '--';
} else {
   $havepaple = $_POST['havepaple'];
}

if($_POST['haveoffice']=' '){
   $haveoffice = '--';
} else {
   $haveoffice = $_POST['haveoffice'];
}

if($_POST['q1']=' '){
   $q1 = '--';
} else {
   $q1 = $_POST['q1'];
}

if($_POST['q2']=' '){
   $q2 = '--';
} else {
   $q2 = $_POST['q2'];
}

if($_POST['q3']= ' '){
   $q3 = '--';
} else {
   $q3 = $_POST['q3'];
}


$servername = "localhost";
$username = "bhava";
$password = "bhava123";

// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// Create database
$sql = "CREATE DATABASE studDB";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully";
} else {
echo "Error creating database: " . $conn->error;
}


$sql = "CREATE TABLE studsurv1 (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
college VARCHAR(30) NOT NULL,
cclass VARCHAR(30) NOT NULL,
cyear INT(6),
cclass VARCHAR(30) NOT NULL,
havetv VARCHAR(30) NOT NULL,
havecable VARCHAR(30) NOT NULL,
havephone VARCHAR(30) NOT NULL,
havewindows VARCHAR(30) NOT NULL,
haveapple VARCHAR(30) NOT NULL,
havelinux VARCHAR(30) NOT NULL,
haveoffice VARCHAR(30) NOT NULL,
q1 VARCHAR(30) NOT NULL,
q2 VARCHAR(30) NOT NULL,
q3 VARCHAR(30) NOT NULL,
reg_date TIMESTAMP
)";
if ($conn->query($sql) === TRUE) {
echo "Table studsurv1 created successfully";
} else {
echo "Error creating table: " . $conn->error;
}


$sql = "INSERT INTO studsurv1 (college, cclass, cyear,havetv,havecable,havephone,havewindows,havepaple,haveoffice,q1,q2,q3)
VALUES ('$college ','$cclass ','$cyear','$havetv','$havecable','$havephone','$havewindows','$havepaple','$haveoffice',$q1','$q2','$q3',)";

if ($conn->query($sql) === TRUE) {
echo "Inserted successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>