0

If I have a page that has a link <a href='edit_info.php?id=1001'>1001</a> and on the page edit_info.php I would like to use the id to make a query to a database, say

SELECT * FROM table WHERE id = $_GET['id']

Now I want to fill a bunch of text fields with the results. Must I do this all in the same php

('<?php //place all fields in an echo here ?>)

Or is there a way I can make the query and then in html pull the data from the query?

ex.

<?php //query and results here ?>

<html>
  <body>
   all my input fields w/ data here
 </body>
</html>

2 Answers 2

2

You'd be setting the input fields with the values from the query.

Example:

<input type="textbox" name="input_name" value="<?php print $valuefromquery; ?>">

And do for each of the results you'd like to display. Also use PDO /MySQLi to query the database.

Sign up to request clarification or add additional context in comments.

3 Comments

I always use mysqli but I have coded everything I am doing so far procedurally so i haven't used PDO.
@user2690363 All good :) I apologise for assuming you would've done it in mysql_* because you put the $_GET['id'] straight into the query.
@Phil Thats left up to the person to do, I answered the question as to how he would have the values display in the textbox.
0

You can put it all in one php file.

You can do the example you made. You can open <?php and close ?> php code in between your html or javascript. Just close and escape properly.

AND take note of XSS

AND AND you might also find php include useful. It helps when you are reusing php code . . like a dynamic personalized header maybe?

3 Comments

you mean mysqli_real_escape_string()? I am using. Am also using a header through include, or require_once() whichever shoe fits
not real escape string. thats for db queries. Im talking about php.net/manual/en/function.htmlspecialchars.php BTW you should learn prepared statements. MySQLi has them. It has a learning curve but once you get it right you would be more confident on your db queries.
So basically any time you're passing certain characters through the URL via GET you should use the special characters function so the link translates those special characters properly. Correct?

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.