harafa Posted February 13, 2009 Share Posted February 13, 2009 Hi all, I'm trying to write PHP code that lets me check if a user is already registered (exists in my batabase) so he can log in, or not registered so he has to. In other words, i check for the user's ID in my database, if found --> go to next PHP page if not --> do nothing (he has to go back to log in) So, now i need to put a button (to go to the next PHP) in the if statement, so this button will be valid only if the condition (user already exists in db) is true... Is that possible ????? can i put a button inside the IF scope in PHP? if it isn't possible, what else can i do? Quote Link to comment Share on other sites More sharing options...
Caesar Posted February 14, 2009 Share Posted February 14, 2009 You really don't want to do it in 100 different PHP pages. Instead, use methods (See OOP) or functions...all within a single PHP page. That being said, it's possible to display anything you want on a conditional basis. What you're asking is basically the basics of if/else 101. Something like.... <?php function loadpage($var) { // Your code here } if($_SESSION['loggedin']) loadpage('members'); else loadpage('login'); ?> There's of course different approaches, techniques...etc. But yes, more than possible. Quote Link to comment Share on other sites More sharing options...
harafa Posted February 14, 2009 Author Share Posted February 14, 2009 hi, thnx 4 the speedy response, but i wanna ask abt something, wt is the function loadpage supposed to do to actually load another page? is it a link or a button or wt? thnx again, appreciate ur help Quote Link to comment Share on other sites More sharing options...
harafa Posted February 14, 2009 Author Share Posted February 14, 2009 btw, i tried to write an HTML line inside the if scope in PHP, but it ddnt work here's wt i did : <html> <form action="w_doc.html" method = "get"> <?php $log =$_GET["ii"]; //this is the ID we get from the previous HTML $con = mysql_connect("localhost","root","")or die ("Unable to connect!"); mysql_select_db("my_db",$con)or die ("Unable to select database!"); $query= "SELECT*FROM doctor where ID='$log'"; $result = mysql_query($query) or die ("Error in query: $query.".mysql_error()); if (mysql_num_rows($result) > 0) { echo "Logged in successfully !"; <input type="submit" value="Load page" > // this line ddnt work at all } else echo "You have no account on our site, you have to register first!"; ?> </html> Now, wt do i have 2 do 2 make <input type="submit" value="Load page" > work??? I tried also to end the PHP just b4 this line n start it again roght after it, but this ddnt work either PLZ HELP ME !! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.