Login Register






need help php code (My final project in college) filter_list
Author
Message
need help php code (My final project in college) #1
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 5

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\travel\admin\cek_login.php on line 6

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\travel\admin\cek_login.php on line 7
please check, is there anything wrong?
thank's alot.
sorry if my language is less understood

Reply

RE: need help php code (My final project in college) #2
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);
I love creativity and creating, I love science and rational thought, I am an open atheist and avid self-learner.

Reply

RE: need help php code (My final project in college) #3
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?

Reply

RE: need help php code (My final project in college) #4
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") . '" />";

Reply

RE: need help php code (My final project in college) #5
(05-06-2011, 03:22 PM)ghoza Wrote: 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?

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");
should be
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.

Reply