Jump to content

Php error message in html table


aashcool198

Recommended Posts

i have written a php login. Now when password or user name is wrong i want to display error at a certain position. How can i do it?  i mean php script and html forms are on the same page but they are different. how can i send something from php code to html table?

 

 

  Quote
<?php

 

// Open a connection to the DB

$conn = mysql_connect('localhost', 'root', '') or die(mysql_error());

mysql_select_db('Sumeru Skills', $conn);

 

// Start the session (DON'T FORGET!!)

session_start();

 

// Check if user wants to login (GET info)

if(isset($_GET['try'])) {

 

  // That's nice, user wants to login. But lets check if user has filled in all information

  if(empty($_POST['username']) || empty($_POST['password'])) {

 

      // User hasn't filled it all in!

      echo 'Please fill in all the required fields!';

 

  } else {

 

      // User filled it all in!

 

      // Make variables save with addslashes and md5

      $username = $_POST['username'];

      $password = $_POST['password'];

 

 

 

 

      // Search for a combination

      $query = mysql_query("SELECT employee_id FROM login

                  WHERE (username = '" . $username . "' && password = '" . $password . "')

                ") or die(mysql_error());

 

      // Save result

      list($user_id) = mysql_fetch_array($query);

 

      // If the user_id is empty no combination was found

      if(empty($user_id)) {

 

        echo 'No combination of username and password found.';

 

      } else {

     

        // the user_id variable doesn't seem to be empty, so a combination was found!

 

        // Create new session, store the user id

        $_SESSION['user_id'] = $user_id;

 

        // Redirect to userpanel.php

        header('location: userpanel.php');

      }     

  }

}

 

?>

 

<HTML>

<head> <link rel="stylesheet" type="text/css" href="test.css" /> </head>

 

 

 

<font face="verdana,arial" size=-1>

<center><table cellpadding=2 cellspacing=0 border=0>

<tr><img src = "sumeru.jpg" height = "30%" align = "center"></tr>

<tr><td bgcolor="#084B8A"><table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td bgcolor="#084B8A" align=center style="padding:2;padding-bottom:4"><b><font size=-1 color="white"></font></th></tr>

<tr><td bgcolor="white" style="padding:5"><br>

<form method="post" action="login.php?try=true" name=pform>

<input type="hidden" name="action" value="login">

<input type="hidden" name="user" value="deluxe">

<input type="hidden" name="hide" value="">

<center><table >

<tr><td><font face="verdana,arial" size=-1>Username:</td><td><input type="text" name="username"></td></tr>

<tr><td><font face="verdana,arial" size=-1>Password:</td><td><input type="password" name="password"></td></tr>

<tr><td><font face="verdana,arial" size=-1> </td><td><font face="verdana,arial" size=-1><input type="submit" value="Go"></td></tr>

<tr><td colspan=2><font face="verdana,arial" size=-1> </td></tr>

<tr><td colspan=2><font face="verdana,arial" size=-1>Lost your password? click <a href="http://www.authpro.com/cgi-bin/auth.cgi?user=deluxe&action=lost">here</a>!</td><td colspan=2><font face="verdana,arial" size=-1><a href="http://www.authpro.com/cgi-bin/auth.cgi?user=deluxe&action=reg"><img src = "icon.gif" width="45" height="45" style="border: 0px

blue solid;"></a></td></tr>

<tr></tr>

</table></center>

</form>

</td></tr></table></td></tr></table>

 

 

 

 

 

 

</form>

 

</html>

Link to comment
https://forums.phpfreaks.com/topic/159899-php-error-message-in-html-table/
Share on other sites

Try this. Changes are marked in brown.

 

  Quote

<?php

 

// String variable to store error

$err = '';

// Open a connection to the DB

$conn = mysql_connect('localhost', 'root', '') or die(mysql_error());

mysql_select_db('Sumeru Skills', $conn);

 

// Start the session (DON'T FORGET!!)

session_start();

 

// Check if user wants to login (GET info)

if(isset($_GET['try'])) {

 

  // That's nice, user wants to login. But lets check if user has filled in all information

  if(empty($_POST['username']) || empty($_POST['password'])) {

 

      // User hasn't filled it all in!

      $err = 'Please fill in all the required fields!';

 

  } else {

 

      // User filled it all in!

 

      // Make variables save with addslashes and md5

      $username = $_POST['username'];

      $password = $_POST['password'];

 

 

 

 

      // Search for a combination

      $query = mysql_query("SELECT employee_id FROM login

                  WHERE (username = '" . $username . "' && password = '" . $password . "')

                ") or die(mysql_error());

 

      // Save result

      list($user_id) = mysql_fetch_array($query);

 

      // If the user_id is empty no combination was found

      if(empty($user_id)) {

 

        $err = 'No combination of username and password found.';

 

      } else {

     

        // the user_id variable doesn't seem to be empty, so a combination was found!

 

        // Create new session, store the user id

        $_SESSION['user_id'] = $user_id;

 

        // Redirect to userpanel.php

        header('location: userpanel.php');

      }     

  }

}

 

?>

 

<HTML>

<head> <link rel="stylesheet" type="text/css" href="test.css" /> </head>

 

 

 

<font face="verdana,arial" size=-1>

<center><table cellpadding=2 cellspacing=0 border=0>

<tr><img src = "sumeru.jpg" height = "30%" align = "center"></tr>

<tr><td bgcolor="#084B8A"><table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td bgcolor="#084B8A" align=center style="padding:2;padding-bottom:4"><b><font size=-1 color="white"></font></th></tr>

<tr><td bgcolor="white" style="padding:5"><br>

<?php echo ($err != '') ? $err . '<br>' : ''; ?>

<form method="post" action="login.php?try=true" name=pform>

<input type="hidden" name="action" value="login">

<input type="hidden" name="user" value="deluxe">

<input type="hidden" name="hide" value="">

<center><table >

<tr><td><font face="verdana,arial" size=-1>Username:</td><td><input type="text" name="username"></td></tr>

<tr><td><font face="verdana,arial" size=-1>Password:</td><td><input type="password" name="password"></td></tr>

<tr><td><font face="verdana,arial" size=-1> </td><td><font face="verdana,arial" size=-1><input type="submit" value="Go"></td></tr>

<tr><td colspan=2><font face="verdana,arial" size=-1> </td></tr>

<tr><td colspan=2><font face="verdana,arial" size=-1>Lost your password? click <a href="http://www.authpro.com/cgi-bin/auth.cgi?user=deluxe&action=lost">here</a>!</td><td colspan=2><font face="verdana,arial" size=-1><a href="http://www.authpro.com/cgi-bin/auth.cgi?user=deluxe&action=reg"><img src = "icon.gif" width="45" height="45" style="border: 0px

blue solid;"></a></td></tr>

<tr></tr>

</table></center>

</form>

</td></tr></table></td></tr></table>

</form>

 

</html>

 

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.