Jump to content

kojote

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

kojote's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Oh, I assume that error is because your 3 tables have a different numbers of columns and using UNION ALL on them would first make a big table with all three of those tables in, but because "SELECT * FROM" returns all columns, and there's a different number of columns, it errors. Change it to this instead $sql="SELECT userName FROM customer UNION ALL SELECT userName FROM admin UNION ALL SELECT userName FROM staff WHERE userName ='$myusername' and password='$mypassword;'"; It's recommended that you always try out your SQL by, in your database in phpmyadmin, selecting SQL and pasting your query there (with variables changed to test values), then running and see what it returns. In this case you'd have to try something like SELECT userName FROM customer UNION ALL SELECT userName FROM admin UNION ALL SELECT userName FROM staff WHERE userName ='admin' and password='test'; You still have a variable $tablename declared in the beginning btw, but now you are using those names directly in your query so you might as well remove that. =P
  2. No, mysql_query() returns the resulting table from the SELECT query, not a boolean. Those parts of the code are correct. mysql_query returns a boolean FALSE upon error, and a mysql result resource otherwise. Pardon, what I meant to say was that using that function on a correct SELECT query, it returns the result of the query, and not just a "did it work?" boolean. But I forgot that in this error, the mysql_num_rows() function has no resource as parameter, which means the result of the mysql_query() was false anyway and the error lies in the SQL query. I think my edit of the query should fix this.
  3. No, mysql_query() returns the resulting table from the SELECT query, not a boolean. Those parts of the code are correct.
  4. I see you are trying to find out if the user already exists in 3 different tables, but the way you handle this is a bit incorrect. This is what the SQL query would look like generated by your php: SELECT * FROM customer, admin, staff WHERE username='$myusername' and password='$mypassword'"; But you are handling this query in a wrong way as you would now get the cartesian result (for every row in table1 - show every row in table2). You should instead union the tables together like this: SELECT * FROM customer UNION ALL SELECT * FROM admin UNION ALL SELECT * FROM staff WHERE username='$myusername' and password='$mypassword'"; And as said, keep your information in a global $_SESSION array. Also, not that this is faulty perse, but there is no need to use double quotes around your variables in the following lines of code, as those variables are already declared as strings. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB");
  5. If there's an error with your SQL query, it might be easier to have the query as created in your php echo'd on your webpage and then copy/paste it and execute it directly in your database, then find the error. I see you use single quotes around your values that have to be putten in a numeric column (like privilege I assume) as well, this could potentially lead to an error. Try keep in mind the value of the variable you try to insert and the value of the column type you want to put it in.
×
×
  • 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.