To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Coding

Coding Help with PHP coding

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-07-2009, 05:10 PM   #1
chaseab
Junior Member
 
Join Date: May 2009
Posts: 14
Exclamation No errors but it's not working! Please Help

I have a login system that has login,register,and levels. I also have a admin control panel (admin.php) this is the code for that:
PHP Code:
<?php
session_start
();
include(
'/home/neochase/public_html/header.php');
if(
$_SESSION['level']>2)
{
echo
"<h2>ADMIN ACCESS GRANTED!</h2>";
echo
"<p><font size='6' face='Century Gothic'>Change a User Level</font>
<form action='aprocess.php' method='POST'>
<table>
        <tr>
            <td><font size='4' face='arial'>Username</font></td>
            <td><font size='4' face='arial'>Level</font></td>
        </tr>
        <tr>
            <td>
            <input type='text' name='username'>
            </td>
            <td>
            <select name='level'>
            <option>0</option>
            <option>2</option>
            <option>3</option>
            </select>
            </td>
            <td>
            <input type='submit' value='Change!' name='Changed'>
            </form>
            </td>
            </table><hr>"
;

echo
"<font size='6' face='Century Gothic'>Delete a User</font>
<form action='aprocess.php' method='POST'>
<table>
        <tr>
            <td><font size='4' face='arial'>Username</font></td>
        </tr>
        <tr>
            <td><input type='text' name='username'></td>
            <td><input type='submit' value='Change!' name='deleteuser'></td>
        </tr>
        </table><hr>"
;

}
else
    echo
"You must be an administrator to view this page!!!!!!!";


?>
I am trying to get the level change to work. I have a database named neochase_login table named users and id,name,username,password,date,level,and,email
I am working on the level field and here is my code for aprocess.php
PHP Code:
<?php
session_start
();
$connect = mysql_connect("localhost","username","password") or die("Couldn't connect to db!");
mysql_select_db("neochase_login") or die("Couldn't select db!");
$username = $_POST['username'];
$level = $_POST['level'];
$submit = $_POST['Changed'];
if(
$submit)//This processes Change User Level
{

$query = "UPDATE `neochase_login`.`users` SET `level` = '$level' WHERE `users`.`username` =$username";
if(
$query)
    echo
"Task Completed!";
else
    echo
"Epic Fail!";


}
    else
        echo
"You aren't supposed to access this file directly!";
?>
I always Get the Task Completed Message and nothing happens

Please Help,
Chase
chaseab is offline   Reply With Quote
Old 11-07-2009, 06:02 PM   #2
rincewind456
.--..--...-.-.-..
 
rincewind456's Avatar
 
Join Date: Nov 2005
Location: Rimwards
Posts: 1,354
You don't actually run an mysql query on $query.

and this line
PHP Code:
if($query)
will always be true as on the previous line you have set $query.

What you need to do is change this
PHP Code:
$query = "UPDATE `neochase_login`.`users` SET `level` = '$level' WHERE `users`.`username` =$username";
for this
PHP Code:
$query = mysql_query( "UPDATE `neochase_login`.`users` SET `level` = '$level' WHERE `users`.`username` =$username");
rincewind456 is offline   Reply With Quote
Old 11-07-2009, 06:13 PM   #3
chaseab
Junior Member
 
Join Date: May 2009
Posts: 14
Quote:
Originally Posted by rincewind456 View Post
You don't actually run an mysql query on $query.

and this line
PHP Code:
if($query)
will always be true as on the previous line you have set $query.

What you need to do is change this
PHP Code:
$query = "UPDATE `neochase_login`.`users` SET `level` = '$level' WHERE `users`.`username` =$username";
for this
PHP Code:
$query = mysql_query( "UPDATE `neochase_login`.`users` SET `level` = '$level' WHERE `users`.`username` =$username");
That worked but now I get Epic Fail! Please Help!
chaseab is offline   Reply With Quote
Old 11-08-2009, 06:03 AM   #4
rincewind456
.--..--...-.-.-..
 
rincewind456's Avatar
 
Join Date: Nov 2005
Location: Rimwards
Posts: 1,354
Then try changing your code to this
PHP Code:
<?php
session_start
();
$connect = mysql_connect("localhost","username","password") or die("Couldn't connect to db!");
mysql_select_db("neochase_login") or die("Couldn't select db!");
$username = $_POST['username'];
$level = $_POST['level'];
$submit = $_POST['Changed'];
if(
$submit)//This processes Change User Level
{

    
$query = "UPDATE `neochase_login`.`users` SET `level` = '$level' WHERE `users`.`username` =$username";
    
$result = mysql_query( $query);
    if(
$result)
    echo
"Task Completed!";
    else
    echo
"Epic Fail!", mysql_error('Query String: '.$query);


}
else
echo
"You aren't supposed to access this file directly!";
?>
to see what error is being returned.
rincewind456 is offline   Reply With Quote
Old 11-08-2009, 06:29 AM   #5
niroshan
Senior Member
 
niroshan's Avatar
 
Join Date: Nov 2002
Location: sri lanka
Posts: 208
PHP Code:
$query = "UPDATE `neochase_login`.`users` SET `level` = '$level' WHERE `users`.`username` = '".$username."'";
PS: Note the single quotes before and after the $username since its a string type
__________________
Be the best you can be!!!!!
niroshan is offline   Reply With Quote
Old 11-08-2009, 06:54 AM   #6
rincewind456
.--..--...-.-.-..
 
rincewind456's Avatar
 
Join Date: Nov 2005
Location: Rimwards
Posts: 1,354
Quote:
Originally Posted by niroshan View Post
PHP Code:
$query = "UPDATE `neochase_login`.`users` SET `level` = '$level' WHERE `users`.`username` = '".$username."'";
PS: Note the single quotes before and after the $username since its a string type
But you don't need to concatenate the query string, as the variables are expanded within double quoted strings.
PHP Code:
$query = "UPDATE `neochase_login`.`users` SET `level` = '$level' WHERE `users`.`username` ='$username'";
rincewind456 is offline   Reply With Quote
Reply

Bookmarks

Tags
login system, php help


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

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
Forum Jump


All times are GMT -4. The time now is 04:33 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.