You Now Here »

contoh simple coding php, connect database mysql, register, login  (Read 33237 times - 43 votes) 

DANNY

G-Plus Author
  • ADMINISTRATOR
  • More Share Forum Topic
  • [MS] kepala suku
  • *
  • DANNY sangat terkenal!DANNY sangat terkenal!DANNY sangat terkenal!DANNY sangat terkenal!DANNY sangat terkenal!DANNY sangat terkenal!
  • Rep Power: 6
  • Join: September 30, 2009
  • Posts: 11,927
  • Poin: 194.231
    • WWW
  • IP member tracker Logged


contoh simple coding php, connect database mysql, register, login
mudah2an bs membantu...
buat koleksi ane jg sebagai pembelajaran
:D

yg ini untuk file register.php

Quote
Code: [Select]
<!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=iso-8859-1" />
<title>Register</title>
</head>

<body>
<h1>Register</h1>
<table><tr>
<form action=register.php method=post>

<td width="81">Username:</td>
<td width="247"><input name="username" size="30" autocomplete="off" value="" type="text" /></td>

</tr><tr>

<td>Password:</td>
<td><input name="password" size="30" type="password" /></td>

</tr>

<tr>

<td>First Name:</td>
<td><input name="firstname" size="30" type="text" /></td>

</tr>

<tr>

<td>Last Name:</td>
<td><input name="lastname" size="30" type="text" /></td>

</tr>

<tr>

<td>Age:</td>
<td><input name="age" size="30" maxlength="2" /></td>

</tr>
</table>


<p><input type="submit" class="button" value="Register" /></p>
</form>
</body>
</html>

buat connect-in ke data base buat file mysql-connect.php

Quote
Code: [Select]
<?php
$con 
mysql_connect("DB_HOST","DB_USER","DB_PASS");
mysql_select_db("DB_NAME"$con);
?>


silakan replace, ato taro aja di area register.php , buat input kedatabase gunanya

Quote
Code: [Select]
<?php
include 'mysql-connect.php';
$username $_POST['username'];
$password $_POST['password'];
$firstname $_POST['firstname'];
$lastname $_POST['lastname'];
$age $_POST['age'];
$ip $_SERVER['REMOTE_ADDR'];

$result mysql_num_rows(mysql_query("SELECT * FROM TABLENAME WHERE username='$username'"));
if(
$result == 1)
    {
    echo 
<h1>ERROR!</h1>The username you have chosen already exists!;
    }
else
    {
    
mysql_query("INSERT INTO TABLENAME (username, password, firstname, lastname, age, ip)
VALUES ('
$username', '$password', '$firstname', '$lastname', '$age', '$ip')");

    echo 
'
  <p>Congratulations! You have successfully registered! </p>
  <p>Click <a href="login.php">here</a> to login.</p>‘;
?>

sekarang kite bikin script buat login login.php

Quote
Code: [Select]
<html>
<head>
<title>Login</title>
</head>
<body>
<form name="login" action="login2.php" method="post">


<table align="center"><tr>

<td class="title">Username</td>
<td><input name="user" size="30" autocomplete="off" value="" type="text" /></td>

</tr><tr>

<td class="title">Password</td>
<td><input name="pass" size="30" type="password" /></td>

</tr></table>


<p style="text-align:center;"><input type="submit" class="button" value="Login" /></p></form>
</body>
</html>

sekarang buat file login2.php ,  apa gunanya? buat validasi masuk kearea member, apakah data login ada pada database yg udah diinput waktu register tadi...

Quote
Code: [Select]
<?php
include 'mysql-connect.php';

$username $_POST['user'];
$password $_POST['pass'];
$query1 mysql_query("SELECT * FROM TABLENAME WHERE username='$username'");
$result mysql_num_rows($query1);
if(
$result == 0)
{
include 
'<h1>Error!</h1>The username you specified does not exist!';
}
else
{

$checkuser mysql_query("SELECT * FROM TABLENAME WHERE username='$username'");

            
$row mysql_fetch_array($checkuser);
                            
$password2 $row['password'];
                            
$status $row['status'];
                if (
$password == $password2)
                    {
                    
//PUT PASSWORD PROTECTED INFORMATION HERE
                    
}
                else
                    {
                    echo 
'<h1>Error!</h1>The username and password combination you entered does not match the ones we have in the database.';
                    }

}
?>

yoi, mungkin segitu aja dah cukup... silakan dicoba brhoo
moga bermanfaat
:beer:


View Mobile Web Short URL:
« Last Edit: May 02, 2010, 08:26:16 PM by admin_danny »

DANNY

G-Plus Author
  • ADMINISTRATOR
  • More Share Forum Topic
  • [MS] kepala suku
  • *
  • DANNY sangat terkenal!DANNY sangat terkenal!DANNY sangat terkenal!DANNY sangat terkenal!DANNY sangat terkenal!DANNY sangat terkenal!
  • Rep Power: 6
  • Join: September 30, 2009
  • Posts: 11,927
  • Poin: 194.231
    • WWW
  • IP member tracker Logged
Re: contoh simple coding php, connect database mysql, register, login
« Reply #1 on: May 02, 2010, 08:17:57 PM »
boking buat tambahan

rebrond

  • Global Moderator
  • More Share Forum Topic
  • [MS] rakyat jelata
  • ********
  • rebrond sangat terkenal!rebrond sangat terkenal!rebrond sangat terkenal!rebrond sangat terkenal!rebrond sangat terkenal!rebrond sangat terkenal!
  • Rep Power: 6
  • Join: March 29, 2010
  • Posts: 492
  • Poin: 820
  • About me: rebrond lulusan pakem
    • WWW
  • IP member tracker Logged
Re: contoh simple coding php, connect database mysql, register, login
« Reply #2 on: May 02, 2010, 08:22:08 PM »
nice share mod ane coba dulu
  :love:love:love:love:love
  :keren:keren:keren:keren

rizalubay

Re: contoh simple coding php, connect database mysql, register, login
« Reply #3 on: March 05, 2011, 09:40:07 PM »
ini salah satu script yg ane butuh nih ,,buat belajar php , kebetulan ane pengin mendalami PHP ... :matabelo
kalo ada lg, share lg ya min ,, :please