Current location: Hot Scripts Forums » Programming Languages » PHP » $username how can I save


$username how can I save

Reply
  #1 (permalink)  
Old 08-02-07, 12:09 PM
Hamed Hamed is offline
Wannabe Coder
 
Join Date: Jan 2007
Posts: 188
Thanks: 2
Thanked 0 Times in 0 Posts
$username how can I save

PHP Code:

<?php

session_start
();
if(!
session_is_registered(myusername)){
header("location:mlogin.php");
}
include 
"db.php";
//Now serails
//username for welcome
$username $_GET['username'];
//mean panel page
if($_GET['act'] == 'idx'){
    
$username $_GET['username'];
    include 
"theme/login.htm";
}
//add new S/N for a simple program but not active
if($_GET['act'] == 'newsn'){
    include 
"theme/addsn.htm";
    
$username $_GET['username'];
}
if(
$_GET['act'] == 'addnewsn'){
    
$username $_GET['username'];
    
$sql="SELECT * FROM users WHERE username='$username' LIMIT 1";
    
$result=mysql_query($sql);
    while (
$user mysql_fetch_array($result)){
    
$rate $user['rate'];
    }
    
$sid '';
    
$swname $_POST['swname'];
    
$swsn $_POST['swsn'];
if(
$rate >= 25){
    
$act 'YES';
    
mysql_query("INSERT INTO `swsn` (
`sid` ,
`swname` ,
`swsn` ,
`act` ,
`username`
)
VALUES (
'', '
$swname', '$swsn', 'YES', '$username'
);"
);
    include 
"theme/addsn_yes.htm";
    }else{
        
$act 'NO';
        
mysql_query("INSERT INTO `swsn` (
`sid` ,
`swname` ,
`swsn` ,
`act` ,
`username`
)
VALUES (
'', '
$swname', '$swsn', 'NO', '$username'
);"
);
        include 
"theme/addsn_no.htm";
        }
    }
    
//make finder
if($_GET['act'] == 'find'){
    
$username $_GET['username'];
    include 
"theme/find.htm";
}
if(
$_GET['act'] == 'finder'){
    
$username $_GET['username'];
    
$keyword $_POST['keyword'];
    
$sql "SELECT *
FROM `swsn`
WHERE `swname` LIKE CONVERT( _utf8 '
$keyword'
USING latin1 )
COLLATE latin1_general_ci
AND `act` = CONVERT( _utf8 'YES'
USING latin1 )
COLLATE latin1_general_ci"
;
$swfind=mysql_query($sql);
$count=mysql_num_rows($sql);
if(
$count==0){
    include 
"theme/nore.htm";
}else{
    echo 
'<html dir="rtl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="theme/css.css">
<title>Finder</title>
</head>
<body>
<br /><br /><br /><br /><br /><br /><br />
<div class="wall">'
;
while (
$finds mysql_fetch_array($swfind)){
  
$swname $finds['swname'];
  
$swsn $finds['swsn'];
  
$users $finds['username'];
  include 
"theme/findbit.htm";
 }
include 
"theme/footer.htm";
}
}
// make alphabet list
if($_GET['act'] == 'list'){
    
$username $_GET['username'];
    include 
"theme/list.htm";
    }
if(
$_GET['get']){
    
$letter $_GET['get'];
$sqlruns mysql_query("
    SELECT *
    FROM swsn
    WHERE swname LIKE '
$letter%'
    AND `act` = CONVERT( _utf8 'YES'
USING latin1 )
COLLATE latin1_general_ci
    ORDER BY swname
"
)or die (mysql_error()); 
echo 
'<html dir="rtl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="theme/css.css">
<title>LIST of all</title>
</head>
<body>
<br /><br /><br /><br /><br /><br /><br />
<div class="wall">'

while(
$sws mysql_fetch_array($sqlruns)){
    
$swname $sws['swname'];
    
$swsn $sws['swsn'];
    
$users $sws['username'];
    include 
"theme/findbit.htm";
    }
    include 
"theme/footer.htm";
    }
