<?php
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$keywords = $_POST['keywords'];
$description = $_POST['description'];
$user_id = $_GET['user_id'];
?>
I have a web form that needs to recognize the users id #. I have it set up where $user_id = $_GET['user_id'];
I also believe that I have the id retrieval code right. I made sure that the user_id
matched my table but I keep getting an error that says that user_id
is an unidentified index.
This means that user_id is not being sent in the headers; You are using both GET and POST in that code snippet, you can only send one at a time when doing a HTTP Request unless your form action has query string in it.
I believe what you could be doing is that on the page with your form, you have user_id set in the URL, however when that form is posted, you will loose all the query strings, so you need to do this;
<form action="/post.php?user_id=123" method="POST">
That should hopefully solve your issue.
did you change user_id retrieval to POST? it should be
$user_id = $_POST['user_id'];
if it still doesn't work check where you define the user_id for any typo errors.
Okay maybe i figure it out what do you want to point out. Do you want to get the user_id of a user that is already logged-in in your website/webpage, right? If so, then you must use this some code:
$_SESSION['user_id'] = $_POST['user_id'];
So that you can access the user's id wherever in the page. Hopes this helps.