Jump to content

IF Statement & mysql verifying


Garcia

Recommended Posts

I had another topic but I didn't make it clear enough maybe this will be better and I can get this fixed.

 

Admin creates a Project and assigns the clients email to the projectclient field under project. The client logs on to see his projects only assigned to him.

 

What I want my IF statement to do is see if $email equals the $projectclient and if it does display the project. Now I think that I am missing something because when I do this WHERE projectclient=$projectclient'; I didn't specify exactly what to pull from the database like to pull the same email found in the table.

 

Here is my bit of code:

<?php
session_start();
header("Cache-control: no-cache");

//Where $con is found. Works perfectly for other SQL queries.
require ('config.php');

//Lets select the $projectclient
$sql ='SELECT projectclient FROM project WHERE projectclient=$projectclient';
$rs = @mysql_query($sql, $con);
$row = mysql_fetch_assoc($rs);

$email = $_SESSION['email'];
$projectclient = $row['projectclient'];

//Lets see if it works. No.
print $row['projectclient'];

//Are you logged on . Check username.
if($_SESSION['email']){
print " Welcome ";
print $_SESSION['email'];
}
else
{
header ("Location:login.php"); exit();
}

//DO you have a project?!
if($email == $projectclient)
{
print "You have a project!";
}
else
{
print "Currently showing no projects.";
}
?>

Link to comment
Share on other sites

Try changing

 

//Lets select the $projectclient
$sql = 'SELECT projectclient FROM project WHERE projectclient=$projectclient';

 

to

 

//Lets select the $projectclient
$sql = "SELECT projectclient FROM project WHERE projectclient=".$projectclient."";

 

You CANT have $variables inside of 'single quotes'... this code below should also work

 

//Lets select the $projectclient
$sql = "SELECT projectclient FROM project WHERE projectclient=$projectclient";

 

Note the awesome "double quotes"

Link to comment
Share on other sites

I still don't get anything. I know that displaying the user's email works fine so I can cross that off.

 

I also get this error :

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\vault\project\client.php on line 8

 

Should I have the @ in front of mysql_fetch_assoc();

 

How does the system know what $projectclient is, by the IF statement correct, because the IF statement checks if it equals the $email.

Link to comment
Share on other sites

$projectclient isn't declared because I don't know what exactly to declare it to. It's created by the Admin and not used in the login form so I can have it in the session variable as well. Hmm? Since it's suppose to equal $email to properly work so what do you suggest me to do for this?

Link to comment
Share on other sites

^ Well, you could.. but if it's empty then there would be no point.

 

What is something else you could store in a session (besides email) that would be unique to that user? Then set that as a session and have this

 

WHERE projectclient=$$_SESSION['THAT_UNIQUE_VALUE_YOU_THOUGHT_OF'][/quote] 

Link to comment
Share on other sites

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.