//now we make all as a list
if($_GET['act'] == 'lists'){
    
$username $_GET['username'];
    
$keyword $_POST['keyword'];
    
$sql "SELECT *
FROM `swsn`
AND `act` = CONVERT( _utf8 'YES'
USING latin1 )
COLLATE latin1_general_ci"
;
$swfind=mysql_query($sql);
echo 
'<html dir="rtl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="theme/css.css">
<title>Finder</title>
</head>
<body>
<br /><br /><br /><br /><br /><br /><br />
<div class="wall">'
;
while (
$finds mysql_fetch_array($swfind)){
  
$swname $finds['swname'];
  
$swsn $finds['swsn'];
  
$users $finds['username'];
  include 
"theme/findbit.htm";
  
 }
 
$username $_GET['username'];
include 
"theme/footer.htm";
}
//now we make what users post
if($_GET['act'] == 'ours'){
    
$username $_GET['username'];
    
$keyword $_POST['keyword'];
    
$sql "SELECT *
FROM `swsn` WHERE username='
$username'
AND `act` = CONVERT( _utf8 'YES'
USING latin1 )
COLLATE latin1_general_ci"
;
$swfind=mysql_query($sql);
echo 
'<html dir="rtl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="theme/css.css">
<title>Your Posts</title>
</head>
<body>
<br /><br /><br /><br /><br /><br /><br />
<div class="wall">'
;
while (
$finds mysql_fetch_array($swfind)){
  
$swname $finds['swname'];
  
$swsn $finds['swsn'];
  
$users $finds['username'];
  include 
"theme/findbit.htm";
  
 }
include 
"theme/footer.htm";
}
if(
$_GET[act] == 'out')
{
session_destroy();
echo 
"<meta http-equiv=\"refresh\" content=\"0;URL=mlogin.php\" /";
}
?>
these are my code I want to get $username one time and after that when I use $usename it give what I get at 1st with $_GET['username']
Reply With Quote
  #2 (permalink)  
Old 08-02-07, 12:44 PM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
PHP Code:

<?php

session_start
();

// Only set username if it's not already saved
if ( !isset( $_SESSION['username'] ) )
    
$_SESSION['username'] = isset( $_GET['username'] ) ? $_GET['username'] : '';

// Reference w/ $username
$username = & $_SESSION['username'];

// Then throughout your script...
echo $username;

?>
Then just call file.php?username=### and $username is assigned for the duration of the session.

Be sure to sanitize the value though before throwing it into a MySQL query!
__________________
The toxic ZCE
Reply With Quote
  #3 (permalink)  
Old 08-02-07, 01:17 PM
Hamed Hamed is offline
Wannabe Coder
 
Join Date: Jan 2007
Posts: 188
Thanks: 2
Thanked 0 Times in 0 Posts
It won't help me!
Reply With Quote
  #4 (permalink)  
Old 08-05-07, 03:00 PM
Hamed Hamed is offline
Wannabe Coder
 
Join Date: Jan 2007
Posts: 188
Thanks: 2
Thanked 0 Times in 0 Posts
bad bad

PHP Code:

<?php

session_start
();
// Only set username if it's not already saved
if ( !isset( $_SESSION['username'] ) )
    
$_SESSION['username'] = isset( $_GET['username'] ) ? $_GET['username'] : '';

// Reference w/ $username
$username = & $_SESSION['username'];


if(!
session_is_registered(myusername)){
header("location:mlogin.php");
}
include 
"db.php";
//Now serails
//username for welcome
//mean panel page
if($_GET['act'] == 'idx'){
    include 
"theme/login.htm";
}
//add new S/N for a simple program but not active
if($_GET['act'] == 'newsn'){
include 
"theme/addsn.htm";
}
if(
$_GET['act'] == 'addnewsn'){
    
$sql="SELECT * FROM users WHERE username='$username' LIMIT 1";
    
$result=mysql_query($sql);
    while (
$user mysql_fetch_array($result)){
    
$rate $user['rate'];
    }
    
$sid '';
    
$swname $_POST['swname'];
    
$swsn $_POST['swsn'];
if(
$rate >= 25){
    
$act 'YES';
    
mysql_query("INSERT INTO `swsn` (
`sid` ,
`swname` ,
`swsn` ,
`act` ,
`username`
)
VALUES (
'', '
$swname', '$swsn', 'YES', '$username'
);"
);
    include 
"theme/addsn_yes.htm";
    }else{
        
$act 'NO';
        
mysql_query("INSERT INTO `swsn` (
`sid` ,
`swname` ,
`swsn` ,
`act` ,
`username`
)
VALUES (
'', '
$swname', '$swsn', 'NO', '$username'
);"
);
        include 
"theme/addsn_no.htm";
        }
    }
    
//make finder
if($_GET['act'] == 'find'){
    
    include 
"theme/find.htm";
}
if(
$_GET['act'] == 'finder'){
    
    
$keyword $_POST['keyword'];
    
$sql "SELECT *
FROM `swsn`
WHERE `swname` LIKE CONVERT( _utf8 '
$keyword'
USING latin1 )
COLLATE latin1_general_ci
AND `act` = CONVERT( _utf8 'YES'
USING latin1 )
COLLATE latin1_general_ci"
;
$swfind=mysql_query($sql);
$count=mysql_num_rows($swfind);
if(
$count==0){
    include 
"theme/nore.htm";
}else{
include 
"theme/head.htm";
while (
$finds mysql_fetch_array($swfind)){
  
$swname $finds['swname'];
  
$swsn $finds['swsn'];
  
$users $finds['username'];
  include 
"theme/findbit.htm";
   }
include 
"theme/footer.htm";
 }
}
// make alphabet list
if($_GET['act'] == 'list'){
    include 
"theme/list.htm";
    }
