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

I need help showing the first column of the table to show up exactly with the my

ID: 3582631 • Letter: I

Question

I need help showing the first column of the table to show up exactly with the mysql table into the php page. Is there a way to fix it ?

So I created a php form where the user enters the information. sand.truman.edu/~jyl6557/assignment5/hw5-dataentry.php . it asks for name, hometown, gender(only male and female) and status (freshman, sophmore, junior, senior). once it checks and passes through those tests, it would say added successfully and then show the links to add another enry or display the table.

here is the data entry page code:





Submission Form

// form with questions
function printform()
{
echo <<

Fill out the Information

Name:


Hometown:


Gender:


Year-status:











Info


END;
}
function process_form()
{
//local variables
$hostname='mysql.truman.edu';
$username='jyl6557';
$password='obookevo';
$db='jyl6557CS315';
$name=$_POST['Name'];
$hometown=$_POST['hometown'];
$gender=$_POST['gender'];
$status=$_POST['status'];


$connectDB=new PDO("mysql:host=$hostname;dbname=$db", $username,$password);

$sql_insert=$connectDB->prepare( "INSERT INTO People(Name, hometown, gender, status) VALUES (:Name, :hometown, :gender, :status)");
$sql_insert->bindParam(':Name',$name);
$sql_insert->bindParam(':hometown',$hometown);
$sql_insert->bindParam(':gender',$gender);
$sql_insert->bindParam(':status',$status);
$sql_insert->execute();

". $e->getMessage();

$connectDB=null;

echo <<

Added


ADD another entry
END;
}
//main program
if(isset($_POST['Submit']))
{
//matches any set of letters and specific words.
   $nameregrex="/^[A-z_-]/";
   $hometownregrex="/^[A-z_-]/";
   $genderregrex="/(M|f)emale|(M|m)ale/";
   $statusregrex="/(F|f)freshman|(S|s)ophmore|(J|j)unior|(S|s)enior/";
if(preg_match($nameregrex, $_POST['Name']) && preg_match($hometownregrex, $_POST['hometown']) && preg_match($genderregrex, $_POST['gender'])
&& preg_match($statusregrex, $_POST['status']))
{

echo << Add another entry


Display table
END;

process_form();
}
}
else
{
printform();
}

?>

the table that suppose to be like this:

here is the display table code pulled from mysql table:


Student Information Form



   
  

     
//sorts and displays data
function doGetAll($connectDB)
{
$sortby="name";
$sql="SELECT * from People order by $sortby";
$result=$connectDB->query($sql) or die ("mysql failed");
echo <<

List of students


END;

foreach ($result as $r)
{
extract($r);
print"

";
}
print"

";
echo <<

Successfully added


Add another information
END;
}
//connects to database
$hostname='mysql.truman.edu';
$username='jyl6557';
$password='obookevo';
$dbname='jyl6557CS315';
$connectDB= new PDO("mysql:host=$hostname;dbname=$dbname" ,$username,$password);

if(!$connectDB)
{
print "Error";
exit;
}
doGetAll($connectDB);

?>


   

Name hometown gender status john kansas city male senior bob matthews kirksville male freshman

Explanation / Answer

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote