0

So I have searched for how to insert items from a MySQL database into a form. From what I understand, for each field, I need to add value="<?php echo htmlentities($Variable); ?>" is there a way to insert the fields all at once? Like in a PHP script? Each field already has a name identifier, that's how the insert.php insert the values into the database, like this:

    //SQL Query to insert data
$sql="INSERT INTO case_info (Volunteer,CaseShortTitle,CaseNumber,HearingDate...)
VALUES ('$_POST[Volunteer]','$_POST[CaseShortTitle]','$_POST[CaseNumber]','$_POST[HearingDate]'...)

and the form fields look like this:

<div><input type="text" id="p1f5c" name="CaseShortTitle" class="fieldcontent"><div class="fielderror"></div></div>

Then the Submit button goes to this insert.php file

Is there a way to use GET to populate the fields in this manner?

Thank you!

0

1 Answer 1

1

It's generally bad practice to input data into your database directly from the $_POST variables, you should consider sanitizing them first.

If I understand what you are asking, you can do something like this;

<form action="" id="myForm" title="myForm">

        <?php
        $query = "SELECT * FROM case_info LIMIT 1";
        $result = myqsl_query($query) or die(mysql_error());
        while($row = mysql_fetch_array($result)){
        ?>
        <input type="text" id="volunteer" value="<?php echo $row['Volunteer']; ?>"
        <input type="text" id="CaseShortTitle" value="<?php echo $row['CaseShortTitle']; ?>"
        <?php
        } //Close while{} loop
        ?>

</form>
Sign up to request clarification or add additional context in comments.

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.