TalkPHP
 
 
Account Login
Latest Articles
» How to keep your forms from double posting data
» cURL Basics
» Securing your PHP applications Part 1
» The way the function rolls
» Database Abstraction with Zend_Db - Part 2
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Display Modes
Old 07-01-2008, 12:11 AM   #21 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
delayedinsanity is on a distinguished road
Default

Quote:
Originally Posted by codefreek View Post
if you are trying to give out pointers with a code please don't
give a snippet of code with a new error ;)

PS thank you!
Mine or his?

EDIT: Haha, happens to me all the time, I was looking over my code and I forgot a semicolon. It's edited and fixed.
-m
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
codefreek (07-01-2008)
Old 07-01-2008, 12:20 AM   #22 (permalink)
The Addict
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 283
Thanks: 166
codefreek is on a distinguished road
Default

For some reason the damn firefox 3 is blocking the access to the script it said cookie error! w*t*f*

you guys got any ideas?
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.
codefreek is offline  
Reply With Quote
Old 07-01-2008, 12:21 AM   #23 (permalink)
The Frequenter
Advanced Programmer Top Contributor Good Samaritan 
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 424
Thanks: 22
sketchMedia is on a distinguished road
Default

Add the site as an exception in FF3?
Tools => Options => Privicy => Exceptions
__________________
sketchMedia is offline  
Reply With Quote
The Following User Says Thank You to sketchMedia For This Useful Post:
codefreek (07-01-2008)
Old 07-01-2008, 12:26 AM   #24 (permalink)
The Addict
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 283
Thanks: 166
codefreek is on a distinguished road
Default

Thank you for the suggestion
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.

Last edited by codefreek : 07-01-2008 at 01:49 AM.
codefreek is offline  
Reply With Quote
Old 07-01-2008, 01:26 AM   #25 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
delayedinsanity is on a distinguished road
Default

He's just trying to help.

It looks like you're missing code in the users.php file, something along the lines of

PHP Code:
if ($_POST
Should be in there somewhere, because otherwise it's trying to log people in even if they haven't submitted the form, and in addition since the form is being displayed regardless of the submission you can't then set any headers afterwards (the location, etc).
-m
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
codefreek (07-01-2008)
Old 07-01-2008, 01:44 AM   #26 (permalink)
The Visitor
 
Join Date: Jun 2008
Posts: 4
Thanks: 3
webid is on a distinguished road
Default

$_POST ? first code i read he was going for $_GET...
webid is offline  
Reply With Quote
Old 07-01-2008, 01:53 AM   #27 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
delayedinsanity is on a distinguished road
Default

Yeah, on his index.php, but his users.php uses a POST form.
delayedinsanity is offline  
Reply With Quote
Old 07-01-2008, 09:17 AM   #28 (permalink)
The Addict
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 283
Thanks: 166
codefreek is on a distinguished road
Default

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


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 (
$_POST)
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[&#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.

                
}

        }



?>

i put in the POST thing!
but still wont work ! :(
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.
codefreek is offline  
Reply With Quote
Old 07-01-2008, 10:44 AM   #29 (permalink)
The Gregarious
Upcoming Programmer Inquisitive 
 
Join Date: Sep 2007
Posts: 540
Thanks: 64
Tanax is on a distinguished road
Default

erhm..
HTML Code:
<input type="text" name="username" value="{$username}" />
{$username} = ????
Are you using a template engine?

Also I noticed: There's no need to use mysql_real_escape_string on $_GET['cat'].
__________________
Tanax is offline  
Reply With Quote
Old 07-01-2008, 10:53 AM   #30 (permalink)
The Addict
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 283
Thanks: 166
codefreek is on a distinguished road
Default

tanax } can be used as well as \ same function
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.
codefreek is offline  
Reply With Quote
Old 07-01-2008, 04:01 PM   #31 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
delayedinsanity is on a distinguished road
Default

Tanax: In his copy of the code there is a reason to use it, because he doesn't run any checks to make sure that it's an integer, so they could very well try and insert malicious data. In mine it's casted to an integer so no it's not needed, and I omitted it.

Also, braces can be used in a couple different ways in PHP without it having to be part of a template engine. Some people will use them to further differentiate a variable within a block structure, as opposed to string concatenation, like so;

PHP Code:
$canidae 'fox';
$canis 'dog';
$szString "The quick brown {$canidae} jumps over the lazy {$canis}"
You could even use them to group a block of code if you want some more visual organization;

PHP Code:
header("Content-type: text/plain");

echo 
'Hello, world!';
echo 
"\n\n";

