Извеждане на променлива в HTML код

emagi

Registered
Здравейте!
Днес цял ден се занимавам със следното!Имам следния код:
Код:
<?php
session_start();
if (isset($_POST['userid']) && isset($_POST['password']))
    {
        $userid = $_POST['userid'];
        $password = $_POST['password'];
        $db_conn = mysql_connect('localhost', 'xxx', 'xxx') or die ("Could not connect MYSQL server");
        $mysql = mysql_select_db('pavel') or die ("Can not find database");
        $query = "select count(*) from auth1 where userid = '$userid' and pass = md5('$password')";
        $result = mysql_query($query) or die ("Can not run query");
        $count = mysql_result ($result, 0, 0 );
        if ($count == 0 )
            {
                echo '<div align="center"><h3>UserID or PAssword Incorrect!!!</h3></div>';
								echo '<p><div align="center"><a href="1.php">Go Back</div></a></p>';
            }
        else
            {
                $_SESSION['userid'] = $userid;
                echo'<META HTTP-EQUIV="Refresh"
                  CONTENT="0; URL=2.php">';
                  exit; 
                
            }
        
    }
else
    {
        if (isset($userid))
            {
                echo '<h2>Could not log in</h2>';
            }
        else
            {
                echo '<div align="center"><h3>You are not logged in</h3></div>';
            }
?>
<html>
<head></head>
</head>
<body>
<table width="100%" border="1" cellspacing="1" cellpadding="1">
  <tr>
    <th height="100" bordercolor="#CCFF99" background="1.jpg"><h1>@Magi Server `08</h1></th>
  </tr>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="1">
  <tr>
    <td height="35" background="2.jpg"> </td>
  </tr>
</table> 
<table width="100%" height="569" align="center" border="2">
<tr>
<td width="144" height="124" align="center" valign="top" bordercolor="#FFFF00" background="3.jpg" >
<form method="post" action="login.php">
<table align="left" valign="top">
<tr>
	<td><span class="style5">Username</span></td>
  </tr>
  <tr>
  <td><input name="userid" type="text" value="" size="12" /></td>
</tr>
<tr>
	<td><span class="style5">Password</span></td>
  </tr>
  <tr>
  <td><input type="password" name="password" size="12" ></td>
</tr>
<tr>
	<td colspan="2" align="center"><input type="submit" value="Log In"></td>
</tr>
</table>
</form></td>
<td width="588" rowspan="2" align="center" valign="top"  background="5.jpg"><br /><u><?php echo date('H:i, jS F') ?></u>
</u></td>
<td width="210" rowspan="2" valign="top" align="center"><table width="100%" border="0" cellspacing="1" cellpadding="1">
  <tr>
    <td><div align="center"><img src="mnenie.gif" width="210" height="50" /></div></td>
  </tr>
  <tr>
    <td> </td>
  </tr>
</table></td>
</tr>
<tr>
  <td height="437" align="center" valign="top" bordercolor="#FFFF00" background="4.jpg"> </td>
</tr>
</table>
</body>
</html>
}
?>
НИщо сложно,обикновена форма за логване!Обаче проблема е там!Ако не се въведат правилно потребителското име и паролата,то този ред:
Userid or Password Incorrect
излиза на върха на страницата,а аз искам да излиза в определен ред на таблицата!Има ли начин,примерно при неправилно въведено име,да се присвои на променлива низ,ето как:
Код:
...........
if ($count ==0)
      {
              $ppp = "Password or UserID incorrect";
       }
и някъде във HTML кода да се направи следното:
...........
<td width="588" rowspan="2" align="center" valign="top" background="5.jpg"><br /><u><?php echo date('H:i, jS F');
echo $ ppp;
?></u>
</u></td>
Какво бихте ме посъветвали!Предварително благодаря!
P.S.Спънката идва от това,че тука вече наблягам малко на визията на сайта!Иначе,ако няма проблем!
 
Хвърли един поглед как го направих:
<?php
session_start();
if (isset($_POST['userid']) && isset($_POST['password']))
{
$userid = $_POST['userid'];
$password = $_POST['password'];
$db = mysql_connect('xxxxx', 'xxxx', 'xxxx'') or die (mysql_error());
$mysql = mysql_select_db('pavel') or die ("Can not find DataBase");
$query = "select count(*) from auth1 where userid='$userid' and pass=md5('$password')";
$result = mysql_query($query) or die ("Can not run query");
$count = mysql_result($result, 0, 0 );
if ($count == 0 )
{
$news = "The UserID and Password are incorrect.";

//echo '<div align="center"><h3>The UserID and Password are incorrect</h3></div>';
//echo '<div align="center"><a href="login.php">Go back</a></div>';
}
else
{
$_SESSION['userid'] = $userid;
header("Location:main.php");
}
}
else
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>eMagi</title>
<style type="text/css">

</head>
<body>
<table width="100%" border="1" cellspacing="1" cellpadding="1">
<tr>
<th height="100" bordercolor="#CCFF99" background="1.jpg"><h1>@Magi Server `08</h1></th>
</tr>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td height="35" background="2.jpg"> </td>
</tr>
</table>
<table width="100%" height="569" align="center" border="2">
<tr>
<td width="144" height="124" align="center" valign="top" bordercolor="#FFFF00" background="3.jpg" >
<form method="post" action="login.php">
<table align="left" valign="top">
<tr>
<td><span class="style5">Username</span></td>
</tr>
<tr>
<td><input name="userid" type="text" value="" size="12" /></td>
</tr>
<tr>
<td><span class="style5">Password</span></td>
</tr>
<tr>
<td><input type="password" name="password" size="12" ></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Log In"></td>
</tr>
</table>
</form></td>
<td width="588" rowspan="2" align="center" valign="top" background="5.jpg"><br /><u>
<?php echo $news; ?>
</td>
<td width="210" rowspan="2" valign="top" align="center"><table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td><div align="center"><img src="mnenie.gif" width="210" height="50" /></div></td>
</tr>
<tr>
<td> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="437" align="center" valign="top" bordercolor="#FFFF00" background="4.jpg"> </td>
</tr>
</table>
</body>
</html>
<?php
}
?>
Обаче,като не въведа правилно потр.име и парола ми дава само бял екран.
 
