Jump to content

PHP-putting a button inside if scope


harafa

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/145133-php-putting-a-button-inside-if-scope/
Share on other sites

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.

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 !!

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.