0

I am trying to run PHP could which inserts a value into a MySQL table.

My db connection is working ok.

I have the code in a function:

function InsertRighmoveID($RightmoveID)
{
    # Connection already created in main program

    #Define the query to insert righmove ID already in Database
    #VALUES ('" . substr($name, 23, 31) . "')";

    echo "In InsertRighmoveID() function </br>";
        $query_enter_rightmove_ID = 

        "INSERT INTO tblRightMoveIDs (rightmoveID)
        VALUES ('" . $RightmoveID . "');";

        #Echo the query to check it

        echo $query_enter_rightmove_ID . "</br>";

        #Execute the query
        $query_enter_rightmove_ID = mysql_query($query_enter_rightmove_ID);
        echo "Leaving InsertRighmoveID() function </br>";

        #Execute the query
        $query_enter_rightmove_ID = mysql_query($query_enter_rightmove_ID);

        #Check to see if the query worked   
        if (!$query_enter_rightmove_ID) 
            {
                die("Database query failed:" . mysql_error());
            }
        echo "Leaving InsertRighmoveID() function </br>";
}

when I run the code in a webpage, get it to print the query to screen this is the message:

INSERT INTO tblRightMoveIDs (rightmoveID) VALUES ('44047607')

Database query failed:

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 '1' at line 1

44047607 is the value passed to the function.

If I run the:

INSERT INTO tblRightMoveIDs (rightmoveID) VALUES ('44047607'); 

Outside the program it works.

2
  • Edit your code properly Commented Nov 21, 2013 at 10:12
  • why u r making an easy program so complex? Commented Nov 21, 2013 at 10:20

2 Answers 2

1

Remove the semicolon ; from here

 "INSERT INTO tblRightMoveIDs (rightmoveID)
    VALUES ('" . $RightmoveID . "');";
                            -------^
Sign up to request clarification or add additional context in comments.

Comments

0

There is error here in the starred parts:

**$query_enter_rightmove_ID** = mysql_query($query_enter_rightmove_ID);
echo "Leaving InsertRighmoveID() function </br>";
#Execute the query
$query_enter_rightmove_ID = mysql_query(**$query_enter_rightmove_ID**);

You are executing mysql_query first time with a proper query and it puts the result into $query_enter_rightmove_ID variable. Second time, you are using the result of first query as the parameter to mysql_query which is wrong

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.