0

Straight to the point...:)
I have problem connect to database. when I click Login button, the code can't read the username in my database.
I have checked the codes but i think there are some mistakes, but i don't know where it will be. Please help me. Here with I attach my login form and connection form...
Please help me soon. Thanks...

Attachments
<html>
 <head>
  <title>AUTOMASI BISNIS PROSES SARANA dan UTILITAS - POLITKNIK BATAM</title>
  <style type="text/css">
   <p align="center"><b><font size="5">AUTOMASI BISNIS PROSES SARANA dan UTILITAS</font></b></p>>

  <!--
  INPUT 
  {
  background:  #ffffff;
  border-color: #777777;
  border-style: solid;
  border-width: 1px;
  color: #333333;
  font-size: 13px;
  }
  -->
  </style>
 </head>
<body alink="#000000" bgcolor="gray" link="#000000" text="#000000" vLink="#000000">
<!-- start title -->
<table border="1" borderColor="#000000" cellpadding="0" cellspacing="0" height="11%" width="100%">
  <tr>
    <td align="left" bgcolor="#e5e5e5"><br>
    &nbsp;
    </td>
  </tr>
</table>

&nbsp;<b><? print(Date("l F d, Y")); ?></b>
<!-- end title -->
<!-- start main -->

 
<table border="1" bordercolor="#000000" cellpadding="0" cellspacing="0" height="86%" width="100%">
  <tr>
    <td bgcolor="#e5e5e5" valign="top">
	<p align="center">&nbsp;</p>
	<p align="center">&nbsp;</p>
	<p align="center"><b><font size="5" face="Georgia">AUTOMASI BISNIS PROSES 
	SARANA DAN UTILITAS</font></b></p>
	<p align="center">&nbsp;</p>
	<p align="center">&nbsp;</p>
    <table border="1" bordercolor="#000000" cellpadding="0" cellspacing="0" height="150" width="375" align="center">
	 <tr>
	 	 <td height="20" align="center" bgcolor="#000000">
		 <font size="4" color="#ffffff">Admin Login</font><font size="4"> </font>
	  	 </td>
	 </tr>
	 <tr>
	 	 <td valign="top">
		 <form action="submit.php" method="post"><br>
		 <table border="0" cellpadding="3" cellspacing="0" align="center" width="275">
		  <tr>
		  	  <td>
			  <b><font size="4">Username :</font></b><font size="4"> </font>
			  </td>
			  <td>
			  <font size="4">
			  <input type="text" name="username" size="21">
			  </font>
			  </td>
		  </tr>
		  <tr>
		  	  <td>
			  <b><font size="4">Password :</font></b><font size="4"> </font>
			  </td>
			  <td>
			  <font size="4">
			  <input type="password" name="password" size="21">
			  </font>
			  </td>
		  </tr>
		  <tr>
		  	 <td colspan="2">
		 	  <center><font size="4"><input type="submit" name=login value="Submit "></font>
			  <font face="Arial"><left><font size="4"><input type="reset" name="reset" value="Reset  ">
			  </font></font></center>
			   <font face="Arial">
			  <left></center>
			  &nbsp;</td>

		  </tr>
		 </table>
		 </form>
		 </td>
	 </tr>
	</table>
    </td>
  </tr>
  <tr>
    <td bgcolor="#e5e5e5" valign="top">&nbsp;</td>
  </tr>
</table>
</body>
 </html>
<?php
$connected = mysql_connect('localhost', 'root');
if( !connected ) {
	die ("Connect to MySQL Server failed");
		 }

$retval = mysql_select_db("sarana", $connected);

if (!retval) {
	die ("Database doesn't connect");
	     }
?>
<html>
 <head>
  <title>AUTOMASI BISNIS PROSES SARANA dan UTILITAS - POLITKNIK BATAM</title>
  <style type="text/css">
   <p align="center"><b><font size="5">AUTOMASI BISNIS PROSES SARANA dan UTILITAS</font></b></p>

  <!--
  INPUT 
  {
  background:  #ffffff;
  border-color: #777777;
  border-style: solid;
  border-width: 1px;
  color: #333333;
  font-size: 13px;
  }
  -->
  </style>
 </head>
<body alink="#000000" bgcolor="gray" link="#000000" text="#000000" vLink="#000000">
<!-- start title -->
<table border="1" borderColor="#000000" cellpadding="0" cellspacing="0" height="11%" width="100%">
  <tr>
    <td align="left" bgcolor="#e5e5e5"><br>
    &nbsp;
    </td>
  </tr>
</table>

&nbsp;<b><? print(Date("l F d, Y")); ?></b>
<!-- end title -->
<!-- start main -->
<br>
<br>
<br>
<table border="1" bordercolor="#000000" cellpadding="0" cellspacing="0" height="86%" width="100%">
 <body>
<?php

include ("koneksi.php");

$username     = $HTTP_POST_VARS['username'];
$password 	  = $HTTP_POST_VARS['password'];

$query = "SELECT username FROM sarana WHERE
		  username = '$username' AND password = '$password'";
		  
$DEBUG = false;
if($DEBUG)
	{
		print $query . "<br>\n";
	}
	else{
			$rs = mysql_query($query);
			gettype($rs);
			if($rs)
			{
				$num = mysql_num_rows($rs);
					if($num > 0)
						{
							$row = mysql_fetch_object($rs);
							$nr  = $row->username;
							print "<SCRIPT LANGUAGE=JAVASCRIPT>\n";
							print "window.location = 'menu.php'\n";
							print "</SCRIPT>";
						}
						else
							{
								print "Your Username does not exist<br>";
								
								print "<a href=form_login.php>Try again, please</a>";
							}
							
			}
			else
				{
					print "Data Failed to be read\n<br><br><br>";
			
					print "<a href=form_login.php>Try again, please</a>";
				}
		}
		
mysql_close();
?>
</table>
</body>
</html>
2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by bintang
0

original koneksi.php

$connected = mysql_connect('localhost', 'root');
if( !connected ) {
die ("Connect to MySQL Server failed");
}

$retval = mysql_select_db("sarana", $connected);

if (!retval) {
die ("Database doesn't connect");
}

A couple changes are needed in your koneksi.php:

$connected = mysql_connect('localhost', 'root', 'password');
if( !$connected ) {
	die ("Connect to MySQL Server failed");
		 }

$retval = mysql_select_db("sarana", $connected);

if (!$retval) {
	die ("Database doesn't connect");
	     }
0

Thanks a lot for yor kind reply. I am satisfied. Once again, thank you...:)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.