Jump to content

[SOLVED] another question for everyone who knows what there doing


Reaper0167

Recommended Posts

ok

you don't need javascript

 

do this..

 

<?php
  if (your condition) {
    $message = "1 message";
  }
  else {
    $message = "another message";
  }
?>
<html>
  <head>
  </head>
  <body>
    <div><?php echo $message; ?></div>
  </body>
</html>

Link to comment
Share on other sites

thanks for the help but now when i click on submit it takes me to the php page and that is empty. here is the code.

login.php

<?php
// log in success or failure

if ($count == 1) {
$message = "You are now logged in.";
    
} else {
$message = "This username is not registered. Pleaser register first.";

}

?> 

 

and my div code

index.html

<?php // this page is html not php
<div>
      <div align="center"><?php echo $message; ?></div>
</div>
?>

Link to comment
Share on other sites

i just put the php tags in there so the code was easier to read.

ok,,, here is all the code so far. check out the page if you would like.

http://mylahstone.com

the red text is where i'm looking to put the success/error message,, not in a seperate browser window.

// this is the php page with my form
<?php
<html>
<head>

<style>
.error { color: #ff0000; }
</style>
<!-- using javascript to make sure fields are not left empty -->

    <script type="text/javascript" language="javascript">

    function validate(form1)
    {
    var valid = true;

    if (form1.username.value)
    {
        document.getElementById('username_error').innerHTML = '';
    }
    else
    {
        document.getElementById('username_error').innerHTML = 'Please enter a username.';
        valid = false;
    }

    if (form1.password.value)
    {
        document.getElementById('password_error').innerHTML = '';
    }
    else
    {
        document.getElementById('password_error').innerHTML = 'Please enter a password.';
        valid = false;
    }
    return valid;
    }
    </script>
    
<style type="text/css">
    <!--
    body {
    background-color: #FFFFFF;
    }
    -->
    </style>

    <title></title>
    <style type="text/css">
    p.c3 {text-align: center}
    div.c2 {text-align: right}
    div.c1 {text-align: center}
    .style4 {color: #FF0000}
    </style>
</head>

<body>
    <p> </p>

    <p> </p>

    <p> </p>

    <p> </p>

    <table width="100%" height="36" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td height="36">
                <div class="c1">
                    <img src="pics/header.png" alt="header" width="433" height="37">
                </div>
            </td>
        </tr>
    </table>

    <p align="center">Hi, please log in.</p>
    <div>
      <div align="center" class="style4">I would like the message to display here instead of on new page.</div>
    </div>
<form action="login.php" method="post" name="form1" id="form1" onSubmit="return validate(this);">
<table width="100%" border="0" cellspacing="3" cellpadding="0">
            <tr>
                <td width="39%">
                    <div class="c2">
                        <label for="username">Username:</label>
                    </div>
                </td>

                <td width="61%"><input name="username" type="text" size="35" /> <span id="username_error" class="error"></td>
            </tr>

            <tr>
                <td>
                    <div class="c2">
                        <label for="password">Password:</label>
                    </div>
                </td>

                <td><input name="password" type="password" size="35" /> <span id="password_error" class="error"></td>
            </tr>

            <tr>
                <td> </td>

                <td><input type="submit" name="submit" id="submit" value="  Log in  "></td>
            </tr>
        </table>
    </form>

<p class="c3">Don't have a username?
    <br>
     Click here to register.</p>

<!-- using javascript  to set focus of the cursor on the username textfield -->
<script type="text/javascript" language="javascript">

    document.form1.username.focus();

</script>

</body>
</html>
?>

 

// this is the php with the script
<?php

$host = "-------------"; // host name
$dbusername = "--------------"; // mysql username
$dbpassword = "------------"; // mysql password
$db_name = "-----------"; // database name
$tbl = "-------------"; // table name

// connects to server and members databse.
mysql_connect("$host", "$dbusername", "$dbpassword") or die("cannot connect");
mysql_select_db("$db_name") or die("cannot select DB");

// username/password changed to variables.
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM $tbl WHERE username='$username' and password='$password'";
$result = mysql_query($sql);

// create variable for success/failure message
$count = mysql_num_rows($result);

// log in success or failure
if ($count == "1") {
    echo "Thank you for logging in.";
} else {
    echo "This is not a registered username. Please register before logging in.";
}
?> 

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.