Jodarecode
06-18-2008, 12:51 PM
My issue is I cant seem to get the other tables data to display with out an error, I've tried JOIN and UNION and they dont seem to work.
tables:
-users
-formdata
"users" table:
userid
name
email
username
password
"formdata" table:
userid
fieldid
value
saveas
the script checks against username and password for the login and I need it to also SELECT saveas FROM "formdata" table, but the where clause is interfering with it and I tried every combination I can find regarding mysql the version.
Its not showing the syntax error but is showing my error because the username and password are not passing.
if (mysql_num_rows($result) != 1) {
echo "<font color='red'>Error, Please re-enter or register!</font>";
include "login.html";
Here is the whole code:
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
session_start();
$username = $_POST['username'];
$password = md5($_POST['password']);
$query = "SELECT *
FROM formdata RIGHT JOIN users ON users.userid = formdata.userid
WHERE username='".$username."' and password='".$password."'";
//the following passes but with out the formdata table: $query = "select * from users where username='$username' and password='$password'";
$result = mysql_query($query);
if (mysql_num_rows($result) != 1) {
$error = "Bad Login";
echo "<font color='red'>Error, Please re-enter or register!</font>";
include "login.html";
} else {
$_SESSION['username'] = "$username";
while($row = mysql_fetch_array($result))
{
echo "<p>", $row['userid']. " - <a href=\"\"> ". $row['saveas'], "</a>";
}
}
?>
This is the closest I've gotten, it passes the username/password but still doesn't display data "saveas" from the other table "formdata".
$query = "SELECT *
FROM formdata RIGHT JOIN users ON 'users.userid'='formdata.userid'
WHERE username='".$username."' and password='".$password."'";
Both userid in both tables "users and formdata" are INT(25).
This is driving me up the wall, tho a great learning experiance
Is it maybe the way the script runs ie....if (mysql_num_rows($result) != 1)
Is there another way of doing this maybe?
I have an Idea but need help if I use an "if" userid in "users" table is "blah blah" matched with "userid" in "formdata" table then echo "saveas" data matched with the "userid" in the "formdata" table:
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
session_start();
$username = $_POST['username'];
$password = md5($_POST['password']);
$query = "SELECT * FROM users WHERE username='".$username."' and password='".$password."'";
$query1 = "SELECT DISTINCT saveas FROM formdata, users";
$result = mysql_query($query);
$result1 = mysql_query($query1);
if (mysql_num_rows($result) != 1) {
$error = "Bad Login";
echo "<font color='red'>Error, Please re-enter or register!</font>";
include "login.html";
} else {
$_SESSION['username'] = "$username";
while($row = mysql_fetch_array($result))
{
while($row1 = mysql_fetch_array($result1))
{
echo "<p>", $row['userid']. " - <a href=\"\"> ". $row1['saveas'], "</a>";
}
}
}
?>
tables:
-users
-formdata
"users" table:
userid
name
username
password
"formdata" table:
userid
fieldid
value
saveas
the script checks against username and password for the login and I need it to also SELECT saveas FROM "formdata" table, but the where clause is interfering with it and I tried every combination I can find regarding mysql the version.
Its not showing the syntax error but is showing my error because the username and password are not passing.
if (mysql_num_rows($result) != 1) {
echo "<font color='red'>Error, Please re-enter or register!</font>";
include "login.html";
Here is the whole code:
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
session_start();
$username = $_POST['username'];
$password = md5($_POST['password']);
$query = "SELECT *
FROM formdata RIGHT JOIN users ON users.userid = formdata.userid
WHERE username='".$username."' and password='".$password."'";
//the following passes but with out the formdata table: $query = "select * from users where username='$username' and password='$password'";
$result = mysql_query($query);
if (mysql_num_rows($result) != 1) {
$error = "Bad Login";
echo "<font color='red'>Error, Please re-enter or register!</font>";
include "login.html";
} else {
$_SESSION['username'] = "$username";
while($row = mysql_fetch_array($result))
{
echo "<p>", $row['userid']. " - <a href=\"\"> ". $row['saveas'], "</a>";
}
}
?>
This is the closest I've gotten, it passes the username/password but still doesn't display data "saveas" from the other table "formdata".
$query = "SELECT *
FROM formdata RIGHT JOIN users ON 'users.userid'='formdata.userid'
WHERE username='".$username."' and password='".$password."'";
Both userid in both tables "users and formdata" are INT(25).
This is driving me up the wall, tho a great learning experiance
Is it maybe the way the script runs ie....if (mysql_num_rows($result) != 1)
Is there another way of doing this maybe?
I have an Idea but need help if I use an "if" userid in "users" table is "blah blah" matched with "userid" in "formdata" table then echo "saveas" data matched with the "userid" in the "formdata" table:
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
session_start();
$username = $_POST['username'];
$password = md5($_POST['password']);
$query = "SELECT * FROM users WHERE username='".$username."' and password='".$password."'";
$query1 = "SELECT DISTINCT saveas FROM formdata, users";
$result = mysql_query($query);
$result1 = mysql_query($query1);
if (mysql_num_rows($result) != 1) {
$error = "Bad Login";
echo "<font color='red'>Error, Please re-enter or register!</font>";
include "login.html";
} else {
$_SESSION['username'] = "$username";
while($row = mysql_fetch_array($result))
{
while($row1 = mysql_fetch_array($result1))
{
echo "<p>", $row['userid']. " - <a href=\"\"> ". $row1['saveas'], "</a>";
}
}
}
?>