Jump to content

unable to access and return a single value from a table


farris

Recommended Posts

this is for a login script...just letting you know so the variables make sense...

im trying to access a database and pull out the column "usercode" when the username and userpassword on a row is found

[code]<?php
// Database connection information
include('../Connections/databaseconnect.php');

// Puts user input into variables
$loginusername= $_POST[loginusername];
$loginuserpassword= $_POST[loginuserpassword];

//MySQL query string that points to the usercode information that we want so that we can put it into a cookie
$finduser= "SELECT usercode FROM users WHERE username = '$loginusername' AND userpassword = '$loginuserpassoword'";

//Selects database and returns an error if it doesn't work
mysql_select_db($db_database,$conn) or die(mysql_error());


//Puts MySQL query into a variable
$result = mysql_query("$finduser");

//Pulls information from the array and displays it
while($row = mysql_fetch_array($result))
  {
  echo $row['usercode'] . "<br>";
  }
?>[/code]

i tried the query directly on mysql and it returns the variable that i want without any problems
i had originally tried to echo $result directly but i ran into the resource id #4 problem and when i researched that i found out about fetch array

ive been trying to learn php for about a month and mysql for about 3 weeks so this could be something i just keep looking right over and not paying attention
Link to comment
Share on other sites

it still doesnt return anything

i tried echoing the 2 login variables and they came back correctly so all the information is being passed correctly from the previous page and the registration page uses the same database file to connect so that must be correct to
just thought id rule out those 2 sources of error
Link to comment
Share on other sites

Did you try to echo your query to see what it looks like?
I don't know much about select a db but I don't have the $conn when I do it.
I just do it this way
mysql_select_db("database_name");

Other then tha I am not sure it all looks good to me :(

Stephen
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.