Page 1 of 2

You have an error in your SQL syntax; problem!!! =(

Posted: Thu Nov 05, 2009 8:50 am
by Goofan
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

i get this message when im trying to get a (saved_id)
this is my code

plz help me

Code: Select all

 
<?php
include "../login/database.php"; //Fil för databasinställning
$id =(isset($_GET['saved_id'])) ? $_GET['saved_id'] : false;    
$sql="SELECT * FROM konto WHERE saved_id=$id";
    
$result = mysql_query($sql) or die(mysql_error());//Välj all info i tabell. //hämtar all info från tabell
 

Re: You have an error in your SQL syntax; problem!!! =(

Posted: Thu Nov 05, 2009 9:14 am
by AbraCadaver
I can only assume that $_GET['saved_id'] is not set so $id = false.

Assuming saved_id is an integer, try:

Code: Select all

$id =(isset($_GET['saved_id'])) ? (int)$_GET['saved_id'] : false;
if($id !== false) {
    $sql="SELECT * FROM konto WHERE saved_id=$id";
} else {
    echo "NO saved_id!";
}

Re: You have an error in your SQL syntax; problem!!! =(

Posted: Thu Nov 05, 2009 10:47 am
by Goofan
well i figured out where my problem where and i got a sending page sending to a diffrent page and on that i dont know what to type to send the code further to next page

code: sending page

Code: Select all

 
<?php
include "database.php";//Fil för databasinställning.
 
if (@$_POST["submit"])//Kollar om knappen SUBMIT använts.
{
$sql="SELECT * FROM konto";//Ta allt från databas tabellen: "konto".
 
    $result = mysql_query($sql) or die(mysql_error(FAIL));//Välj all info i tabell.
        while($row = mysql_fetch_array( $result ))//Hämtar info från tabell.
            {
                if ((@$_POST[user]== @$row[user]) && (@$_POST[password]== @$row[pass]) && (@$row[***] =="1"))//Kollar så att användare finns i databasen och kollar om användaren är ***.
                    {
                        header('Refresh: 0; url=../***/***_***(***).php?saved_id='.$row[saved_id]);//Skickas till angiven sida.
                    }
                if ((@$_POST[user]== @$row[user]) && (@$_POST[password]== @$row[pass]) && (@$row[***] =="0"))//Kollar så att användare finns i databasen och kollar om användaren är ***.
                    {
                        header('Refresh: 0; url=../menu_main(menu).php?saved_id='.$row[saved_id]);//Skickas till angiven sida.
                    }       
            }
        exit;//Lämnar loop.
            header("Location: login.php");//Skickas till angiven sida efter en viss tid.
            
}
?>
 

then i got the recieving page nr1
>here i dont know what to code to make it send the saved_id further to the allready shown recieving page nr2
can u help me or do i need to post it under java...?

code:recieving page nr1:

Code: Select all

 
<html>
<head>
//in the script im sending the login person further opening these windows "as i get it this is not possible in normal php script to send 2 location having one recieving page... 
<script type="text/javascript">
parent.main.location.href = "***/***_***.php"
parent.menu.location.href = "***_***.php"
</script>
</head>
</html>
<body>
***overview
</body>
</html>
 

im very greatful for any help i get =)

Re: You have an error in your SQL syntax; problem!!! =(

Posted: Thu Nov 05, 2009 10:54 am
by AbraCadaver
Well the receiving page is receiving the vars as get parameters, so you need to use the $_GET superglobal. If the receiving page has a .php extension, then something like this:

Code: Select all

parent.main.location.href = "(***/***_***.php?saved_id=<?php echo $_GET['saved_id'] ?>)"
parent.menu.location.href = "(***_***.php?saved_id=<?php echo $_GET['saved_id'] ?>)"
-Shawn

Re: You have an error in your SQL syntax; problem!!! =(

Posted: Thu Nov 05, 2009 11:03 am
by Goofan
well thanks it solved alot of problems thanks

but if ure here =) or someone else?
can u help me fix this problem as im not getting to get as i want it

Code: Select all

 
while($row = mysql_fetch_array( $result )) //hämtar info från tabell.
{
    $user=$row['user'];
}
//further down after the first php script i got this
// its supposed to write the user name but all i get is [b]a[/b] and the full username is [b]all[/b]
and i dont get why its only writing out one letter instead of all 3 letters... can u help?
user <?php echo $user['user'] ?>
?>
 

thanks again for all the help


-Thomas

Re: You have an error in your SQL syntax; problem!!! =(

Posted: Thu Nov 05, 2009 12:06 pm
by AbraCadaver
Goofan wrote:well thanks it solved alot of problems thanks

but if ure here =) or someone else?
can u help me fix this problem as im not getting to get as i want it

Code: Select all

 
while($row = mysql_fetch_array( $result )) //hämtar info från tabell.
{
    $user=$row['user'];
}
//further down after the first php script i got this
// its supposed to write the user name but all i get is [b]a[/b] and the full username is [b]all[/b]
and i dont get why its only writing out one letter instead of all 3 letters... can u help?
user <?php echo $user['user'] ?>
?>
 
user <?php echo $user['user'] ?>

thanks again for all the help


-Thomas
You've already defined $user=$row['user'] so why try and use $user['user']? Just use this:

<?php echo $user ?>

Re: You have an error in your SQL syntax; problem!!! =(

Posted: Thu Nov 05, 2009 12:28 pm
by Goofan
=) that problem got solved =) i had the missing files on a diffrent page.... middle reciever page...:
however i got this problem now:



can someone help me fix this problem?

Here im sending a specific saved_id to a recieving page nr 1 wich is supposed to open 2 windows "target" and so it does then on my recieving page nr 2 im getting the saved_id and can by that way get the row where saved_id is at but when im writing this out to show i only get one letter when its supposed to get 3 letters from my DB(database) and yes ive double checked the DB






my sending page
:code:

Code: Select all

 
<?php
include "database.php";//Fil för databasinställning.
 
if (@$_POST["submit"])//Kollar om knappen SUBMIT använts.
{
$sql="SELECT * FROM konto";//Ta allt från databas tabellen: "konto".
 
    $result = mysql_query($sql) or die(mysql_error(FAIL));//Välj all info i tabell.
        while($row = mysql_fetch_array( $result ))//Hämtar info från tabell.
            {
                if ((@$_POST[user]== @$row[user]) && (@$_POST[password]== @$row[pass]) && (@$row[admin] =="1"))//Kollar så att användare finns i databasen och kollar om användaren är admin.
                    {
                        header('Refresh: 0; url=../admin/admin_menu(main).php?saved_id='.$row[saved_id]);//Skickas till angiven sida.
                    }
                if ((@$_POST[user]== @$row[user]) && (@$_POST[password]== @$row[pass]) && (@$row[admin] =="0"))//Kollar så att användare finns i databasen och kollar om användaren är admin.
                    {
                        header('Refresh: 0; url=../menu_main(menu).php?saved_id='.$row[saved_id]);//Skickas till angiven sida.
                    }       
            }
        exit;//Lämnar loop.
            header("Location: login.php");//Skickas till angiven sida efter en viss tid.
            
}
?>
 



recieving page nr 1
:code:

Code: Select all

 
<html>
<head>
$id =(isset($_GET['saved_id']))
<script type="text/javascript">
parent.main.location.href = "sidor/admin_overview.php?saved_id=<?php echo $_GET['saved_id'] ?>"
parent.menu.location.href = "admin_menu.php?saved_id=<?php echo $_GET['saved_id'] ?>"
</script>
</head>
</html>
<body>
admin overview
</body>
</html>
 






//recieving page nr 2
:code:

Code: Select all

 
<?php
include "../login/database.php"; //Fil för databasinställning
$id =(isset($_GET['saved_id'])) ? (int)$_GET['saved_id'] : false;   
 if($id !== false) {
     $sql="SELECT * FROM konto WHERE saved_id=$id";
 } else {
     echo "NO saved_id!";
 }
$result = mysql_query($sql) or die(mysql_error());//Välj all info i tabell. //hämtar all info från tabell
 
                 
while($row = mysql_fetch_array( $result )) //hämtar info från tabell.
{
    $fornamn=$row['fornamn'];
}
?>
//further down after the first php script i got this
// its supposed to write the user name but all i get is [b]a[/b] and the full username is [b]all[/b]
and i dont get why its only writing out one letter instead of all 3 letters... can u help?
user <?php echo $user['user'] ?>
?>
 

thanks again for all the help


-Thomas



And once more thanks for all the help uve given me

Re: You have an error in your SQL syntax; problem!!! =(

Posted: Thu Nov 05, 2009 1:08 pm
by Goofan
tell me if u want any of the code commented =) ill make it with smile on my face ;) promiss...

Re: You have an error in your SQL syntax; problem!!! =(

Posted: Thu Nov 05, 2009 1:19 pm
by AbraCadaver
Goofan wrote:tell me if u want any of the code commented =) ill make it with smile on my face ;) promiss...
Post all of nr2 or put it in pastebin.com

