PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ianhull
Forum Contributor
Posts: 310 Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK
Post
by ianhull » Mon May 29, 2006 5:58 am
Hi Guys,
I'm back for more help.
I have always used SELECT Username, Password FROM table but I have loads of columns in this project and I didn't really want to type out each one so I thought of using SELECT * instead but it does not work.
Can anyone see why in my code below?
Thanks.
Code: Select all
<?php session_start();
include_once("includes/globals.php");
$email = $_POST['email'];
$password = $_POST['password'];
$live = "Active";
if(empty($email)){
include_once("error_pages/login_error.php");
exit();
}
elseif(empty($password)){
include_once("error_pages/login_error.php");
exit();
}
include_once("includes/connect.php");
$sql = "SELECT * FROM users WHERE email='$email' AND password='$password' AND status='$live'";
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
include_once("error_pages/index_error.php");
exit();
}
else{
}
while ($line = mysql_fetch_array($r))
{
extract($line);
}
$_SESSION['mycompanyname'] = $companyname;
$_SESSION['myfirstname'] = $firstname;
$_SESSION['mylastname'] = $lastname;
$_SESSION['myemail'] = $email;
$_SESSION['mypassword'] = $password;
$_SESSION['mysite'] = $site;
$_SESSION['mytitle'] = $title;
echo $_SESSION['mycompanyname'];
?>
$phpNut
Forum Commoner
Posts: 40 Joined: Tue May 09, 2006 5:13 pm
Post
by $phpNut » Mon May 29, 2006 6:05 am
on this line:
your missing the resource
...
ianhull
Forum Contributor
Posts: 310 Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK
Post
by ianhull » Mon May 29, 2006 6:08 am
Thanks, I tried that but it did not work.
That has always worked before, I really just wanted to be lazy and use * instead of typing out 28 columns in my SELECT statement.
Nevermind, Thanks anyway.
$phpNut
Forum Commoner
Posts: 40 Joined: Tue May 09, 2006 5:13 pm
Post
by $phpNut » Mon May 29, 2006 6:12 am
What error are you actually getting?
ianhull
Forum Contributor
Posts: 310 Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK
Post
by ianhull » Mon May 29, 2006 6:19 am
No errors, just trying to work around the SELECT.
I have to type username, password, email, company, site, photo, etc etc I was hoping I could just use SELECT * and have the the variables and values available.
I have started typing now so I will just use my old way.
Thanks
$phpNut
Forum Commoner
Posts: 40 Joined: Tue May 09, 2006 5:13 pm
Post
by $phpNut » Mon May 29, 2006 6:28 am
Oh so thats what you wanted,
try changing this,
Code: Select all
while ($line = mysql_fetch_array($r))
{
extract($line);
}
$_SESSION['mycompanyname'] = $companyname;
$_SESSION['myfirstname'] = $firstname;
$_SESSION['mylastname'] = $lastname;
$_SESSION['myemail'] = $email;
$_SESSION['mypassword'] = $password;
$_SESSION['mysite'] = $site;
$_SESSION['mytitle'] = $title;
echo $_SESSION['mycompanyname'];
to this
Code: Select all
while ($row = mysql_fetch_object($r)) {
$_SESSION['mycompanyname'] = $row->companyname;
$_SESSION['myfirstname'] = $row->firstname;
$_SESSION['mylastname'] = $row->lastname;
$_SESSION['myemail'] = $row->email;
$_SESSION['mypassword'] = $row->password;
$_SESSION['mysite'] = $row->site;
$_SESSION['mytitle'] = $row->title;
}
echo $_SESSION['mycompanyname'];
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Mon May 29, 2006 6:33 am
Silly
mysql_affected_rows() won't return anything if you're not running an update or a delete. Use mysql_num_rows() instead