<?php
session_start();
if (isset($_POST['userid']) && isset($_POST['password']))
{
$userid = $_POST['userid'];
$password = $_POST['password'];
$db = mysql_connect('xxxxx', 'xxxx', 'xxxx'') or die (mysql_error());
$mysql = mysql_select_db('pavel') or die ("Can not find DataBase");
$query = "select count(*) from auth1 where userid='$userid' and pass=md5('$password')";
$result = mysql_query($query) or die ("Can not run query");

if (mysql_fetch_array($result))
{
$news = "The UserID and Password are incorrect.";

//echo '<div align="center"><h3>The UserID and Password are incorrect</h3></div>';
//echo '<div align="center"><a href="login.php">Go back</a></div>';
}
else
{
$_SESSION['userid'] = $userid;
header("Location:main.php");
}
}
else
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>eMagi</title>
<style type="text/css">

</head>
<body>
<table width="100%" border="1" cellspacing="1" cellpadding="1">
<tr>
<th height="100" bordercolor="#CCFF99" background="1.jpg"><h1>@Magi Server `08</h1></th>
</tr>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td height="35" background="2.jpg"> </td>
</tr>
</table>
<table width="100%" height="569" align="center" border="2">
<tr>
<td width="144" height="124" align="center" valign="top" bordercolor="#FFFF00" background="3.jpg" >
<form method="post" action="login.php">
<table align="left" valign="top">
<tr>
<td><span class="style5">Username</span></td>
</tr>
<tr>
<td><input name="userid" type="text" value="" size="12" /></td>
</tr>
<tr>
<td><span class="style5">Password</span></td>
</tr>
<tr>
<td><input type="password" name="password" size="12" ></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Log In"></td>
</tr>
</table>
</form></td>
<td width="588" rowspan="2" align="center" valign="top" background="5.jpg"><br /><u>
<?php echo $news; ?>
</td>
<td width="210" rowspan="2" valign="top" align="center"><table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td><div align="center"><img src="mnenie.gif" width="210" height="50" /></div></td>
</tr>
<tr>
<td> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="437" align="center" valign="top" bordercolor="#FFFF00" background="4.jpg"> </td>
</tr>
</table>
</body>
</html>
<?php
}
?>

Пробвай така! :wink:
 
Е то разликата каква я?Дали ще проверявам за броя върнатите редове с count(*) или ще обhодя целия масив с mysql_fetch_array не е ли едно и също!Проблема ми е,че променливата $news не мога да и присвоя стойност - този низ!
Аз го дефинирам:
Код:
.....
if (count ==0)
    {
           $news = "Wrong userid or password";
    }
и по-надолу в скрипта го извеждам.Ако има стойност променливата $news то тя да бъде изведена:
Код:
.......
<td><?php echo $news ?></td>
......
Дава ми обаче предупреждение:
Undefinied variable: news on line 76
А де!
 
Ето какво направих,сложих променливта $news директно след
Код:
session_start();
$news = "The UserID and Password are incorrect.";
И стана!Ама така не ми върши работа!
 

Back
Горе