-Shawn

Re: You have an error in your SQL syntax; problem!!! =(

Posted: Thu Nov 05, 2009 1:21 pm
by Goofan
that is all the php script that ive got in that page... the rest is html scripting... still want it?

Re: You have an error in your SQL syntax; problem!!! =(

Posted: Thu Nov 05, 2009 1:36 pm
by Goofan
Shawn do u think its possible to solve?
Do u see where the error is?
2 heads is better then one =)
Get me into ure loop and ill see if i can code some aswell or error search...
right now im more or less stuck becouse of this problem... :banghead:
but im still smiling ;)

Re: You have an error in your SQL syntax; problem!!! =(

Posted: Thu Nov 05, 2009 1:37 pm
by AbraCadaver
Well, assuming that the db field name for the user is user, then I've given you the answer, but here are two ways again:

Code: Select all

while($row = mysql_fetch_array( $result )) //hämtar info från tabell.
{
    $fornamn=$row['fornamn'];
    $user=$row['user'];
}
?>
//further down after the first php script i got this
user <?php echo $user ?>
--or--

Code: Select all

while($row = mysql_fetch_array( $result )) //hämtar info från tabell.
{
    $fornamn=$row['fornamn'];
}
?>
//further down after the first php script i got this
user <?php echo $row['user'] ?>
Or is 'fornamn' the user field? In that case just echo $fornamn; Where the hell is this $user['user'] stuff coming from?

-Shawn

Re: You have an error in your SQL syntax; problem!!! =(

Posted: Thu Nov 05, 2009 1:39 pm
by Goofan
well its where it types the info out so that i can see it...

Re: You have an error in your SQL syntax; problem!!! =(

Posted: Thu Nov 05, 2009 1:40 pm
by Goofan
ill give u a more "newer code" alot more coments

Re: You have an error in your SQL syntax; problem!!! =(

Posted: Thu Nov 05, 2009 1:42 pm
by AbraCadaver
OK so I translated fornamn from Swedish and it seems to be firstname, so if that is indeed the name of the field in the DB, then do the following. If not, then you need to figure out what the fieldname is:

Code: Select all

while($row = mysql_fetch_array( $result )) //hämtar info från tabell.
{
    $fornamn=$row['fornamn'];
}
?>
//further down after the first php script i got this
user <?php echo $fornamn; ?>