made $_SESSION[] data into php variable but it still won't work in a mysql query -
i have trouble checking $_session variable on mysql query. want details of user logged in, appears not working properly.
i have $user = mysql_real_escape_string($_session['username']);
puts code regular variable, , make query database is:$sql = "select * admin username='$user' limit 1";
and count if user exists use code: $usercount = mysql_num_rows($sql); // count output amount
this not seem work. keep getting error: "warning: mysql_num_rows() expects parameter 1 resource, string given in /home/alexartl/public_html/crm/headercode.php on line 18"
and way, user account exist , logged in when have been testing below full code
// if session vars aren't set, try set them cookie if (!isset($_session['user_id'])) { if (isset($_cookie['user_id']) && isset($_cookie['username'])) { $_session['user_id'] = $_cookie['user_id']; $_session['username'] = $_cookie['username']; } } ?> <?php //if username set if (isset($_session['username'])) { //making username php variable $user = mysql_real_escape_string($_session['username']); //the query grab users name $sql = "select * admin username='$user' limit 1"; $usercount = mysql_num_rows($sql); // count output amount if ($usercount == 1) { while($row = mysql_fetch_array($sql)){ //just array grabs users info $username = $row["username"]; $password = $row["password"]; $first_name = $row["first_name"]; $last_name = $row["last_name"]; $gender = $row["gender"]; $birthdate = $row["birthdate"]; $email_address = $row["email_address"]; $city = $row["city"]; $state = $row["state"]; $retrieval = $row["retrieval"]; $isadmin = $row["isadmin"]; $join_date = $row["join_date"]; //if user has "isadmin" "yes", link "manage users" page appear if($isadmin == "yes"){ $ifadmin = '<li><a href="manageusers.php">manage users</a></li>'; } } } } ?>
i won't "don't use mysql_* commands", don't :p
you missing:
$result = mysql_query($sql); //actually execute query
then use
$usercount = mysql_num_rows($result); // count output amount
separately, don't seem connect to, or use
database wish query.
$link = mysql_connect('localhost', 'user', 'pass') or die('could not connect mysql server.' ); mysql_select_db('databasename');
Comments
Post a Comment