MrFish Posted June 23, 2009 Report Share Posted June 23, 2009 (edited) I think it's called a field. I'm trying to get the information from a field where the username is "MrFish" and I want to make it a cookie. I followed the w3c tutorials best I could and tried multiple ways but none of them worked. Here is what I'm trying- ///////////////////After successfully "logging in" (finding a username/password match), this script is executed to set the cookies. /* Login Success */ /* Set Expiration Date */ $expdate = time()+(60*60*24*30); /* 30 days*/ /* Find ID */ $queryinput = 'SELECT id FROM users WHERE username =\'' . $username . '\''; $results = mysql_query($queryinput); $id = mysql_fetch_field($results); /* WHAT DO I PUT HERE? NOTHING WORKS D:*/ /* Set Cookie */ setCookie("id", $id, $expdate); setCookie("username", $username, $expdate); echo '<script type="text/javascript">'; echo 'alert("' . $_COOKIE["username"] . $id . '");';////////////////Temporary Debugging element echo '</script>'; The username successfully became a cookie. But the id is giving me errors. How do I get the field value correctly? Edited June 23, 2009 by MrFish Link to comment Share on other sites More sharing options...
justsomeguy Posted June 23, 2009 Report Share Posted June 23, 2009 mysql_fetch_field isn't going to give the value of a field, it gets information about that field in the database (the name of it, the data type, length, etc). If you want the value you should get the row from the result, and then you can get the value from the row. $queryinput = 'SELECT id FROM users WHERE username =\'' . $username . '\'';$results = mysql_query($queryinput);if ($row = mysql_fetch_assoc($results)) $id = $row['id'];else echo 'user not found'; Link to comment Share on other sites More sharing options...
duncan_cowan Posted June 23, 2009 Report Share Posted June 23, 2009 I think: ///////////////////After successfully "logging in" (finding a username/password match), this script is executed to set the cookies. /* Login Success */ /* Set Expiration Date */ $expdate = time()+(60*60*24*30); /* 30 days*/ /* Find ID */ $queryinput = 'SELECT id FROM users WHERE username =\'' . $username . '\''; $results = mysql_query($queryinput); $array = mysql_fetch_array($results); $id = $array['id']; /* Set Cookie */ setCookie("id", $id, $expdate); setCookie("username", $username, $expdate); echo '<script type="text/javascript">'; echo 'alert("' . $_COOKIE["username"] . $id . '");';////////////////Temporary Debugging element echo '</script>'; Hope this helps. Link to comment Share on other sites More sharing options...
MrFish Posted June 23, 2009 Author Report Share Posted June 23, 2009 justsomeguy,It works! Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now