Simple table like this
CREATE TABLE IF NOT EXISTS `users` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`username` varchar(25) NOT NULL,
`password` varchar(25) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=101 ;
<?php
session_start();
function insert(){
if(isset($_POST)&& isset($_SESSION['post_vars'])){
$insert_query="insert into users set username = '".$_SESSION['post_vars']['username']."' , password ='".$_SESSION['post_vars']['password']."'";
$result = mysql_query($insert_query);
if($result) {echo "<h1> successfully Added";
session_unset();
session_destroy();
return;
}
}
}
foreach($_POST as $key => $value) {
$_SESSION['post_vars'][$key] = $value;
}
$connection = mysql_connect('localhost','root','***');
if(!$connection)die('could not connect to the server check'.mysql_error());
else{
if(!$db=mysql_select_db("my_data",$connection))die('<p>error connecting to the database'.mysql_error());
else
{
$query_all="select * from users";
$query = "select username from users where id ='1'";
$result =mysql_query($query);
$result_all=mysql_query($query_all);
if($result){
if(mysql_num_rows($result)==0) die("there is no user for this for this user id");
$a=mysql_fetch_array($result);
if($a[0]=='admin') {
echo "Users are : ";
while($array=mysql_fetch_array($result_all)) {
echo $array[1].",";
}
echo "<form action='index.php' method='POST' onsubmit='alert('Sure?')";
echo "' >";
echo "<p>User Name<input type='text' id='username' name='username' value='" ;
if($_SESSION['post_vars']['username']){
echo $_SESSION['post_vars']['username']."'>";
}
else {
echo "'>";
echo "insert a user name";
unset($_POST);
}
echo "<p>Password<input type='text' id='password' name='password' value='";
if($_SESSION['post_vars']['password']){
echo $_SESSION['post_vars']['password']."'>";
}
else {
echo "'>";
echo "insert a password";
unset($_POST);
}
echo "<input type='submit' value='Add'></div>";
echo "</form>";
insert();
session_unset();
}else die("you dont have sufficient previlages to view this infomation");
}
}}
?>