Garcia Posted October 21, 2007 Share Posted October 21, 2007 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 More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 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 https://forums.phpfreaks.com/topic/74148-if-statement-mysql-verifying/#findComment-374448 Share on other sites More sharing options...
Garcia Posted October 21, 2007 Author Share Posted October 21, 2007 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 https://forums.phpfreaks.com/topic/74148-if-statement-mysql-verifying/#findComment-374455 Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 Is $projectclient declared before you run the MYSQL Query? it doesnt look like it is in the code you posted Which would be why you get the mysql_fetch_assoc error Link to comment https://forums.phpfreaks.com/topic/74148-if-statement-mysql-verifying/#findComment-374457 Share on other sites More sharing options...
Garcia Posted October 21, 2007 Author Share Posted October 21, 2007 $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 https://forums.phpfreaks.com/topic/74148-if-statement-mysql-verifying/#findComment-374460 Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 Well, if this page is right after a login, you could use $_POST vars. But if now, make it to where after a user logs in, just store his/her information (email) in a $_SESSION var.. Then read it when running the SQL query Link to comment https://forums.phpfreaks.com/topic/74148-if-statement-mysql-verifying/#findComment-374462 Share on other sites More sharing options...
Garcia Posted October 21, 2007 Author Share Posted October 21, 2007 Hmm well $email is stored in a $_SESSION variable but just not $projectclient. Would it work if I added projectclient in a $_session variable in login even if it is empty. It would then be defined when I add a project to that client ? Link to comment https://forums.phpfreaks.com/topic/74148-if-statement-mysql-verifying/#findComment-374464 Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 ^ 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 https://forums.phpfreaks.com/topic/74148-if-statement-mysql-verifying/#findComment-374466 Share on other sites More sharing options...
Garcia Posted October 21, 2007 Author Share Posted October 21, 2007 I still believe my other way could work. There is no way for it to do a loop to see if the result of $email matches with any of the results in projectclient ? Link to comment https://forums.phpfreaks.com/topic/74148-if-statement-mysql-verifying/#findComment-374532 Share on other sites More sharing options...
Garcia Posted October 21, 2007 Author Share Posted October 21, 2007 bump Link to comment https://forums.phpfreaks.com/topic/74148-if-statement-mysql-verifying/#findComment-374753 Share on other sites More sharing options...
Garcia Posted October 22, 2007 Author Share Posted October 22, 2007 No help at all? Link to comment https://forums.phpfreaks.com/topic/74148-if-statement-mysql-verifying/#findComment-375666 Share on other sites More sharing options...
Wes1890 Posted October 22, 2007 Share Posted October 22, 2007 You either have to have something UNIQUE to select the right projectclient out of the Database in the WHERE clause, or you must get data from the $_REQUEST vars... other than that you can't just predict something that the script cant get Link to comment https://forums.phpfreaks.com/topic/74148-if-statement-mysql-verifying/#findComment-375815 Share on other sites More sharing options...
kevincro Posted October 23, 2007 Share Posted October 23, 2007 Try the following code with single quotes. $sql = "SELECT projectclient FROM project WHERE projectclient='$projectclient'"; Also, have you made a database connection? Link to comment https://forums.phpfreaks.com/topic/74148-if-statement-mysql-verifying/#findComment-375908 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.