Вопрос

I have a form where the user inputs their ID and this then populates their name from a database? There is a whole form I just copied the relevant parts and the sql below.

User ID: <input value="User ID" name="user_id">

$sql = "SELECT user_firstname, user_surname FROM users_tbl WHERE xxxx = users_tbl.user_id"
$result = pg_query($sql);

I have made it this far, but im not sure what to do.

Это было полезно?

Решение 2

You probably want something like ...

page1.php

<form method="POST" action="page2.php">
User ID: <input name="user_id" value="User ID">
<input type="submit" value="go">
</form>

page2.php

$id = mysql_escape_string( $_POST['user_id'] );
$sql = "SELECT `user_firstname`, `user_surname` FROM `users_tbl `WHERE `id` = '$id' LIMIT 1";
...

Другие советы

You should filter GET or POST form variables. So the right way would be:

$sql = "SELECT user_firstname, user_surname FROM users_tbl WHERE users_tbl.user_id= ".$_POST['user_id'];
$result = pg_query($sql);

Also don't forget to filter POST and GET variables from sql injections

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top