if(
$_GET['get']){
    
$letter $_GET['get'];
$sqlruns mysql_query("
    SELECT *
    FROM swsn
    WHERE swname LIKE '
$letter%'
    AND `act` = CONVERT( _utf8 'YES'
USING latin1 )
COLLATE latin1_general_ci
    ORDER BY swname
"
)or die (mysql_error());
$count=mysql_num_rows($sqlruns);
if(
$count==0){
    include 
"theme/nore.htm";}else{ 
include 
"theme/head.htm";
while(
$sws mysql_fetch_array($sqlruns)){
    
$swname $sws['swname'];
    
$swsn $sws['swsn'];
    
$users $sws['username'];
    include 
"theme/findbit.htm";
    }
    include 
"theme/footer.htm";
    }
}
//now we make all as a list
if($_GET['act'] == 'lists'){
    
$sql = ("SELECT *
FROM `swsn`
WHERE `act` = CONVERT( _utf8 'YES'
USING latin1 )
COLLATE latin1_general_ci"
) or die (mysql_error());
$swfind=mysql_query($sql);
include 
"theme/head.htm";
while (
$finds mysql_fetch_array($swfind)){
  
$swname $finds['swname'];
  
$swsn $finds['swsn'];
  
$users $finds['username'];
  include 
"theme/findbit.htm";
  
 }
 
include 
"theme/footer.htm";
}
//now we make what users post
if($_GET['act'] == 'ours'){
$usename $_GET['username'];
    
$sql = ("SELECT *
FROM `swsn` WHERE username='
$username'
AND `act` = CONVERT( _utf8 'YES'
USING latin1 )
COLLATE latin1_general_ci"
) or die (mysql_error());
$swfind=mysql_query($sql);
include 
"theme/head.htm";
while (
$finds mysql_fetch_array($swfind)){
  
$swname $finds['swname'];
  
$swsn $finds['swsn'];
  
$users $finds['username'];
  
$sid $finds['sid'];
  include 
"theme/userbit.htm";
  
 }
include 
"theme/footer.htm";
}
//make edit for user posts
if($_GET['act'] == 'edit'){
    
$sid $_GET['sid'];
    
$sqls=mysql_query("SELECT * FROM swsn WHERE sid='$sid' LIMIT 1") or die (mysql_error());
while(
$rows=mysql_fetch_array($sqls)){
    
$swnamen $rows['swname'];
    
$swsnn $rows['swsn'];
    
$sids $rows['sid'];
    }
    include 
"theme/editsn.htm";
    }
if(
$_GET['act'] == 'editnewsn'){
    
$sql="SELECT * FROM users WHERE username='$username' LIMIT 1";
    
$result=mysql_query($sql);
    while (
$user mysql_fetch_array($result)){
    
$rate $user['rate'];
    }
    
$swname $_POST['swname'];
    
$sid $_POST['sid'];
    
$swsn $_POST['swsn'];
if(
$rate >= 25){
    
mysql_query("UPDATE `swsn` SET `swname` = '$swname',
`swsn` = '
$swsn' , act = 'YES' WHERE `sid` = '$sid' LIMIT 1") or die (mysql_error());
    include 
"theme/addsn_yes.htm";
    }else{
            
mysql_query("UPDATE `swsn` SET `swname` = '$swname',
`swsn` = '
$swsn' , act = 'NO' WHERE `sid` = '$sid' LIMIT 1") or die (mysql_error());
        include 
"theme/addsn_no.htm";
        }
    }

//logout link
if($_GET[act] == 'out')
{
session_destroy();
echo 
"<meta http-equiv=\"refresh\" content=\"0;URL=mlogin.php\">";
}
?>
Now I use this but it won't word for me!
Reply With Quote
  #5 (permalink)  
Old 08-05-07, 03:08 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
The session_is_registered() function is depreciated, it only works when register globals are enabled, and should not be mixed with code using $_SESSION[...].

You need to rewrite your code using current coding standards.

One other possible reason why your code might not be working is that your mysql_ function calls might be failing, but there is no error checking and error reporting code to tell you if they worked or not. The php manual contains examples of error checking logic in the examples under each mysql function definition.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???

Last edited by mab; 08-05-07 at 03:10 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
save as dialog and delete controls on a toolbar? fairychick85 Windows .NET Programming 1 02-05-07 05:40 AM
Save As in Visual Basic iceiceady Visual Basic 2 04-28-06 02:27 PM
i need a script to upload images and save it into database darroosh Script Requests 7 01-29-06 04:23 PM
XMG Hosting Re-Opening! Save 15%! JSXtremist General Advertisements 0 08-01-05 11:29 AM
'save as' option for XML files hulkphil JavaScript 1 03-04-05 09:15 AM


All times are GMT -5. The time now is 06:07 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.