Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-08-2009, 08:19 AM   #1 (permalink)
jnich104
Monkey N00B
 
jnich104's Avatar
 
Join Date: Jun 2008
Location: Nailsea
Posts: 107
jnich104 is on a distinguished road
Send a message via MSN to jnich104
Sql and php

Hey guys, i am creating a new script for my site and i am getting a error but i cant see where it is, and my MySQL looks right

Code
PHP Code:
if($_GET['page'] == 'login')
    {
        
$CONNECT mysql_connect($DB_IP,$DB_USER,$DB_PASS);
            if(!
$CONNECT)
                {
                    die(
'MySQL Error : '.mysql_error());
                }
        
mysql_select_db($DB_NAME$CONNECT);

        
$RESULT mysql_query("SELECT * FROM ".$PREFIX."accounts WHERE username='".$_POST['username']."");
        
$RESULTB mysql_query("SELECT * FROM ".$PREFIX."accounts WHERE username='".$_POST['username']." AND password=".md5($_POST['password'])."");
        while(
$row mysql_fetch_array($RESULT))
          {
            
            
             while(
$rowb mysql_fetch_array($RESULTB))
              {
                   
session_regenerate_id();
                  
$_SESSION['HEWP_MEMBER_ID'] = $rowb['user_id'];
                  
$_SESSION['HEWP_FIRSTNAME'] = $rowb['user_firstname'];
                  
header('location: index.php');
              }
                  else
              {
                  
session_regenerate_id();
                
$_SESSION['HEWP_ERROR'] = 'Password was wrong';
                
header('location: login.fun.php');
              }
          } 
              else 
         {
              
session_regenerate_id();
              
$_SESSION['HEWP_ERROR'] = 'Username was wrong';
              
header('location: login.fun.php');
          }
        
mysql_close($CONNECT);
        
    } 

Error
PHP Code:
Parse errorparse error in C:wampwwwfunctions.php on line 30 

Line 30 :
PHP Code:
}
/* ->  */ else 

Any ideas
__________________
Jamie Nicholls - Feel Free To Ask Questions
jnich104 is offline   Reply With Quote
Old 11-08-2009, 08:48 AM   #2 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 832
DJMaze is on a distinguished road
PHP Code:
while { } else { } 
Is that valid code?
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 11-08-2009, 09:07 AM   #3 (permalink)
jnich104
Monkey N00B
 
jnich104's Avatar
 
Join Date: Jun 2008
Location: Nailsea
Posts: 107
jnich104 is on a distinguished road
Send a message via MSN to jnich104
KK so i cant have else after a while. Thanks
__________________
Jamie Nicholls - Feel Free To Ask Questions
jnich104 is offline   Reply With Quote
Old 11-08-2009, 09:17 AM   #4 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 832
DJMaze is on a distinguished road
duh. They are:
if {} else {}
do {} while ()

Read: PHP: Control Structures - Manual
NOTE: skip "goto" it sucks hard!
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 11-13-2009, 03:00 PM   #5 (permalink)
billybolsa
Recruit
 
billybolsa's Avatar
 
Join Date: Oct 2009
Posts: 9
billybolsa is on a distinguished road
you should also call session_start() at the beginning (with nothing above it) of your document if your going to be working with session variables, otherwise they will not work.
billybolsa is offline   Reply With Quote
Old 11-13-2009, 05:24 PM   #6 (permalink)
farmdve
Recruit
 
Join Date: Nov 2009
Posts: 3
farmdve is on a distinguished road
Seeing this code i see quite a few security holes with those posts. Anyone can execute a simple mysql injection through those.
The password is ok tho but use mysql_real_escape_string on all the posts that you compare in the db
farmdve is offline   Reply With Quote
Old 11-24-2009, 09:47 AM   #7 (permalink)
jnich104
Monkey N00B
 
jnich104's Avatar
 
Join Date: Jun 2008
Location: Nailsea
Posts: 107
jnich104 is on a distinguished road
Send a message via MSN to jnich104
How do i use this Function mysql_real_escape_string()

?? i looked into it and it confusing me
__________________
Jamie Nicholls - Feel Free To Ask Questions
jnich104 is offline   Reply With Quote
Old 11-24-2009, 09:53 AM   #8 (permalink)
billybolsa
Recruit
 
billybolsa's Avatar
 
Join Date: Oct 2009
Posts: 9
billybolsa is on a distinguished road
$string =mysql_real_escape_string($stringToStrip);

but you can only use this if you establish a mysql connection first. Otherwise it will produce errors. I think its probably a better idea to create your own validating functions because then you can use them any where you want.
billybolsa is offline   Reply With Quote
Old 11-29-2009, 07:05 AM   #9 (permalink)
jnich104
Monkey N00B
 
jnich104's Avatar
 
Join Date: Jun 2008
Location: Nailsea
Posts: 107
jnich104 is on a distinguished road
Send a message via MSN to jnich104
k so if i got
PHP Code:
function strip($code)
  {
  } 
What code would i put which will strip code for input text???
__________________
Jamie Nicholls - Feel Free To Ask Questions
jnich104 is offline   Reply With Quote
Old 11-29-2009, 11:14 PM   #10 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,700
sde is on a distinguished road
PHP Code:
$username mysql_real_escape_string($_POST['username']); 
then pass $username instead of $_POST['username'] in the query.
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 10:18 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting