thewooleymammoth Posted October 20, 2008 Share Posted October 20, 2008 i need to run a query to tell me the type of account the person has the only thing i can think of is... "SELECT type FROM users WHERE email = '$username'" and it returns '0' although there is a type for each one and i can see there is on phpmyadmin and i cant find the proper syntax on any tutorials or anything. the correct code would really help thanks Quote Link to comment https://forums.phpfreaks.com/topic/129187-solved-dont-know-mysql-sytnax-at-all/ Share on other sites More sharing options...
dropfaith Posted October 20, 2008 Share Posted October 20, 2008 is username defined anywhere?? $Name = mysql_escape_string($_GET['Name']); $query = "SELECT * FROM Art WHERE Name = '$Name'"; Quote Link to comment https://forums.phpfreaks.com/topic/129187-solved-dont-know-mysql-sytnax-at-all/#findComment-669771 Share on other sites More sharing options...
revraz Posted October 20, 2008 Share Posted October 20, 2008 Chances are $username is not coming over, so you are sending a bad query. One way to tell is to put the query in a variable and echo it. Are you sure $username is the right variable? Since you are checking the email field, is the email the same as the $username? Other than that, your syntax is correct. Quote Link to comment https://forums.phpfreaks.com/topic/129187-solved-dont-know-mysql-sytnax-at-all/#findComment-669981 Share on other sites More sharing options...
Maq Posted October 20, 2008 Share Posted October 20, 2008 Paste the code before this, where you actually assign $username its value. Quote Link to comment https://forums.phpfreaks.com/topic/129187-solved-dont-know-mysql-sytnax-at-all/#findComment-669989 Share on other sites More sharing options...
thewooleymammoth Posted October 20, 2008 Author Share Posted October 20, 2008 $username= mysql_escape_string(strip_tags($_POST['username'])); $password= mysql_escape_string(strip_tags($_POST['password'])); $q = "SELECT email FROM musicusers WHERE email = '$username' AND password = '$password'"; $q2="SELECT type FROM musicusers WHERE email = '$username'"; if (mysql_num_rows(mysql_query($q))) { $_SESSION['type']=mysql_query($q2); $_SESSION['username'] = $username; $type=$_SESSION['type']; echo $type; } this is the login page, i changed it around a little bit and im not getting '0' anymore im getting Resource id #8 ive included a print screen from php my admin with the data included in the table [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/129187-solved-dont-know-mysql-sytnax-at-all/#findComment-670079 Share on other sites More sharing options...
dropfaith Posted October 20, 2008 Share Posted October 20, 2008 if im not mistaken or missing some other code why are you running two querys for this just select * from musicusers WHERE email = '$username' AND password = '$password'"; will get all fields or just seperate fileds with a comma email, type $username= mysql_escape_string(strip_tags($_POST['username'])); $password= mysql_escape_string(strip_tags($_POST['password'])); $q = "SELECT * FROM musicusers WHERE email = '$username' AND password = '$password'"; if (mysql_num_rows(mysql_query($q))) { $_SESSION['type']=mysql_query($q); $_SESSION['username'] = $username; $type=$_SESSION['type']; echo $type; } Quote Link to comment https://forums.phpfreaks.com/topic/129187-solved-dont-know-mysql-sytnax-at-all/#findComment-670089 Share on other sites More sharing options...
thewooleymammoth Posted October 20, 2008 Author Share Posted October 20, 2008 now my code looks like this $username= mysql_escape_string(strip_tags($_POST['username'])); $password= mysql_escape_string(strip_tags($_POST['password'])); //$q = "SELECT email, type FROM musicusers WHERE email = '$username' AND password = '$password'"; $q="SELECT * FROM musicusers WHERE email = '$username' AND password = '$password'"; //$q2="SELECT type FROM musicusers WHERE email = '$username'"; if (mysql_num_rows(mysql_query($q))) { $_SESSION['type']=mysql_query($q); $_SESSION['username'] = $username; $type=$_SESSION['type']; echo $type."<br>"; echo $username."<br>"; } and the output is Resource id #8 5wooley4@gmail.com Quote Link to comment https://forums.phpfreaks.com/topic/129187-solved-dont-know-mysql-sytnax-at-all/#findComment-670097 Share on other sites More sharing options...
thewooleymammoth Posted October 20, 2008 Author Share Posted October 20, 2008 by the way im trying to get $type to = 'artist' idk if i made that clear Quote Link to comment https://forums.phpfreaks.com/topic/129187-solved-dont-know-mysql-sytnax-at-all/#findComment-670120 Share on other sites More sharing options...
thewooleymammoth Posted October 20, 2008 Author Share Posted October 20, 2008 for whatever reason (after a ton of playing around and searching) this works $q="SELECT * FROM musicusers WHERE email = '$username' AND password = '$password'"; $q2="SELECT type FROM musicusers WHERE email = '$username'"; if (mysql_num_rows(mysql_query($q))) { $last=mysql_query($q2); $type=mysql_fetch_assoc($last); $_SESSION['username'] = $username; $_SESSION['type']=$type; foreach($type as $b) { if ($b != '') { $_SESSION['type']=$b; } } which makes $_SESSION['type']=to the account type Quote Link to comment https://forums.phpfreaks.com/topic/129187-solved-dont-know-mysql-sytnax-at-all/#findComment-670131 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.