I get the value in the database and click on the id field how i past(get
) this field to other location can anyone help me

Dani AI

Generated

As asked about passing an ID to another page and pointed to using the query string, here are concise, practical best practices to make that work reliably and safely.

If the ID is non-sensitive and you want bookmarkable links, a URL parameter is fine. For anything sensitive or state-changing use POST or a server-side session. Never trust client input: always validate, escape before output, and enforce authorization on the receiving page.

Validate the incoming value (example using the filter API):

$id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
if ($id === false || $id === null) {
    http_response_code(400);
    exit('Invalid id');
}

See filter_input documentation: filter_input. When printing into HTML, escape or cast to int (see htmlspecialchars).

Use prepared statements for database access (PDO example):

$stmt = $pdo->prepare('SELECT * FROM items WHERE id = :id');
$stmt->execute([':id' => $id]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);

Reference: PDO prepared statements.

If you prefer to avoid showing the ID in the URL, store it in session and redirect:

session_start();
$_SESSION['item_id'] = $id;
header('Location: next_page.php');
exit;

Security notes: require ownership/authorization checks to prevent IDOR (see OWASP on IDOR: ), use CSRF tokens for actions that change data, and log/handle invalid attempts. 's basic idea is correct; add these validation, escaping, and authorization steps to make it robust.

Recommended Answers

All 3 Replies

Let's say you have the number 2 stored in the variable $id, meaning $id = 2 and you want to pass it to the next page, you would write something like this:

echo "<a href = 'next_page.php?id='".$id."'>Next Page</a>";

Now the value you passed to the next_page.php is stored in

$_GET['id'];

If this is not what you mean, please let me know.

Thank dear

If this is what you were looking please mark this thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.