RE: INSERT question. 2 pointers.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Actually, according to the MySQL manual and experience, if you don't want to
insert data into each column in a table, you can specify the columns you DO
want to insert data into. See below:

$sql = "INSERT INTO myTable (col1,col3,col4) VALUES
('$val1','$val2','$val3')";

As you can see, the above query would only insert data into three out of
four columns. Your list of VALUES must exactly match the number of columns
specified in the list. Any columns for which a value is not provided will be
set to their default value.

If you need more information, check the MySQL manual under the heading
"INSERT Syntax".

> -----Original Message-----
> From: Amit_Wadhwa@Dell.com [mailto:Amit_Wadhwa@Dell.com]
> Sent: Friday, November 22, 2002 1:11 AM
> To: php-db@lists.php.net
> Subject:  INSERT question. 2 pointers.
> 
> 
> hi Scott,
> 
> 1. When you are using an insert where you dont want to use 
> all columns:
> use this:
> $query = "INSERT INTO accounts VALUES('".$accnts[0]."',
> 'TIMESTAMP(10)','','','','',)";
> (never have empty comma strings with nothing inside.)
> 
> 2. Secondly, when you get errors, and you dont know where the error is
> do this:
> before executing the query,
> print out the query on the browser (comment out the query 
> execution code) 
> and then copy paste the query from the browser
> and then run the same in your mysql client, 
> and you will know exactly where is the problem from the error 
> generated.
> regards,
> 
> ***************************
> Amit Wadhwa 
> Dell International Services
> ***************************
> 
> -----Original Message-----
> From: NIPP, SCOTT V (SBCSI) [mailto:sn4265@sbc.com]
> Sent: Thursday, November 21, 2002 12:46 AM
> To: 'php-db@lists.php.net'
> Subject:  INSERT question...
> 
> 
> 	I have an INSERT statement that I cannot quiet get working.  The
> table that this data is being put into has 7 columns, but I 
> only care about
> putting in the data from the first two columns at this time.  
> The first
> column is an array element, and the second column needs to be 
> a timestamp.
> Here is the INSERT statement:
> 
> $query = "INSERT INTO accounts VALUES('".$accnts[0]."', 
> 'TIMESTAMP(10)', , ,
> , ,)";
> 
> 	Here is the error being displayed on the web page:
> 
> You have an error in your SQL syntax near ' , , ,)' at line 1
> 	Thanks in advance for the help.
> 
> Scott Nipp
> Phone:  (214) 858-1289
> E-mail:  sn4265@sbc.com
> Web:  http:\\ldsa.sbcld.sbc.com
> 
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux