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
https://forums.phpfreaks.com/topic/74148-if-statement-mysql-verifying/
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"

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.

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.