[SOLVED] Insert Statement problems

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
afbase
Forum Contributor
Posts: 113
Joined: Tue Aug 15, 2006 1:29 pm
Location: SoCAL!!!!

[SOLVED] Insert Statement problems

Post 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.
Last edited by afbase on Wed Jun 13, 2007 4:45 pm, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
afbase
Forum Contributor
Posts: 113
Joined: Tue Aug 15, 2006 1:29 pm
Location: SoCAL!!!!

Post by afbase »

yes it is
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

If the columns are all varchar then you need to wrap the inserted data in quotes.
afbase
Forum Contributor
Posts: 113
Joined: Tue Aug 15, 2006 1:29 pm
Location: SoCAL!!!!

Post 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)."';
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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]}'
        )"; 
?>
Post Reply