TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-26-2008, 05:31 PM   #1 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Application Error New Problem - Help is needed Ty in adv!

LOOK DOWN FOR HELPING ME ON A OTHER PROBLEM





PHP Code:
<?php
error_reporting
(E_ALL & ~E_NOTICE);
include(
"db_connect.php");

$sql "SELECT * FROM `users` WHERE `id` = '".$id."'";
                
$query mysql_query($sql) or die(mysql_error());
        while(
$sel_table mysql_fetch_array($query)) 
        {
  print 
$sel_table['username'];

}
    
$net "UPDATE `users` SET `username` = '".$username."', `password` = '".$password."' WHERE `id` = '".$id."'";
    
$web_result mysql_query($net) or die(mysql_error());


?>
no errors are made i am trying to do print $sel_table['username'] or even post the id or something but for some reason it do not print..

so please tell me whats wrong :S

//Code,-No flame please ;)-

Code:
CREATE TABLE `users` (
  `id` int(11) NOT NULL auto_increment,
  `username` varchar(30) NOT NULL,
  `password` varchar(40) NOT NULL,
  `email` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

LOOK DOWN FOR HELPING ME ON A OTHER PROBLEM

Last edited by codefreek : 06-26-2008 at 09:56 PM. Reason: Look down for new problem!
codefreek is offline  
Reply With Quote
Old 06-26-2008, 06:17 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Where are you getting $id from? And there's nothing going on inside of your while loop so I'm not sure where you're getting the other variables from either, but if $id is an empty value then chances are your query isn't returning any errors, but it's not returning any data either.
-m
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
codefreek (06-26-2008)
Old 06-26-2008, 07:06 PM   #3 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default -

Quote:
Originally Posted by delayedinsanity View Post
Where are you getting $id from? And there's nothing going on inside of your while loop so I'm not sure where you're getting the other variables from either, but if $id is an empty value then chances are your query isn't returning any errors, but it's not returning any data either.
-m


//delayedinsanity
I just want to know why it is not letting me get any of the data from db table users?..

like $sel_table['username']
or $username as a var,

Thank you in adv.


EDIT:
i get bool(false) bool(true)
on
Code:
var_dump($sel_table);
var_dump($web_result);

EDIT:

LOOK DOWN FOR HELPING ME ON A OTHER PROBLEM

Last edited by codefreek : 06-26-2008 at 09:44 PM. Reason: Var_dumb(); added
codefreek is offline  
Reply With Quote
Old 06-26-2008, 07:20 PM   #4 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

That's what I'm trying to do as well. Which is why I was wondering if maybe that was an incomplete code segment and perhaps the problem was located elsewhere, since I can't see anywhere that $id is being defined, and if you're searching for an empty ID, or an ID that doesn't exist in the table, then you're going to get an empty result which would be why $sel_table isn't receiving any data.
-m
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
codefreek (06-26-2008)
Old 06-26-2008, 08:49 PM   #5 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

That is the code segment, i didn't code anything else yet because of the fact that the code is not working




EDIT:

LOOK DOWN FOR HELPING ME ON A OTHER PROBLEM

Last edited by codefreek : 06-26-2008 at 09:44 PM. Reason: Look down!
codefreek is offline  
Reply With Quote
Old 06-26-2008, 09:30 PM   #6 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

i fixed the problem thank you ;)


New problem look down...



EDIT:

LOOK DOWN FOR HELPING ME ON A OTHER PROBLEM

Last edited by codefreek : 06-26-2008 at 09:45 PM. Reason: LOOK DOWN!
codefreek is offline  
Reply With Quote
Old 06-26-2008, 09:32 PM   #7 (permalink)
Jim
The Addict
 
Jim's Avatar
 
Join Date: Nov 2007
Location: the Netherlands
Posts: 281
Thanks: 2
Jim is on a distinguished road
Default

Ok to make it damn easy, echo the $sql variable. I bet we can learn much more from that :)

I go with delayedinsanity, you cannot use variables that don't exist (yet). You first have to create the variables that you want to be used. Both $id and $username don't exist, so they will return NULL. (NULL = basically _nothing_)

Edit// Damn too late :(
__________________
Nunchaku! Who doesn't like martial arts? =)
Send a message via MSN to Jim Send a message via Skype™ to Jim
Jim is offline  
Reply With Quote
The Following User Says Thank You to Jim For This Useful Post:
codefreek (06-26-2008)
Old 06-26-2008, 09:42 PM   #8 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Application Error So i have a new problem - help!

