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
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Display Modes
Old 06-26-2008, 06:31 PM   #1 (permalink)
The Frequenter
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 405
Thanks: 219
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
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.

Last edited by codefreek : 06-26-2008 at 10:56 PM. Reason: Look down for new problem!
codefreek is online now  
Reply With Quote
Old 06-26-2008, 07:17 PM   #2 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
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, 08:06 PM   #3 (permalink)
The Frequenter
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 405
Thanks: 219
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
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.

Last edited by codefreek : 06-26-2008 at 10:44 PM. Reason: Var_dumb(); added
codefreek is online now  
Reply With Quote
Old 06-26-2008, 08:20 PM   #4 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
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, 09:49 PM   #5 (permalink)
The Frequenter
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 405
Thanks: 219
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
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.

Last edited by codefreek : 06-26-2008 at 10:44 PM. Reason: Look down!
codefreek is online now  
Reply With Quote
Old 06-26-2008, 10:30 PM   #6 (permalink)
The Frequenter
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 405
Thanks: 219
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
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.

Last edited by codefreek : 06-26-2008 at 10:45 PM. Reason: LOOK DOWN!
codefreek is online now  
Reply With Quote
Old 06-26-2008, 10:32 PM   #7 (permalink)
Jim
The Addict
 
Jim's Avatar
 
Join Date: Nov 2007
Location: the Netherlands
Posts: 224
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 :(
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, 10:42 PM   #8 (permalink)
The Frequenter
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 405
Thanks: 219
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
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.
codefreek is online now  
Reply With Quote
Old 06-26-2008, 10:49 PM   #9 (permalink)
The Frequenter
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 405
Thanks: 219
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,
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.
codefreek is online now  
Reply With Quote
Old 06-26-2008, 11:03 PM   #10 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
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, 11:30 PM   #11 (permalink)
The Frequenter
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 405
Thanks: 219
codefreek is on a distinguished road
Default

thank you i don't style my applications before everything is done..
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.
codefreek is online now  
Reply With Quote
Old 06-26-2008, 11:33 PM   #12 (permalink)
The Frequenter
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 405
Thanks: 219
codefreek is on a distinguished road
Default

so should i take off the $_POST?
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.
codefreek is online now  
Reply With Quote
Old 06-26-2008, 11:43 PM   #13 (permalink)
The Frequenter
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 405
Thanks: 219
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 ;)
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.

Last edited by codefreek : 06-26-2008 at 11:59 PM. Reason: FIXED
codefreek is online now  
Reply With Quote
Old 06-26-2008, 11:49 PM   #14 (permalink)
The Frequenter
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 405
Thanks: 219
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>"
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.

Last edited by codefreek : 06-27-2008 at 12:06 AM. Reason: One more EDIT
codefreek is online now  
Reply With Quote
Old 06-26-2008, 11:53 PM   #15 (permalink)
The Frequenter
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 405
Thanks: 219
codefreek is on a distinguished road
Default

Some Thing is still wrong, i know everything should work now but it do not work!
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.
codefreek is online now  
Reply With Quote
Old 06-27-2008, 12:20 AM   #16 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
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-27-2008)
Old 06-27-2008, 12:34 AM   #17 (permalink)
The Frequenter
Inquisitive 
 
codefreek's Avatar