Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2005
    Posts
    14

    Unanswered: Displaying an error from php in html

    Hi i have a html page with a username and password box, clicking submit posts this to a php script. If the script detects an error, the error is displayed on the html page. Before i used an echo for the error and it placed the error on top of the html page. I have now made a variable $message and placed that variable to be displayed on the html page, so it's where i want it. But this does not work and i'm not sure what i'm doing wrong. Instead of using <?= (isset($message)) ? $message : "" ?> in the html i also tried <? $message; ?>.


    My code is as followers:-

    login.html
    Code:
    <html>
    <head>
    <title></title>
    </head>
    
    <body>
    <table width="100%" border="0">
    <tr> 
    <td colspan="4"><div align="left"><font size="4" face="Arial, Helvetica, sans-serif"><strong><font size="5"></font></strong></font><font size="5" face="Arial, Helvetica, sans-serif"></font></div></td>
    <td width="50%"><div align="right"><em></em></div></td>
    </tr>
    </table>
    <table>
    <table width="100%" border="0">
    <tr bgcolor="#990000"> 
    <td colspan="5">&nbsp;</td>
    </tr>
    <tr bgcolor="#CCCCCC"> 
    <td width="20%"><div align="center">LOGIN</div></td>
    <td width="20%"><div align="center">REGISTER</div></td>
    <td width="20%"><div align="center">SEARCH</div></td>
    <td width="20%"><div align="center">ABOUT</div></td>
    <td width="20%"><div align="center">CONTACT</div></td>
    </tr>
    </table>
    <form action="checkuser.php" method="post" name="" id="">
    <?= (isset($message)) ? $message : "" ?> 
    <table width="50%" border="0" cellpadding="4" cellspacing="0">
    <tr> 
    <td width="22%">Username</td>
    <td width="78%"><input name="username" type="text" id="username"></td>
    </tr>
    <tr> 
    <td>Password</td>
    
    <td><input name="password" type="password" id="password">
    </td>
    </tr>
    <tr> 
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="Submit"></td>
    </tr>
    </table>
    </form>
    <table width="100%" border="0">
    <tr bgcolor="#CCCCCC"> 
    <td width="20%"><div align="center">LOGIN</div></td>
    <td width="20%"><div align="center">REGISTER</div></td>
    <td width="20%"><div align="center">SEARCH</div></td>
    <td width="20%"><div align="center">ABOUT</div></td>
    <td width="20%"><div align="center">CONTACT</div></td>
    </tr>
    <tr bgcolor="#990000"> 
    <td colspan="5">&nbsp;</td>
    </tr>
    <tr> 
    <td colspan="5"><div align="right">&copy; Copyright 2005, Man on the moon.</div></td>
    </tr>
    </table>
    
    </body>
    </html>

    checkuser.php
    PHP Code:
    <?
    /* Check User Script */
    session_start(); // Start Session

    include 'db.php';
    // Conver to simple variables
    $username $_POST['username'];
    $password $_POST['password'];

    if((!
    $username) || (!$password)){

    $message "Please enter ALL of the information!";
    include (
    "login.html");
    exit();
    }
    ?>
    Many Thanks
    Last edited by rhs98; 02-04-05 at 09:54. Reason: formatting

  2. #2
    Join Date
    Feb 2002
    Location
    San Francisco, CA
    Posts
    441
    Try this (all in one file);

    Code:
    <?
    /* Check User Script */
    session_start(); // Start Session
    
    include 'db.php';
    // Conver to simple variables
    
    if(isset($_POST['formcompleted']) && $_POST['formcompleted'])
    {
    	if(!isset($_POST['username']) || $_POST['username']==''
    		|| !isset($_POST['password']) || $_POST['password']=='')
    	{
    		$message = "Please enter ALL of the information!";
    	}
    }
    ?> 
    <html>
    <head>
    <title></title>
    </head>
    
    <body>
    <table width="100%" border="0">
    	<tr> 
    		<td colspan="4"><div align="left"><font size="4" face="Arial, Helvetica, sans-serif"><strong><font size="5"></font></strong></font><font size="5" face="Arial, Helvetica, sans-serif"></font></div></td>
    		<td width="50%"><div align="right"><em></em></div></td>
    	</tr>
    </table>
    <table width="100%" border="0">
    	<tr bgcolor="#990000"> 
    		<td colspan="5">&nbsp;</td>
    	</tr>
    	<tr bgcolor="#CCCCCC"> 
    		<td width="20%"><div align="center">LOGIN</div></td>
    		<td width="20%"><div align="center">REGISTER</div></td>
    		<td width="20%"><div align="center">SEARCH</div></td>
    		<td width="20%"><div align="center">ABOUT</div></td>
    		<td width="20%"><div align="center">CONTACT</div></td>
    	</tr>
    </table>
    <form action="checkuser.php" method="post" name="" id="">
    <?php echo (isset($message))?$message:''; ?> 
    <table width="50%" border="0" cellpadding="4" cellspacing="0">
    	<tr> 
    		<td width="22%">Username</td>
    		<td width="78%"><input name="username" type="text" id="username" /></td>
    	</tr>
    	<tr> 
    		<td>Password</td>
    		<td><input name="password" type="password" id="password" /></td>
    	</tr>
    	<tr> 
    		<td>&nbsp;</td>
    		<td><input type="submit" name="Submit" value="Submit" /></td>
    	</tr>
    </table>
    <input type="hidden" name="formcompleted" value="1" />
    </form>
    <table width="100%" border="0">
    	<tr bgcolor="#CCCCCC"> 
    		<td width="20%"><div align="center">LOGIN</div></td>
    		<td width="20%"><div align="center">REGISTER</div></td>
    		<td width="20%"><div align="center">SEARCH</div></td>
    		<td width="20%"><div align="center">ABOUT</div></td>
    		<td width="20%"><div align="center">CONTACT</div></td>
    	</tr>
    	<tr bgcolor="#990000"> 
    		<td colspan="5">&nbsp;</td>
    	</tr>
    	<tr> 
    		<td colspan="5"><div align="right">&copy; Copyright 2005, Man on the moon.</div></td>
    	</tr>
    </table>
    
    </body>
    </html>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •