0

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");


}








 

}}



?>
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Skelly1983
0

Use a hidden form element in the login form which has a its value set using php:

<input name="login[url]" type="hidden" value="<?php echo URL; ?>" />

And then use the following on successful login:

define('SITE', "http://".$_SERVER['SERVER_NAME']);

    if (!empty($_SERVER["QUERY_STRING"])) { // Check for query strings
        define('URL', SITE.$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']);
    } else {
        define('URL', SITE.$_SERVER['PHP_SELF']);
    }

    $url = $_POST['login']['url'];

    header("Location: $url");
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.