Tolong pilih kategori sesuai, jenis posting (diskusi atau bukan) dan sertakan tag/topik yang sesuai seperti komputer, java, php, mysql, dll. Promosi atau posting tidak pada tempatnya akan kami hapus!
- Bagi Anda yang ingin mendaftar, baca link berikut:
http://diskusiweb.com/discussion/50491/how-to-registrasi-diskusiweb-com-baca-ini-terlebih-dahulu
- Cara menyisipkan kode program supaya tampil rapi dan terformat dengan baik di diskusiweb.com: http://www.diskusiweb.com/discussion/50415/cara-menyisipkan-kode-program-di-diskusiweb-com
- Cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

user login dg md5 slalu gagal

mau tanya lagi master ketika sy login, ada pesan bgni

Parse error: syntax error, unexpected '$password' (T_VARIABLE) in C:\xampp\htdocs\murid\test\cek_login.php on line 14
koding
<?
session_start();
include ("koneksi.php");
$username = $_POST['username'];
$password = md5($_POST['password']);
if (empty($username)){
echo "<script>alert('Username belum diisi')";
//echo "";
}else if (empty($password)){
echo "alert('Password belum diisi')";
//echo "";
}else{

$login = mysql_query('select * from use where username="$username" and password='$password"');
if (mysql_num_rows($login) > 0){

$_SESSION['username'] = $username;
header("location:index.php");
}else{
echo "alert('Username atau Password salah')";
//echo "";
}
}

?>

Comments

  • 'select * from use where username="$username" and password='$password"'

    coba di cek lagi quote nya

    elo pake '...' buat string
    artinya kalo di dalamnya ada variable, ya elo mesti pake operand DOT / TITIK
  • edited April 17
    sy cb jd sprti ini
    mysql_query('select * from user where username=".$username" and password=".$password"');
    ,tetap usernama dn paaword salah
    Dn keterangan error
    syntax error, unexpected '$password' (T_VARIABLE) in C:\xampp\htdocs\murid\test\cek_login.php on line 14
  • sudah di ubah jadi kaya apa ?
    tolong dong langsung di posting tanpa diminta
  • edited April 17
    Maaf jaringan gangguan

    Jd kyk gni
    session_start();
    include ("koneksi.php");
    $username = $_POST['username'];
    $password = md5($_POST['password']);
    if (empty($username)){
    echo "alert('Username belum diisi')";
    //echo "";
    }else if (empty($password)){
    echo "alert('Password belum diisi')";
    //echo "";
    }else{

    $login = mysql_query('select * from user where username=".$username" and password=".$password"');
    if (mysql_num_rows($login) > 0){

    $_SESSION['username'] = $username;
    header("location:index.php");
    }else{
    echo "alert('Username atau Password salah')";
    //echo "";
    }
    }
  • edited April 17
    'select * from user where username=".$username" and password=".$password"'

    padahal di tret yg satunya sudah ada contohnya lho ...

    'INSERT INTO
    murid(id,nim,tgl,nama,tlahir,tgllahir,alamat,rtrw,desa,kecamatan,kabupaten,provinsi,kls,waliayah,waliibu,alamat2,rtrw2,desa2,kec2,kab2,user)
    VALUES (
    NULL,
    "' . $nim . '",
    "' . $tgl . '",
    "' . $nama . '",
    "' . $tlahir . '",
    "' . $tgllahir . '",
    "' . $alamat . '",
    "' . $rtrw . '",
    "' . $desa . '",
    "' . $kecamatan . '",
    "' . $kabupaten . '",
    "' . $provinsi . '",
    "' . $kls . '",
    "' . $waliayah . '",
    "' . $waliibu . '",
    "' . $alamat2 . '",
    "' . $rtrw . '",
    "' . $desa2 . '",
    "' . $kec2 . '",
    "' . $kab2 . '",
    "' . $user . '"
    )'

    coba dah gw hapus string yg panjang dan gw sederhakan biar lebih jelas ...

    'INSERT INTO murid(...) VALUES (NULL,"' . $nim . '","' . $tgl . '","' . $user . '")'

    'INSERT INTO murid(...) VALUES (NULL,"' . $nim . '","' . $tgl . '","' . $user . '")'

    coba diperhatikan baik-baik QUOTE nya dan operand TITIK nya

    sepasang-sepasang apa ndak ?
  • Owww,mf, gk mudeng2, klo msh bru blajar sring slh, trim ksh
  • edited April 17
    Mf
  • Stl cb gnti sprti ini
    Msh tetap gagal keterangannya sama

    $login = mysql_query('select * from user where username="'.$username.'" and password="'.$password.'"');
    if (mysql_num_rows($login) > 0){.....
  • koding lengkap nya jadi kaya apa ?

    pesan error lengkap nya apa ?
  • Ini koding lengkapnya
    session_start();
    include ("koneksi.php");
    $username = $_POST['username'];
    $password = md5($_POST['password']);
    if (empty($username)){
    echo "alert('Username belum diisi')";
    //echo "";
    }else if (empty($password)){
    echo "alert('Password belum diisi')";
    //echo "";
    }else{

    $login = mysql_query('select * from user where username="'.$username.'" and password="'.$password.'"');
    if (mysql_num_rows($login) > 0){

    $_SESSION['username'] = $username;
    header("location:index.php");
    }else{
    echo "alert('Username atau Password salah')";
    //echo "";
    }
    }
  • edited April 17
    lha wong pesan error nya beda kok dibilang sama to maassss ...

    coba to itu ...
    mysql_query(...);

    diubah jadi :
    mysql_query(...) or die(mysql_errno().': '.mysql_error());

    pesan error yg nungul, posting lengkap kemari



    btw, ini gw yg bingung ...
    di tret yg satunya, elo pake nya mysqli_*
    yg ini pake mysql_*

    ini aplikasi yg sama ? atau beda ?

    elo bikin koneksinya pake mysql_connect() ?
    atau mysqli_connect() ?
  • edited April 17
    Yg stunya sy td cb pkek mysql_connect td error trus, akhirnya sy cb pekek mysqli_connet, klo stunya sy pakek
    Aplikasi sama, cm mikirnya yg sdh agak bingaung.hehe,


    Apa bdanya?
  • edited April 17
    kalo elo koneksi pake mysqli_connect(),
    elo ndak bakal bisa query pake mysql_query()

    kalo pake mysqli_* , ya seterusnya pake mysqli_*

    kalo mau pake mysql_query(), ya elo koneksinya pake mysql_connect()



    itu file koneksi.php isinya apa ?
    elo di situ bikin koneksi pake apa ?
    mysql_connect() atau mysqli_connect() ?
  • ya ndak bakal nyambung maasssss ...

    elo koneksi pake mysqli_connect()
    tapi query pake mysql_query()
    lalu ngitung rows pake mysql_num_rows()

    ndak bakal nyambung
    ya pantes error elo nungul
    lha wong emang ndak nyambung ama database nya

    pake mysqli_query()
    lalu pake mysqli_num_rows()
  • Berrarti yg bener pakek apa?
  • labalaba said:

    pake mysqli_query()
    lalu pake mysqli_num_rows()

  • Mf, stlh dcb muncul gni, trim ksh sdh mulai nyambung
  • edited April 17
    http://php.net/manual/en/mysqli.query.php

    Procedural style
    mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )

    Parameters
    link
    Procedural style only: A link identifier returned by mysqli_connect() or mysqli_init()

    query
    The query string.
    Data inside the query should be properly escaped.



    http://php.net/manual/en/mysqli.query.php#refsect1-mysqli.query-examples
    <?php
    $link = mysqli_connect("localhost", "my_user", "my_password", "world");

    /* check connection */
    if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
    }

    /* Create table doesn't return a resultset */
    if (mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City") === TRUE) {
    printf("Table myCity successfully created.\n");
    }

    /* Select queries return a resultset */
    if ($result = mysqli_query($link, "SELECT Name FROM City LIMIT 10")) {
    printf("Select returned %d rows.\n", mysqli_num_rows($result));

    /* free result set */
    mysqli_free_result($result);
    }

    /* If we have to retrieve large amount of data we use MYSQLI_USE_RESULT */
    if ($result = mysqli_query($link, "SELECT * FROM City", MYSQLI_USE_RESULT)) {

    /* Note, that we can't execute any functions which interact with the
    server until result set was closed. All calls will return an
    'out of sync' error */
    if (!mysqli_query($link, "SET @a:='this will not work'")) {
    printf("Error: %s\n", mysqli_error($link));
    }
    mysqli_free_result($result);
    }

    mysqli_close($link);
    ?>
  • Sy pelajari dlu, trim kasih bxk ilmux, mdh2 cpt nyambung
  • Sy pelajari dlu, trim kasih bxk ilmux, mdh2 cpt nyambung

  • stlh sy coba baca bolak balik yg q paham jadi scrip dibwah ini, lalau muncul error
    Warning: mysqli_num_rows() expects exactly 1 parameter, 2 given in C:\xampp\htdocs\murid\test1\cek_login.php on line 16, mohon pencerahannya dn arahannya, trim ksih
    <?
    <?php
    session_start();
    $conn = mysqli_connect('localhost','Assist','Irac');
    mysqli_select_db($conn,'madrash');
    $username = $_POST['username'];
    $password = md5($_POST['password']);
    if (empty($username)){
    echo "<script>alert('Username belum diisi')";
    //echo "";
    }else if (empty($password)){
    echo "alert('Password belum diisi')";
    //echo "";
    }else{

    $login = mysqli_query($conn,'select * from user where username="'.$username.'" and password="'.$password.'"') or die (mysql_errno().':'.mysql_error());
    if (mysqli_num_rows($conn,$login) > 0){

    $_SESSION['username'] = $username;
    header("location:index.php");
    }else{
    echo "alert('Username atau Password salah')";
    //echo "";
    }
    }

    ?>
  • edited April 18
    mysqli_num_rows() ndak pake $conn
    jangan lalu semua dihantam pake $conn

    dibaca napa manual php nya ...
    http://php.net/manual/en/mysqli-result.num-rows.php

    int mysqli_num_rows ( mysqli_result $result )

    Parameters
    result
    Procedural style only: A result set identifier returned by mysqli_query(), mysqli_store_result() or mysqli_use_result().

    http://php.net/manual/en/mysqli-result.num-rows.php#refsect1-mysqli-result.num-rows-examples

    Example #2 Procedural style
    <?php
    $link = mysqli_connect("localhost", "my_user", "my_password", "world");

    /* check connection */
    if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
    }

    if ($result = mysqli_query($link, "SELECT Code, Name FROM Country ORDER BY Name")) {

    /* determine number of rows result set */
    $row_cnt = mysqli_num_rows($result);

    printf("Result set has %d rows.\n", $row_cnt);

    /* close result set */
    mysqli_free_result($result);
    }

    /* close connection */
    mysqli_close($link);
    ?>
  • Mf, Sdh sy bc, tp gak faham dg bhs inggris, sy terjmh ke bhs indo tp yg bs sy fhm cm sgtu,
  • Gmn cr untuk bs cpt fhm sperti mas ini, soalnya sy baca diulang2 sdikit yg sy fahami
    Klo ada crax atau kunci tlong share. Trim ksh bxk
  • edited April 18
    Stlh sy ubah jd gni
    Cm ada keterangan user dn password salah
    if (mysqli_num_rows($login) > 0){
  • User dn passwornya gni..
  • edited April 18
    lha koding nya sudah jadi spt apa ?

    contoh nya kan sudah ditulis kaya begini :
    mysqli_num_rows($result);

    $result itu asal nya dari
    $result = mysqli_query($link, "SELECT Code, Name FROM Country ORDER BY Name")



    punye elo kan tinggal hapus $conn nya doang

    if (mysqli_num_rows($conn,$login) > 0){

    jadi

    if (mysqli_num_rows($login) > 0){

    $login itu asal nya dari
    $login = mysqli_query($conn,'select * from user where username="'.$username.'" and password="'.$password.'"')

    sudah sama to ?
    ada masalah apa lagi ?



    kalo gagal login ...
    ya berarti antara username atau password nya salah

    kalo liat database elo, username nya "a" (tanpa quote)
    tapi password nya ya elo yg tau
    kan elo yg bikin md5 nya
    itu asalnya dari string apa ?

    misal gini, gw bikin username "ali" (tanpa quote)
    lalu gw mau password nya "test" (tanpa quote)
    "test" itu md5 nya : 098f6bcd4621d373cade4e832627b4f6

    elo bisa coba :
    <?php
    echo md5('test');
    ?>

    hasilnya pasti : 098f6bcd4621d373cade4e832627b4f6

    itu berarti saat login, yg gw isikan di form login ya ...
    username : ali
    password : test

    login dah

    tapi yg tersimpan di table database :

    username | password
    ali | 098f6bcd4621d373cade4e832627b4f6
  • edited April 18
    Sdh sy ganti sprti diatas mas
    $login = mysqli_query($conn,'select * from user where username="'.$username.'" and password="'.$password.'"') or die (mysql_errno().':'.mysql_error());
    if (mysqli_num_rows($login) > 0){

    $_SESSION['username'] = $username;
    header("location:index.php");
    }else{
    echo "alert('Username atau Password salah')";
    //echo "";
  • edited April 18
    ada keterangan gni

  • baca ulang reply gw
  • baik, trim ksh bxk ilmu dn pencerahannya
  • elo bisa coba ...

    echo "alert('Username atau Password salah')";

    ganti dgn :

    echo "alert('Username : ".$username."\nPassword : ".$password."')";

    jalankan, coba login
    kalo gagal, muncul pemberitahuan username & md5 password yg elo isikan

    bandingkan manual dgn data yg ada di table elo
    sama atau enggak ?

    kalo beda, ya bener kalo ndak bisa login

    kalo sama dan ndak bisa login, baru dicari sumber masalahnya
  • edited April 18
    mf,
  • itu yg gw minta di ganti alert nya sudah dicoba belum ?

    tampilan alert nya posting kemari
  • edited April 18
    mf, sdh sy tes beberapa kali muncul
    alert('Username : a Password : 0cc175b9c0f1b6a831c399e269772661')

    koding
    form
    <?php
    $conn = mysqli_connect('localhost','Assist',' Irac;
    mysqli_select_db($conn,'madrash');
    session_start();
    if (isset($_SESSION['username'])){
    header ("location:index.php");
    }
    ?>
    <html>
    <head>
    <title>LOGIN</title>
    </head>
    <body>
    <form method="post" name="login" action="cek_login.php">
    <table border=0 align="center" cellpadding=5 cellspacing=0>
    <tr>
    <td colspan=3><center><font size=5>LOGIN</font></center></td>
    </tr>
    <tr>
    <td>Username</td>
    <td>:</td>
    <td><input type="text" name="username"></td>
    </tr>
    <tr>
    <td>Password</td>
    <td>:</td>
    <td><input type="password" name="password"></td>
    </tr>
    <tr>
    <td colspan=2></td>
    <td><input type="submit" name="submit" value="LOGIN"></td>
    </tr>
    <tr>
    <td colspan=3><a href="daftar.php">DAFTAR</a></td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    verifikasi login
    <?php
    session_start();
    $conn = mysqli_connect('localhost','Assist','Irac');
    mysqli_select_db($conn,'madrash');
    $username = $_POST['username'];
    $password = md5($_POST['password']);
    if (empty($username)){
    echo "<script>alert('Username belum diisi')</script>";
    //echo "<meta http-equiv='refresh' content='1 url=login.php'>";
    }else if (empty($password)){
    echo "<script>alert('Password belum diisi')</script>";
    //echo "<meta http-equiv='refresh' content='1 url=login.php'>";
    }else{

    $login = mysqli_query($conn,'select * from user where username="'.$username.'" and password="'.$password.'" ') or die(mysql_errno().': '.mysql_error());
    if (mysqli_num_rows($login) > 0){

    $_SESSION['username'] = $username;
    header("location:index.php");
    }else{
    echo "alert('Username : ".$username."\nPassword : ".$password."')";
    //echo "<meta http-equiv='refresh' content='1 url=login.php'>";
    }
    }

    ?>
  • alert('Username : a Password : 0cc175b9c0f1b6a831c399e269772661')



    0cc175b9c0f1b6a831c399e269772661 ... dari form elo
    dibanding
    0cc175b9c0f1b6a831c399e26 ... di database
    sama atau enggak ?

    itu kok bisa panjang yg di database cuma 25 karakter ?
    emang table nya elo definisi kan kaya apa ?
    password elo definisikan brp panjang nya ?

    md5 itu panjangnya 32 karakter
  • trim ksh banyak smg ms pajang umur barokah dan banyak rizqinya.Amin, sdh faham, ternyata distu masalahnya, sampek mumet mikirnya
  • mf, apa mksd dr \n di \nPassword
  • Sy kira md5 itu sdh otomatis menyesuaikan
  • edited April 18
    lha bukannya sudah gw tulis di atas ...
    labalaba said:

    ...
    jalankan, coba login
    kalo gagal, muncul pemberitahuan username & md5 password yg elo isikan

    bandingkan manual dgn data yg ada di table elo
    sama atau enggak ?

    ...

    lha gimana ? masa ndak dibandingin ?



    \n itu "new line" / baris baru

    kalo di html <br>

    kalo di file text ...
    di window : \r\n
    di linux / *nix : \n

    dialog box ... tergantung aplikasinya
    aplikasi desktop (delphi, c/c++, vb, dll) biasanya juga \n
    javascript yg notabene jalan di browser juga \n
    vba (vb for aplication, bawaannya ms office) itu juga \n

    elo isi form yg pake <textarea> itu kalo ada baris barunya ngikut os
    di window : \r\n
    di linux / *nix : \n

    macam-macam, tergantung elo ngadepinnya apa
  • trim ksih banyak ilmux, sy bandingkan mas, tp stlh sarannya, soalnya yg ke bc kepikiran sy md5 menyesuaikan otomatis
  • Alhamdulillah sukses
Sign In or Register to comment.