{
    
// This block is executed like normal code, but it's between braces so I can
    // spot it quicker when debugging.
    
$hello 'Hello';
    
$comma ', ';
    
$world 'world!';
    
$var 'world';

    echo 
$hello."{$comma}${$var}";

Codefreek: You used the if conditional without blocking out any code for it with curly braces. So it's not affecting the entirety of the script the way you want it to.

You may want to take a look at PHP: if - Manual to find out what's actually happening when you omit the curly braces after an if statement. I would also suggest considering where exactly you want the if statement to be. Do you want the form displayed whether or not a post has been made? Do you want it to attempt to login the user based on whether or not there's been a post?
-m

Last edited by delayedinsanity : 07-02-2008 at 02:52 PM.
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
codefreek (07-01-2008)
Old 07-01-2008, 04:07 PM   #32 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
delayedinsanity is on a distinguished road
Default

Quote:
ps, who said i wont fix it up later on?..the code..
think of how much time you save if you just code what comes to mind, and not worry about the damn css..


I definitely code what comes to mind as it comes to mind, which is why I spend almost as much time cleaning up behind myself as I do coding my initial thought processes. Earlier there I was referring to the structure and overall readability of your PHP, not your CSS or HTML. The extra CSS I threw in there was just to appease my own stubborn ways a little bit.

When you code, if you want to code messy to get the job done, by all means, code code code. It's the funnest part. However, the first thing I find that helps me a great deal when I run into a bug or code that just doesn't work, is going through and giving it a good scrub down. Remove any excess tags, any unnecessary opening and closing php tags, check my indents just so I can read through it line by line without confusing myself as to the logical progression of what I was attempting to do, so on and so forth.

In the end it was just meant as a helpful suggestion, but definitely not an enforced guideline. You do what works for you, and that's usually the best thing.
-m
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
codefreek (07-01-2008)
Old 07-01-2008, 04:15 PM   #33 (permalink)
The Addict
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 283
Thanks: 166
codefreek is on a distinguished road
Default

well, i humbly Thank you for your help and some good Tips
but as i don't seem to get the script to work and no one to help me i might just
stop with that script and move on..
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.
codefreek is offline  
Reply With Quote
Old 07-01-2008, 04:28 PM   #34 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
delayedinsanity is on a distinguished road
Default

We are trying to help you, but I can't rewrite it for you every time either, you won't actually be learning anything. I would suggest against moving on, because fixing this problem is probably going to greatly improve your ability down the road, both in coding and debugging.

Without reposting the code, what is the current error you are running into, with which page (users or index)?
-m
delayedinsanity is offline  
Reply With Quote
Old 07-01-2008, 04:36 PM   #35 (permalink)
The Addict
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 283
Thanks: 166
codefreek is on a distinguished road
Default

It's not an php error causing this problem it's firefox 3 making some damn cookie error it is not even letting me go in to the script it exits and outputs cookie error the script work! but the firefox 3 is doing some error damn bug like vista!
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.
codefreek is offline  
Reply With Quote
Old 07-01-2008, 04:42 PM   #36 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
delayedinsanity is on a distinguished road
Default

Up to you, but I would suggest downgrading to Firefox2 until 3 comes out of Beta. I played with it for a bit myself and other than the general clunkiness of things (due to being new implementations) it seemed to cause a lot of problems in general with day to day browsing.
-m
delayedinsanity is offline  
Reply With Quote
Old 07-01-2008, 04:44 PM   #37 (permalink)
The Addict
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 283
Thanks: 166
codefreek is on a distinguished road
Default

dude not to be saying this in a bad way but it has been out for like 2 weeks
it is not in beta anymore.

but thank you!
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.
codefreek is offline  
Reply With Quote
Old 07-01-2008, 04:54 PM   #38 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
delayedinsanity is on a distinguished road
Default

It's not a bad way, I really don't keep up with things like I used to.

Is anybody else reading this thread using FF3? I like being up to date with my technology, but Windows taught me a long time ago, it's usually best to wait for a while after it's been fully out for any major fixes, then upgrade.
-m
delayedinsanity is offline  
Reply With Quote
Old 07-01-2008, 07:10 PM   #39 (permalink)
The Addict
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 283
Thanks: 166
codefreek is on a distinguished road
Default

well i will continue working on my script if it's something i have learned, i am not a person who gives up when something is to hard i will work on the code and maybe find a way to get it working thank you.
Will post any future errors i might find and can not work out
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.
codefreek is offline  
Reply With Quote
Old 07-01-2008, 07:30 PM   #40 (permalink)
The Gregarious
Upcoming Programmer Inquisitive 
 
Join Date: Sep 2007
Posts: 540
Thanks: 64
Tanax is on a distinguished road
Default

Quote:
Originally Posted by delayedinsanity View Post
Tanax: In his copy of the code there is a reason to use it, because he doesn't run any checks to make sure that it's an integer, so they could very well try and insert malicious data. In mine it's casted to an integer so no it's not needed, and I omitted it.
But it's totally useless to do a mysql_real_escape_string when it's an integer. It's better just to check if it's an integer, takes less loading time and is far more cleaner. Not to mention; easier.

And thanks for the info about braces, didn't know that!
__________________
Tanax is offline  
Reply With Quote
The Following User Says Thank You to Tanax For This Useful Post:
codefreek (07-01-2008)
Reply