PHP Code:
<?php
error_reporting
(E_ALL & ~E_NOTICE);
include(
"db_connect.php");
session_start(); // Starts the session.

if ($_SESSION[&#8216;logged’] == 1) { // User is already logged in.

        
header("Location: index.php"); // Goes to main page.

        
exit(); // Stops the rest of the script.

} else {

        if (!isset(
$_POST[&#8217;submit’])) { // The form has not been submitted.

echo
<form action='users.php' name='login' method='post'> 
<table> 
    <tr> 
        <td> 
        username 
        </td> 
    </tr> 
    <tr> 
        <td> 
        <input type='text' name='
$username'> 
        </td> 
    </tr> 

        <tr> 
        <td> 
        password
        </td> 
    </tr> 
    <tr> 
        <td> 
        <input type='text' name='
$password'> 
        </td> 
    </tr> 
    <tr> 
        <td> 
        
        </td> 
    </tr> 
    <tr> 
    </tr> 
    <tr> 
        <td> 
        <input type='submit' name='login' value='login'> 
        </td> 
    </tr> 
</table> 
</form>"
;     
    
    } else {

                
$username form($_POST[&#8216;username’]);

                
$password md5($_POST[&#8216;password’]); // Encrypts the password.

               

                
$q mysql_query("SELECT * FROM `users` WHERE username = ‘$username’ AND password = ‘$password’") or die (mysql_error()); // mySQL query

                
$r mysql_num_rows($q); // Checks to see if anything is in the db.

               

                
if ($r == 1) { // There is something in the db. The username/password match up.

                        
$_SESSION[&#8216;logged’] = 1; // Sets the session.

                        
header("Location: index.php"); // Goes to main page.

                        
exit(); // Stops the rest of the script.

                
} else { // Invalid username/password.

                        
exit("Incorrect username/password!"); // Stops the script with an error message.

                
}

        }

}

?>

no errors but the login do not work :S
codefreek is offline  
Reply With Quote
Old 06-26-2008, 09:49 PM   #9 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

if you see #8216 in the form :S it is the forum that is making that not me :S
here is code on
PasteBin.be
pastebin if some one wants to take a look at the script in a more clean space,
codefreek is offline  
Reply With Quote
Old 06-26-2008, 10:03 PM   #10 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Your form might be causing the problem. You need the fields to look something more like

PHP Code:
echo '<input type="text" name="username" value="' $username '" />';
echo 
'<input type="text" name="password" value="' $password '" />'
There is nothing in $_POST['username'] or $_POST['password'] because you're using variables to determine the name of those fields. So for all we know, the information could be showing up in $_POST['codefreek']. More likely it's going nowhere, as the name field is probably empty when the page is displayed.

Might I suggest using CSS to style your forms too?
-m
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
codefreek (06-26-2008)
Old 06-26-2008, 10:30 PM   #11 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

thank you i don't style my applications before everything is done..
codefreek is offline  
Reply With Quote
Old 06-26-2008, 10:33 PM   #12 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

so should i take off the $_POST?
codefreek is offline  
Reply With Quote
Old 06-26-2008, 10:43 PM   #13 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Wink

Quote:
Originally Posted by delayedinsanity;
Your form might be causing the problem. You need the fields to look something more like

PHP Code:
echo '<input type="text" name="username" value="' $username '" />';
echo 
'<input type="text" name="password" value="' $password '" />'
how do i put this in my form ?
please reform it to, put it in my form # to match my form..
Ty.


NVM I FIXED ;)

Last edited by codefreek : 06-26-2008 at 10:59 PM. Reason: FIXED
codefreek is offline  
Reply With Quote
Old 06-26-2008, 10:49 PM   #14 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

FORM EDIT:
PHP Code:
      
                
echo "<form action=\"users.php\" method=\"POST\">";

                echo 
"<table>";

                echo 
"<tr>";

                echo 
"<td colspan=\"2\">Login:</td>";

                echo 
"</tr>";

                echo 
"<tr>";

                echo 
'<input type=\"text\" name=\"username\" value="'.$username.'">';

                echo 
"</tr>";

                echo 
"<tr>";

                echo 
'<input type=\"text\" name=\"password\" value="'.$password.'">';

                echo 
"</tr>";

                echo 
"<tr>";

                echo 
"<td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"submit\"</td>";

                echo 
"</tr>";

                echo 
"</table>";

                echo 
"</form>"

Last edited by codefreek : 06-26-2008 at 11:06 PM. Reason: One more EDIT
codefreek is offline  
Reply With Quote
Old 06-26-2008, 10:53 PM   #15 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

Some Thing is still wrong, i know everything should work now but it do not work!
codefreek is offline  
Reply With Quote
Old 06-26-2008, 11:20 PM   #16 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

When you're using single quotes (') you don't have to escape double quotes (") and visa versa. This isn't how I would do it normally, but to fit with the style of what you're doing;

PHP Code:
if ( ! isset($username))
{
    
$username '';
}

if ( ! isset(
$password))
{
    
$password '';
}

$szForm = <<<FORM
<form action="users.php" name="login" method="post"> 
<table> 
    <tr><td>username</td>
        <td><input type="text" name="username" value="
{$username}" /></td>
    </tr> 

    <tr><td>password</td>
        <td><input type="password" name="password" value="
{$password}" /></td>
    </tr>

    <tr><td colspan="2"><input type='submit' name='login' value='login' /></td></tr> 
</table> 
</form>
FORM;

echo 
$szForm
Typos and simple mistakes can happen to anybody at anytime, so never be afraid to view the source directly from your browser, or echo any variables to the screen temporarily to check them, and so on and so forth.
-m
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
codefreek (06-26-2008)
Old 06-26-2008, 11:34 PM   #17 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

Thank you delayedinsanity for all the help :D
wont forget you ;D


EDIT:
Fatal error: Call to undefined function form() in line 45

FIXED THAT PROBLEM

Last edited by codefreek : 06-26-2008 at 11:53 PM. Reason: EDIT - FIXED
codefreek is offline  
Reply With Quote
Old 06-26-2008, 11:42 PM   #18 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

is there any reference on all the errors because i have no idea what that error stands for :S
codefreek is offline  
Reply With Quote
Old 06-26-2008, 11:53 PM   #19 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

now, i got a new problem,
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '‘ AND password = ‘' at line 1

PHP Code:

$q 
mysql_query("SELECT * FROM `users` WHERE username = ‘$username’ AND password = ‘$password’") or die (mysql_error()); // mySQL query 
i tried to change it to
PHP Code:
'".$rest."' 
but that didn't work

I FIXED THAT PROBLEM

Last edited by codefreek : 06-27-2008 at 12:14 AM. Reason: FIXED
codefreek is offline  
Reply With Quote
Old 06-27-2008, 12:18 AM   #20 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Help

now i have a new problem i login with right pass and username, it all works sends me to index if the user is logged in but when i try to logout..
it wont logout :S

THIS IS ON index:
PHP Code:
session_start(); // Starts the session.

if ($_SESSION[‘logged’] != 1) { // There was no session found!

        
header("Location: users.php"); // Goes to login page.

        
exit(); // Stops the rest of the script.

}

echo 
"This is the main page!"
LOGOUT page,
PHP Code:
<?php

      session_unset
(); // Destroys the session.

      
header("Location: users.php"); // Goes back to login.


?>
and this is the users page
PHP Code:
<?php
error_reporting
(E_ALL & ~E_NOTICE);
include(
"db_connect.php");
session_start(); // Starts the session.

if ($_SESSION[‘logged’] == 1) { // User is already logged in.

        
header("Location: index.php"); // Goes to main page.

        
exit(); // Stops the rest of the script.

} else {

if ( ! isset(
$username))
{
    
$username '';
}

if ( ! isset(
$password))
{
    
$password '';
}

$szForm = <<<FORM
<form action="users.php" name="login" method="post"> 
<table> 
    <tr><td>username</td>
        <td><input type="text" name="username" value="
{$username}" /></td>
    </tr> 

    <tr><td>password</td>
        <td><input type="password" name="password" value="
{$password}" /></td>
    </tr>

    <tr><td colspan="2"><input type='submit' name='login' value='login' /></td></tr> 
</table> 
</form>
FORM;

echo 
$szForm;  
   
    


               
$password mysql_real_escape_string($_POST['password']);
           
$username mysql_real_escape_string($_POST['username']);




               

                
$q mysql_query("SELECT * FROM users WHERE username = '$username'
                 AND password = '
$password'") or die (mysql_error()); // mySQL query

                
$r mysql_num_rows($q); // Checks to see if anything is in the db.

               

                
if ($r == 1) { // There is something in the db. The username/password match up.

                        
$_SESSION[‘logged’] = 1// Sets the session.

                        
header("Location: index.php"); // Goes to main page.

                        
exit(); // Stops the rest of the script.

                
} else { // Invalid username/password.

                        
exit("Incorrect username/password!"); // Stops the script with an error message.

                
}

        }



?>
codefreek is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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


All times are GMT. The time now is 03:55 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design