MarlZ15199 MarlZ15199 - 7 months ago 14
PHP Question

Function not working with form element

Please be gentle with me I'm just a newbie. Please tell me what's wrong why this function is not working. There's no error, just blank page.

<?php

include("db.php");

$id = (integer)$_GET['id'];
echo $id;

function updateshowdata($stmt, $con){

$stmt = $con->prepare("SELECT `firstname` FROM `MyGuests` where id =?");
$stmt->bind_param ('i',$id);
$stmt->execute ();
$stmt->bind_result ($firstname);


$updateshow = "<form method='post' action='updateprocess.php'>";

while ($stmt->fetch()) {
$updateshow .= "<input type='text' name='firstname' value='{$firstname}' >";

}

$updateshow .= "</form>";

echo $updateshow;

}
updateshowdata($stmt, $con);

?>


If I change this into below removing function, it is starting to work

<?php

include("db.php");

$id = (integer)$_GET['id'];
echo $id;

$stmt = $con->prepare("SELECT `firstname` FROM `MyGuests` where id =?");
$stmt->bind_param ('i',$id);
$stmt->execute ();
$stmt->bind_result ($firstname);


$updateshow = "<form method='post' action='updateprocess.php'>";

while ($stmt->fetch()) {
$updateshow .= "<input type='text' name='firstname' value='{$firstname}' >";

}

$updateshow .= "</form>";

echo $updateshow;


?>

Answer

Does it works?

function updateshowdata($stmt, $con){
    $id = (int)$GET['id'];

    $stmt = $con->prepare("SELECT `firstname` FROM `MyGuests` where id =?");
    $stmt->bind_param ('i',$id);
    $stmt->execute ();
    $stmt->bind_result ($firstname);    


    $updateshow = "<form method='post' action='updateprocess.php'>";

    while ($stmt->fetch()) {
        $updateshow .= "<input type='text' name='firstname'      value='{$firstname}' >";

}