Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/129187-solved-dont-know-mysql-sytnax-at-all/
Share on other sites

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.

$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]

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;
  }


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

 

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

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.