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

Link to comment
Share on other sites

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

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.