I have a MySQL DB that I want to call for the post ID, when the user is logged in. I already have the DB set up, but I can't have the form field pull the database. What would I do to call this logged in variable? I tried using $row['username']; , $username, everything, but nothing shows up in the field. Here's what I have: I have this in my INPUT field: value="<?php echo $_GET['user'];?>" That doesn't work. What should I do? Thanks
I'm guessing you're using a standard HTML form? If so, what method are you using to submit the form values (GET or POST?) I might be getting this around the wrong way but am assuming that you want to have $_user_name = to the form value submitted?
Sorry if I have not understood your problem, but this is what I see on your code: 1) $result = mysql_query("SELECT * FROM users WHERE username='" . $_user_name . "'") or die(mysql_error()); $row = mysql_fetch_array( $result ); You are using: $_user_name .... this var SHOULD be defined previously to the use. See the _ after the $ ... $_user_name is not the same as $user_name $user_name is the name of the user you use to connect to the database, so probably this sentence is wrong. 2) $_user = $_GET['user']; This has nothing to be with mysql. $_GET is only to get a param passed by: script.php?user=xxx or a form with method="get" I understand that: 1. you have the username (from a form post for example) To be sure that the name is get ok: <?php print_r($_POST); // This output the full POST vars, with their values ?> <?php print_r($_GET); // This output the full GET vars, with their values. The values are on params on the url or form with method=get ?> 2. Once you have the username, get the row from the DB $result = mysql_query("SELECT * FROM users WHERE username='" . $username . "'") or die(mysql_error()); $row = mysql_fetch_array( $result ); To see the full row (can be empty if there is no username with that name) ... <?php print_r($row); ?> 3. To use a value on this row $row['namefield'] namefield SHOULD BE THE NAME OF A FIELD OF THIS DB Please, respond with the exact code or explain me what are you trying to do step by step so I could understand and guide you.