Page 1 of 1

getting this error submitting a form

Posted: Sun Jan 11, 2009 3:48 pm
by chris_s_22
im getting this error
Warning: Invalid argument supplied for foreach() in /mounted-storage/home74b/sub009/sc42562-IQUU/www/truthdare/Game/functions.php on line 4
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

Code: Select all

 
<?php
function create_game($playername, $sex) {
        if($_POST) { 
                foreach($_POST['player'] as $post_key) { 
                $query_string .= " ('".$post_key['sex']."', '".$post_key['playername']."'),";
                } 
                $query_string = substr_replace($query_string,"",-1);
        
                // store the information in the database
                $query = "INSERT INTO `game` (`playername`, `sex`) values $query_string";
                $result = mysql_query($query) or die(mysql_error());
 
                // if suceesfully inserted data into database, send confirmation link to email 
                if($result) {
                        header('Location: http://www.pinkangel4u.com/truthdare/Ga ... board.php');
                }
        }}
?> 
please help
christine xxx

Re: getting this error submitting a form

Posted: Sun Jan 11, 2009 5:16 pm
by it2051229
look at this code

Code: Select all

 
$query_string .= " ('".$post_key['sex']."', '".$post_key['playername']."'),";
//blah
//blah
//blah
$query = "INSERT INTO `game` (`playername`, `sex`) values $query_string";
 
this is equal to

Code: Select all

 
$query = "INSERT INTO `game` (`playername`, `sex`) values $query_string ('".$post_key['sex']."', '".$post_key['playername']."'),";
 
you see the error? it has a "," appended character at the end of the sql statement.