0

I'm trying to use HTML, PHP and MYSQL to pull data from a database and display it in a form (to later be edited). At this point I'm only trying to pull that data and display it in a form. (I'll worry about updating later). I pull the data but nothing displays in my textboxes:

<?php 
$con = mysqli_connect("XXXXX");   //removed for privacy

if (mysqli_connect_errno())
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$query="select * from VOLUNTEER";
echo '$query';
$result = mysqli_query($con, $query);

echo "<table>";

if ($result)                                   
{                        
    while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) 
{
    echo '<form method = "post" action="insertvolunteer.php">';
    echo '<tr>';
    echo '<td>First Name:</td>';
    echo '<td>' . '<input type=text name=FirstName' . $row["FirstName"] . '</td>';
    echo '<td>' . '<input type=hidden name=VolunteerId' . $row["VolunteerId"] .  '</td>';
echo '</tr>';
}
}
 echo "</form>";
 echo "</table>";                             
 mysqli_close($con);
 ?>
1
  • Where is mysqli_select_db() ? did you passed database in mysqli_connect ? Commented Apr 27, 2014 at 17:35

2 Answers 2

2

Text box data needs to be displayed on value as

echo '<td><input type="text" name="FirstName" value="'.$row["FirstName"].'"></td>';
Sign up to request clarification or add additional context in comments.

Comments

0

connect.php

<?php

$server = "server";
$user = "user";
$password = "password";
$bd = "yourbd";

$connect = mysql_connect($server, $user, $password);
$connect = mysql_select_db("$bd", $connect);

if  (!$connect){
echo mysql_error(); exit;
}

?>

namefile.php

<?php
include('connect.php');

    $select = mysql_query("select * from VOLUNTEER");

    while ($show  = mysql_fetch_assoc($select)):

    echo "<table>";
    echo "<form method = 'post' action='insertvolunteer.php'>";
     echo '<tr>';
    echo '<td>First Name:</td>';
    echo '<td><input type="text" name="FirstName" value="'.$show["FirstName"].'"></td>';
    echo '<td><input type="text" name="FirstName" value="'.$show["VolunteerId"].'"></td>';
    echo '</tr>';
    echo "</form";
    echo "</table>";

    endwhile;

?>

When you create an MySQL query, you need to declare this. How?

$var = "SELECT * FROM SOMEWHERE"; wrong

$var = mysql_query("SELECT * FROM SOMEWHERE"); right

'n in echo '<td>' . '<input type=text name=FirstName' . $row["FirstName"] . '</td>';, you need to close the tag. And also have no need of separate <td> of <input>.

Try something like :)

@update I realized that you've got what was wished. Cheers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.