![]() |
|
need help php code (My final project in college) - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: PHP (https://sinister.li/Forum-PHP) +--- Thread: need help php code (My final project in college) (/Thread-need-help-php-code-My-final-project-in-college) |
need help php code (My final project in college) - ghoza - 05-06-2011 login ceking. PHP Code: <?php
include "../config/koneksi.php";
$pass=md5($_POST[password]);
$login=mysql_query("SELECT * FROM user WHERE id_user='$_POST[username]' AND password='$pass'");
$ketemu=mysql_num_rows($login);
$r=mysql_fetch_array($login);
// Apabila username dan password ditemukan
if ($ketemu > 0){
session_start();
session_register("namauser");
session_register("passuser");
session_register("namalengkap");
$_SESSION[namauser]=$r[id_user];
$_SESSION[passuser]=$r[password];
$_SESSION[namalengkap]=$r[nama];
header('location:media.php?module=home');
}
else{
echo "<link href=../config/adminstyle.css rel=stylesheet type=text/css>";
echo "<center>Login gagal! username & password tidak benar<br>";
echo "<a href=index.php><b>ULANGI LAGI</b></a></center>";
}
?>if i run in program the message is Quote:Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\xampp\htdocs\travel\admin\cek_login.php on line 5please check, is there anything wrong? thank's alot. sorry if my language is less understood RE: need help php code (My final project in college) - Frooxius - 05-06-2011 You're sending a query to the database, but have you connected to the database in the first place? For example using the Code: $db = mysql_connect(server, username, password);RE: need help php code (My final project in college) - ghoza - 05-06-2011 I think it's my first connect the database. I use this configuration PHP Code: <?
$server = "localhost";
$username = "root";
$password = "";
$database = "mitra";
// Koneksi dan memilih database di server
mysql_connect($server,$username,$password) or die("Koneksi gagal");
mysql_select_db($database) or die("Database tidak bisa dibuka");
?>if still there is something wrong? RE: need help php code (My final project in college) - tijs14tijs - 06-21-2011 You use header(location), this doesnt work in all versions of internet explorer. you should rather echo "<meta http-equiv="refresh" content="0;url=' . sprintf("yourpage.php") . '" />"; RE: need help php code (My final project in college) - slbmeh - 06-30-2011 (05-06-2011, 03:22 PM)ghoza Wrote: I think it's my first connect the database. You need to assign the connect function to a variable which your code is set up to be $database. so PHP Code: // Koneksi dan memilih database di server
mysql_connect($server,$username,$password) or die("Koneksi gagal");
PHP Code: // Koneksi dan memilih database di server
$database = mysql_connect($server,$username,$password) or die("Koneksi gagal");
Edit: Also, header("Location: "); is a syntactically correct HTTP 1.0 301 redirect call. I believe IE has supported HTTP 1.0 fully since IE 3, however, not all browsers will recognize a meta or javascript redirect. |