allendks45 allendks45 - 2 years ago 98
PHP Question

how do i use php explode method for indexes that can be output to html?

Need help understanding how to use php explode method. Apologies if this question is vague. i want to search for student from his/her id and return their info in html textboxes. From what i have read I need to explode the array produced into separate variables and then call the variables in my html. Can someone explain this method? PHP manual didn't help me.

$host = "localhost";
$dbname = "studentInfo_db";
$user = "George Jetson";
$password = "stopthisthing";

try {
$db = new PDO("mysql:dbname=$dbname; host=$host", $user, $password);

catch (PDOException $e) {
$error_message = $e->getMessage();
include ('database_error.php');

//get student id from text box
if(!isset($studentID)) {
$studentID = filter_input(INPUT_GET, 'studentID', FILTER_VALIDATE_INT);
if($studentID == NULL || $studentID == FALSE) {
$studentID = 1;
//prepare query
$query = 'SELECT * FROM student
WHERE studentID = :studentID';
$statement = $db->prepare($query);
$statement->bindValue(':studentID', $studentID);
$result = $statement->fetch(PDO::FETCH_ASSOC); //how do i get the individual values from query into textboxes?

echo $result['studentID']; //is this correct??
echo $result['name'];
echo $result['email'];
echo $result['GPA'];


Answer Source

I will give it a try

 <input type="text" name="fname" value='<?php echo $result["studentID"]; ?> '>

And so on.

EDIT: oops, didn't close the php tag. Sorry.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download