Start New Discussion Reply to this Discussion PHP page refresh not sorted after using sessions - Pls HELP
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");
}
}}
?>
Related Article: php page refresh
is a PHP discussion thread by naru vaishnaw that has 1 reply and was last updated 1 year ago.
in4sys
Newbie Poster
1 post since Mar 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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");
Skelly1983
Newbie Poster
3 posts since Mar 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
© 2013 DaniWeb® LLC
Page rendered in 0.0591 seconds
using 2.68MB