Page 1 of 1

[SOLVED] Insert Statement problems

Posted: Wed Jun 13, 2007 1:17 pm
by afbase
I'm having trouble with this MYSQL statement

Code: Select all

INSERT INTO country_html (FY_2000_AG,FY_2000_IND,FY_2000_SRV,FY_2005_AG,FY_2005_IND,FY_2005_SRV) VALUES(".$row[1][117].",".$row[1][121].",".$row[1][125].",".$row[1][118].",".$row[1][122].",".$row[1][126].");
from my php code:

Code: Select all

function mysql_insert_array($database){
		$row = 	$this->get_regex_array();
		$this->connect();
		$this->database($database);
		$this->null_test($this->get_regex_array());
		$sql_query="INSERT INTO country_html (FY_2000_AG,FY_2000_IND,FY_2000_SRV,FY_2005_AG,FY_2005_IND,FY_2005_SRV) VALUES(".$row[1][117].",".$row[1][121].",".$row[1][125].",".$row[1][118].",".$row[1][122].",".$row[1][126].");";
		$this->query($sql_query);
		$this->close();
		
	}
the returned error is
INSERT INTO country_html (FY_2000_AG,FY_2000_IND,FY_2000_SRV,FY_2005_AG,FY_2005_IND,FY_2005_SRV) VALUES(.. ,.. ,.. ,24.5 ,39.4 ,12.4 ); failed. Error number: 1064 Message: 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 '. ,.. ,.. ,24.5 ,39.4 ,12.4 )' at line 1

I wouldn't be surprised if it is a really easy mistatke that I am just not noticing in my statement. By the way, FY_2000_AG, FY_2000_IND, FY_2000_SRV, FY_2005_AG, FY_2005_IND, FY_2005_SRV are all VARCHAR columns in the MYSQL table country_html.

Posted: Wed Jun 13, 2007 1:50 pm
by volka
Is
check the manual that corresponds to your MySQL server version for the right syntax to use near '. ,.. ,.. ,24.5 ,39.4 ,12.4 )' at line 1
the original error message?

Posted: Wed Jun 13, 2007 2:57 pm
by afbase
yes it is

Posted: Wed Jun 13, 2007 3:35 pm
by RobertGonzalez
If the columns are all varchar then you need to wrap the inserted data in quotes.

Posted: Wed Jun 13, 2007 4:44 pm
by afbase
thanks everah i got it to work. Yes, that was a silly mistake by me.

Code: Select all

UPDATE country_html SET FY_2000_AG ='".$row[1][117]."',  FY_2000_IND = '".$row[1][121]."',  FY_2000_SRV = '".$row[1][125]."',   FY_2005_AG = '".$row[1][118]."',  FY_2005_IND = '".$row[1][122]."',    FY_2005_SRV =  '".$row[1][126]."' WHERE country_id = '".substr($link,-3)."';

Posted: Wed Jun 13, 2007 5:10 pm
by RobertGonzalez
You know, for cleanliness in your code, you could do:

Code: Select all

<?php
$sql = "INSERT INTO 
            country_html (
                FY_2000_AG, FY_2000_IND, FY_2000_SRV, FY_2005_AG, FY_2005_IND, FY_2005_SRV
            ) 
        VALUES (
            '{$row[1][117]}','{$row[1][121]}','{$row[1][125]}','{$row[1][118]}','{$row[1][122]}','{$row[1][126]}'
        )"; 
?>