Omer Asher
Omer Asher

Reputation: 63

SQL Error: You have an error in your SQL syntax; check the manual that corresponds to your

i have problem with my site. i want to create a page in php. in this page i want user invite user. but i have a error. i dont know what to do. thx all .

the error: SQL Error: 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 '' at line 1..

and in the header have a connect database. its not my problem.

my code:

<?php
include('header.php');
$n1 = rand(1, 9);
$n2 = rand(1, 9);

if(isset($_POST['send'])) {
    $nr1 = base64_decode($_POST['nr1']);
    $nr2 = base64_decode($_POST['nr2']);
    $emailinvite = $db->EscapeString($_POST['email']);
    $rec = $db->FetchArray($db->Query("SELECT id,login FROM `users` WHERE `login`='".$data['login']."'"));

    if($nr1 + $nr2 != $_POST['captcha']){
        $mesaj = '<div class="error">pliz try again.</div>';
    }elseif($_POST['email'] == ""){
        $mesaj = '<div class="error">empty email</div>';
    }elseif ($db->GetNumRows($db->Query("SELECT id FROM `users` WHERE `email`='".$emailinvite."'")) > 0) {
        $mesaj = '<div class="error">your friend register!</div>';
    }else{
        $newhash = rand(1000000,9999999);
        $db->Query("INSERT INTO `inviteuser` (user,emailinvite,hash) values('".$data['login']."','".$emailinvite."','".$newhash."'");

            $error = 0;

        $subject ="invite to site";
        $message="hello

the user {$rec['login']} want to invite you to :
http://www.like2hits.net

click here: 
{$site['site_url']}/register.php?hash={$newhash}

thx!";
        $header="{$site['site_email']} <{$site['site_email']}>";
        $send_contact=mail($emailinvite,$subject,$message,$header);
        $mesaj = "<div class=\"success\">thx you!</div>";
    }
}?>
<div id="login">
            <div class="top">
                  <h1>invite friend</h1>
            </div>
            <div class="content"><div class="msg"><?echo $mesaj;?></div>
            <form id="form" method="post">
                <input type="hidden" name="nr1" value="<? echo base64_encode($n1); ?>" />
                <input type="hidden" name="nr2" value="<? echo base64_encode($n2); ?>" />
                <fieldset>

                        <label>email of your friend</label>
                    <p><span class="fontawesome-user"></span>
                        <input name="email" type="email" value="" required="required" />
                    </p>

                        <label><?=($n1." + ".$n2." = ?")?></label>
                    <p><span class="fontawesome-user"></span>
                        <input name="captcha" type="text" value="" required="required" />
                    </p>
                    <p style="text-align: center; padding-top: 15px;">
                    <input type="submit" name="send" value="invite user" />
                    </p>
                </fieldset>
            </form>
        </div>
    </div>
<?
include('footer.php');?>

Upvotes: 0

Views: 7258

Answers (3)

Loko
Loko

Reputation: 6679

At

$db->Query("INSERT INTO `inviteuser` (user,emailinvite,hash) values('".$data['login']."','".$emailinvite."','".$newhash."'");

You are missing a )

Upvotes: 2

Starx
Starx

Reputation: 78971

A common typo error:

$db->Query("INSERT INTO `inviteuser` (user,emailinvite,hash) 
values('".$data['login']."','".$emailinvite."','".$newhash."'");
                                                          // ^ Closing Bracket 
                                                               Missing

Should be:

$db->Query("INSERT INTO `inviteuser` (user,emailinvite,hash) 
values('".$data['login']."','".$emailinvite."','".$newhash."')");
                                                          // ^ Closing Bracket 

Upvotes: 3

PatrickH
PatrickH

Reputation: 39

I think your quotes are giving the error try this:

$rec = $db->FetchArray($db->Query("SELECT id,login FROM 'users' WHERE 'login'='".$data['login']."'"));

And:

$db->GetNumRows($db->Query("SELECT id FROM 'users' WHERE 'email'='".$emailinvite."'"))

And:

$db->Query("INSERT INTO 'inviteuser' (user,emailinvite,hash) values('".$data['login']."','".$emailinvite."','".$newhash."'");

It depends on what mysql version you have, but at my version this: `` quotes give an error by me. So i use ''

Upvotes: -1

Related Questions