Tag Archives: Password

insert data into your working databases

<?php
mysql_connect(“localhost”, “admin”, “password”) or die(mysql_error());
mysql_select_db(“test”) or die(mysql_error());

mysql_query(“insert into example(name,age) values(‘Timmy Smith’,’23’)”) or die(mysql_error());
mysql_query(“insert into example(name,age) values(‘Rachel Wang’,’23’)”) or die(mysql_error());
mysql_query(“insert into example(name,age) values(‘Timmy wallace’,’23’)”) or die(mysql_error());

echo “Data Inserted!”;
?>

use php and mysql create a page need user name and password

so ,you already set up your databases(in your databases already  had member), there add more then your could let your member log in.

after the form the follow codes use this instead

<?php
} else {
// connect to mysql
$mysql = mysqli_connect(“localhost”, “webauth”, “webauth”);
if(!$mysql) {
echo “Cannot connect to database.”;
exit;
}
// select the appropriate database
$selected = mysqli_select_db($mysql, “auth”);
if(!$selected) {
echo “Cannot select database.”;
exit;
}

// query the database to see if there is a record which matches
$query = “select count(*) from authorized_users where
name = ‘”.$name.”‘ and
password = sha1(‘”.$password.”‘)”;

$result = mysqli_query($mysql, $query);
if(!$result) {
echo “Cannot run query.”;
exit;
}
$row = mysqli_fetch_row($result);
$count = $row[0];

if ($count > 0) {
// visitor’s name and password combination are correct
echo “<h1>Here it is!</h1>
<p>I bet you are glad you can see this secret page.</p>”;
} else {
// visitor’s name and password combination are not correct
echo “<h1>Go Away!</h1>
<p>You are not authorized to use this resource.</p>”;
}
}
?>

create database “auth” into mysql

here is the sourse for your databases

create database auth, there just create 2 users, you could create as many as you like, just insert the user name  and passwords. of course you also could create a page for page register into, following post i will write how to create a page insert data into mysql
use auth;
create table authorized_users ( name varchar(20),
password varchar(40),
primary key     (name)
);
insert into authorized_users values ( ‘username’,
‘password’ );

insert into authorized_users values ( ‘testuser’,
sha1(‘password’) );
grant select on auth.*
to ‘webauth’
identified by ‘webauth’;
flush privileges;