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 09-28-2008, 08:18 AM   #1 (permalink)
The Addict
 
zxt3st's Avatar
 
Join Date: Apr 2008
Posts: 200
Thanks: 18
zxt3st is on a distinguished road
Default Error in Mysql

Here is the error

Code:
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 '@yahoo.com, )' at line 2
Here is my code.

PHP Code:
<?php

include('includes/dbsettings.php');

$duplicates "SELECT username FROM users WHERE username='".trim($_POST['username'])."'";
$result mysql_query($duplicates$link)or die("Could not execute query");
if (
mysql_num_rows($result)>0)
{
    print (
"<script>\n alert('Username already exists!')\n history.back(); </script>");
    exit();
}
if ((
$_POST['username'] == "")||($_POST['password'] == "" && $_POST['password2'] == "")||($_POST['email'] == "")||($_POST['name'] == ""))
{
    print (
"<script>\n alert('All fields are required!')\n history.back(); </script>");
    exit();
}
if (
$_POST['password'] != $_POST['password2'])
{
    print (
"<script>\n alert('Password does not match!!')\n history.back(); </script>");
    exit();
}
if(!
eregi("^[a-zA-Z0-9]+[a-zA-Z0-9_.-]*@[a-zA-Z0-9]+[a-zA-Z0-9_.-])*\.[a-z]{2,4}$"$_POST['email']))
{
    print (
"<script>\n alert('Email is invalid!!!')\n history.back(); </script>");
    exit();
}
$md5pass md5($_POST['password']);
$usrAdd "INSERT INTO users(username, password, email, fullName)
            VALUES("
.$_POST['username'].", ".$md5pass.", ".$_POST['email'].", ".$_POST['fullName'].")";
if(
mysql_query($usrAdd$link))
{
    echo 
"User SUccessfully Added!";
}else{
    echo 
mysql_error();
}

?>
above is my code, its still plain and not the purpose is to just solely register an account.

I already do some research in google but i stil can't find my answers. THanks.
zxt3st is offline  
Reply With Quote
Old 09-28-2008, 08:40 AM   #2 (permalink)
The Wanderer
Good Samaritan 
 
martins256's Avatar
 
Join Date: Mar 2008
Posts: 18
Thanks: 0
martins256 is on a distinguished road
Default

What do you get when you echo $usrAdd; ?
I think that you haven't added ' ' in the SQL.

try this:

PHP Code:
$md5pass quote_smart(md5($_POST['password']));
$_POST['username'] = quote_smart($_POST['username']);
$_POST['email'] = quote_smart($_POST['email']);
$_POST['fullName'] = quote_smart($_POST['fullName']);


$usrAdd "INSERT INTO users(username, password, email, fullName)
            VALUES("
.$_POST['username'].", ".$md5pass.", ".$_POST['email'].", ".$_POST['fullName'].")"

function 
quote_smart($value)
{
    if( 
is_array($value) ) {
        return 
array_map("quote_smart"$value);
    } else {
        if( 
get_magic_quotes_gpc() ) {
            
$value stripslashes($value);
        }
        if( 
$value == '' ) {
            
$value 'NULL';
        } if( !
is_numeric($value) || $value[0] == '0' ) {
            
$value "'".mysql_real_escape_string($value)."'";
        }
        return 
$value;
    }




check out these:
to avoid sql injections

to avoid XSS
martins256 is offline  
Reply With Quote
The Following User Says Thank You to martins256 For This Useful Post:
zxt3st (09-28-2008)
Old 09-28-2008, 08:43 AM   #3 (permalink)
The Addict
 
zxt3st's Avatar
 
Join Date: Apr 2008
Posts: 200
Thanks: 18
zxt3st is on a distinguished road
Default

im just making a simple code yet for my simple tutorial about it :) and will add another code for the sql injection and xss :)

btw, thnx i will try the code.

And i am making a registration system for user.

btw this is what i get when i echo the $usrAdd

Quote:
INSERT INTO users(username, password, email, fullName) VALUES(aldin, 9cdfb439c7876e703e307864c9167a15, aldin@yahoo.com, aldin moreno)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 '@yahoo.com, aldin moreno)' at line 2
And im making a simple registration system, but still the same error.
zxt3st is offline  
Reply With Quote
Old 09-28-2008, 08:53 AM   #4 (permalink)
The Addict
 
zxt3st's Avatar
 
Join Date: Apr 2008
Posts: 200
Thanks: 18
zxt3st is on a distinguished road
Default

btw, i have just added your code, and it works :)

Thanks has been added :)

But i am still willing to hear from other guyz on why am i getting those errors using that simple code i made ;)

thnx,
t3st
zxt3st is offline  
Reply With Quote
Old 09-28-2008, 09:24 AM   #5 (permalink)
The Wanderer
Good Samaritan 
 
martins256's Avatar
 
Join Date: Mar 2008
Posts: 18
Thanks: 0
martins256 is on a distinguished road
Default

The SQL should work if it looked like this:
INSERT INTO users(username, password, email, fullName) VALUES('aldin', '9cdfb439c7876e703e307864c9167a15', 'aldin@yahoo.com', 'aldin moreno')

read more here
martins256 is offline  
Reply With Quote
The Following User Says Thank You to martins256 For This Useful Post:
zxt3st (11-17-2008)
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 08:17 AM.

 
     

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