Re: [PHP-DB] INSERT Question

2003-03-31 Thread Mustafa Ocak
You can't perform update like this.
You should loop through rows you want to update if they have different key
values.

UPDATE tbl_ib_articles SET col_name=new_value WHERE key_column=key_value;

You can change the condition part, which can include non-key columns,

HTH,
Mustafa



- Original Message -
From: "Charles Kline" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Tuesday, April 01, 2003 5:56 AM
Subject: Re: [PHP-DB] INSERT Question


Everything looks okay with this when I echo the sql string:

INSERT INTO tbl_ib_articles (issue_brief,article) VALUES
('24','30'),('24','20'),('24','31')

My question was, what do I need to change to make this an UPDATE?

Thanks,
Charles

On Monday, March 31, 2003, at 08:30 PM, [EMAIL PROTECTED] wrote:

> In a message dated 3/31/2003 5:26:36 PM Pacific Standard Time,
> [EMAIL PROTECTED] writes:
>
>
> > then I built the INSERT like so:
> > foreach($article_keys as $articleid)
> > {
> > $insert[] = "('$v_ib_id','$articleid')";
> > }
> > $article_sql = "INSERT INTO tbl_ib_articles (issue_brief,article)
> > VALUES " . implode(',',$insert);
>
>
>
> It's pretty much okay, except you don't have ( ) around the string
> that you create with the implode. You can echo $article_sql to see
> exactly what the SQL looks like and you can then modify your statement
> so you get the right SQL.
>
> Janet


--
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



Re: [PHP-DB] INSERT Question

2003-03-31 Thread Charles Kline
Everything looks okay with this when I echo the sql string:

INSERT INTO tbl_ib_articles (issue_brief,article) VALUES 
('24','30'),('24','20'),('24','31')

My question was, what do I need to change to make this an UPDATE?

Thanks,
Charles
On Monday, March 31, 2003, at 08:30 PM, [EMAIL PROTECTED] wrote:

In a message dated 3/31/2003 5:26:36 PM Pacific Standard Time, 
[EMAIL PROTECTED] writes:

> then I built the INSERT like so:
> foreach($article_keys as $articleid)
> {
> $insert[] = "('$v_ib_id','$articleid')";
> }
> $article_sql = "INSERT INTO tbl_ib_articles (issue_brief,article)
> VALUES " . implode(',',$insert);


It's pretty much okay, except you don't have ( ) around the string 
that you create with the implode. You can echo $article_sql to see 
exactly what the SQL looks like and you can then modify your statement 
so you get the right SQL.

Janet


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


Re: [PHP-DB] INSERT Question

2003-03-31 Thread Charles Kline
How would I modify the code below to handle an UPDATE?

On Sunday, March 30, 2003, at 07:19 PM, Charles Kline wrote:

then I built the INSERT like so:
foreach($article_keys as $articleid)
{
	$insert[] = "('$v_ib_id','$articleid')";
}
$article_sql = "INSERT INTO tbl_ib_articles (issue_brief,article) 
VALUES " . implode(',',$insert);


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


Re: [PHP-DB] INSERT Question

2003-03-30 Thread Charles Kline
Got it working - well actually not this exact form (I am will get to 
that) but another which uses checkboxes (which is basically the same 
idea).

Here is what I did and this is a bit different because I am using 
HTML_QuickForm which does not allow me to use a name like 
name="fieldname[]"

so my form ended up looking like this:

Test A
Test B
Test C
(this part of the form above was built with a loop from an articles 
table.

so... then this form gets submitted and I did this:

$article_arr = $ib_form->getSubmitValue("ib_article"); // this gets the 
array passed from QuickForm
$article_keys = array_keys($article_arr); // this sets a variable to an 
array of the keys

then I built the INSERT like so:
foreach($article_keys as $articleid)
{
	$insert[] = "('$v_ib_id','$articleid')";
}
$article_sql = "INSERT INTO tbl_ib_articles (issue_brief,article) 
VALUES " . implode(',',$insert);

Thanks to you both for all the help.

- Charles

On Saturday, March 29, 2003, at 09:21 PM, John W. Holmes wrote:

The only addition I have is to adapt the code to create a single INSERT
query in the format I gave earlier. It will run quicker overall.
---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/
-Original Message-
From: Charles Kline [mailto:[EMAIL PROTECTED]
Sent: Saturday, March 29, 2003 9:11 PM
To: Peter Lovatt
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] INSERT Question
Big help! Thanks much.

Now... to figure out how to create that kind of form in HTML_QuickForm
(hehehe). If I can't then I just make it by hand, but now I know the
method! Phew... always more to learn.
- Charles

On Saturday, March 29, 2003, at 08:51 PM, Peter Lovatt wrote:

Hi

you need to create 5 selects, all named investigator[] with index
1-5
(or
0-4), with the option set to empty for no selection.
this will return an array
investigator[1] => '1064618047'
investigator_yesno[1] => 'Y'
investigator[2] => '1649815377'
investigator_yesno[2] => 'N'
for example






Choose person
Paul A
Katrina A
David A

is a primary investigator?
Yes
No





Choose person
Paul A
Katrina A
David A

is a primary investigator?
Yes
No


...more here 




on the script receiving the data you  then need a for loop to insert
the
records, one for each person
for ($i = 1; $i <= 4; $i++)
{
//only do it if there is a value for $investigator[$i], ie there is
a
selection
if($investigator[$i]) {
$query = 'INSERT INTO tbl_report_people
(record_id
, person_id
, investigator_yesno
)
VALUES
("'.$record_id[$i].'"
, "'.$investigator[$i].'"
, "'.$investigator_yesno[$i].'"
)
';
$mysql_result = mysql_query($query, $mysql_link);
}//end if

}//end for



hope this helps

Peter







--
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


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


Re: [PHP-DB] INSERT Question

2003-03-29 Thread Charles Kline
Okay. Will do. Thanks both of you for your time and help. It is 
appreciated!

- Charles

On Saturday, March 29, 2003, at 09:21 PM, John W. Holmes wrote:

The only addition I have is to adapt the code to create a single INSERT
query in the format I gave earlier. It will run quicker overall.
---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/
-Original Message-
From: Charles Kline [mailto:[EMAIL PROTECTED]
Sent: Saturday, March 29, 2003 9:11 PM
To: Peter Lovatt
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] INSERT Question
Big help! Thanks much.

Now... to figure out how to create that kind of form in HTML_QuickForm
(hehehe). If I can't then I just make it by hand, but now I know the
method! Phew... always more to learn.
- Charles

On Saturday, March 29, 2003, at 08:51 PM, Peter Lovatt wrote:

Hi

you need to create 5 selects, all named investigator[] with index
1-5
(or
0-4), with the option set to empty for no selection.
this will return an array
investigator[1] => '1064618047'
investigator_yesno[1] => 'Y'
investigator[2] => '1649815377'
investigator_yesno[2] => 'N'
for example






Choose person
Paul A
Katrina A
David A

is a primary investigator?
Yes
No





Choose person
Paul A
Katrina A
David A

is a primary investigator?
Yes
No


...more here 




on the script receiving the data you  then need a for loop to insert
the
records, one for each person
for ($i = 1; $i <= 4; $i++)
{
//only do it if there is a value for $investigator[$i], ie there is
a
selection
if($investigator[$i]) {
$query = 'INSERT INTO tbl_report_people
(record_id
, person_id
, investigator_yesno
)
VALUES
("'.$record_id[$i].'"
, "'.$investigator[$i].'"
, "'.$investigator_yesno[$i].'"
)
';
$mysql_result = mysql_query($query, $mysql_link);
}//end if

}//end for



hope this helps

Peter







--
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


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


RE: [PHP-DB] INSERT Question

2003-03-29 Thread John W. Holmes
The only addition I have is to adapt the code to create a single INSERT
query in the format I gave earlier. It will run quicker overall.

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/

> -Original Message-
> From: Charles Kline [mailto:[EMAIL PROTECTED]
> Sent: Saturday, March 29, 2003 9:11 PM
> To: Peter Lovatt
> Cc: [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] INSERT Question
> 
> Big help! Thanks much.
> 
> Now... to figure out how to create that kind of form in HTML_QuickForm
> (hehehe). If I can't then I just make it by hand, but now I know the
> method! Phew... always more to learn.
> 
> - Charles
> 
> 
> On Saturday, March 29, 2003, at 08:51 PM, Peter Lovatt wrote:
> 
> > Hi
> >
> > you need to create 5 selects, all named investigator[] with index
1-5
> > (or
> > 0-4), with the option set to empty for no selection.
> >
> > this will return an array
> > investigator[1] => '1064618047'
> > investigator_yesno[1] => 'Y'
> >
> > investigator[2] => '1649815377'
> > investigator_yesno[2] => 'N'
> >
> > for example
> >
> >
> > 
> > 
> > 
> > 
> > 
> > Choose person
> > Paul A
> > Katrina A
> > David A
> > 
> > is a primary investigator?
> >  > checked="checked" />Yes
> > No
> > 
> > 
> > 
> > 
> > 
> > Choose person
> > Paul A
> > Katrina A
> > David A
> > 
> > is a primary investigator?
> >  > checked="checked" />Yes
> > No
> > 
> > 
> > ...more here 
> > 
> > 
> >
> >
> >
> > on the script receiving the data you  then need a for loop to insert
> > the
> > records, one for each person
> >
> >
> > for ($i = 1; $i <= 4; $i++)
> > {
> > //only do it if there is a value for $investigator[$i], ie there is
a
> > selection
> > if($investigator[$i]) {
> > $query = 'INSERT INTO tbl_report_people
> > (record_id
> > , person_id
> > , investigator_yesno
> > )
> > VALUES
> > ("'.$record_id[$i].'"
> > , "'.$investigator[$i].'"
> > , "'.$investigator_yesno[$i].'"
> > )
> > ';
> > $mysql_result = mysql_query($query, $mysql_link);
> >
> > }//end if
> >
> > }//end for
> >
> >
> >
> > hope this helps
> >
> > Peter
> >
> >
> >
> >
> >
> >
> >
> > --
> > 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



Re: [PHP-DB] INSERT Question

2003-03-29 Thread Charles Kline
Big help! Thanks much.

Now... to figure out how to create that kind of form in HTML_QuickForm 
(hehehe). If I can't then I just make it by hand, but now I know the 
method! Phew... always more to learn.

- Charles

On Saturday, March 29, 2003, at 08:51 PM, Peter Lovatt wrote:

Hi

you need to create 5 selects, all named investigator[] with index 1-5 
(or
0-4), with the option set to empty for no selection.

this will return an array
investigator[1] => '1064618047'
investigator_yesno[1] => 'Y'
investigator[2] => '1649815377'
investigator_yesno[2] => 'N'
for example






Choose person
Paul A
Katrina A
David A

is a primary investigator?
Yes
No





Choose person
Paul A
Katrina A
David A

is a primary investigator?
Yes
No


...more here 




on the script receiving the data you  then need a for loop to insert 
the
records, one for each person

for ($i = 1; $i <= 4; $i++)
{
//only do it if there is a value for $investigator[$i], ie there is a
selection
if($investigator[$i]) {
$query = 'INSERT INTO tbl_report_people
(record_id
, person_id
, investigator_yesno
)
VALUES
("'.$record_id[$i].'"
, "'.$investigator[$i].'"
, "'.$investigator_yesno[$i].'"
)
';
$mysql_result = mysql_query($query, $mysql_link);
}//end if

}//end for



hope this helps

Peter







--
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


RE: [PHP-DB] INSERT Question

2003-03-29 Thread Peter Lovatt
Hi

you need to create 5 selects, all named investigator[] with index 1-5 (or
0-4), with the option set to empty for no selection.

this will return an array
investigator[1] => '1064618047'
investigator_yesno[1] => 'Y'

investigator[2] => '1649815377'
investigator_yesno[2] => 'N'

for example







Choose person
Paul A
Katrina A
David A

is a primary investigator?
Yes
No





Choose person
Paul A
Katrina A
David A

is a primary investigator?
Yes
No


...more here 





on the script receiving the data you  then need a for loop to insert the
records, one for each person


for ($i = 1; $i <= 4; $i++)
{
//only do it if there is a value for $investigator[$i], ie there is a
selection
if($investigator[$i]) {
$query = 'INSERT INTO tbl_report_people
(record_id
, person_id
, investigator_yesno
)
VALUES
("'.$record_id[$i].'"
, "'.$investigator[$i].'"
, "'.$investigator_yesno[$i].'"
)
';
$mysql_result = mysql_query($query, $mysql_link);

}//end if

}//end for



hope this helps

Peter







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



Re: [PHP-DB] INSERT Question

2003-03-29 Thread Charles Kline
John,
I modified my form, but not having much luck.
Here is my new form (so far):

** I need to add 4 more selects, not sure how to name them **


Choose person
Paul A
Katrina A
David A

is a primary investigator?
Yes
No

When I submit this form and do a print_r() on the array this is what I 
get.

 ["investigator"]=>
  array(2) {
["person"]=>
string(10) "1033592151"
["yesno"]=>
string(1) "Y"
  }
How would I apply your 'how-to' to this? I have gotten stuck now.

Thanks again,
Charles
On Saturday, March 29, 2003, at 05:46 PM, John W. Holmes wrote:

Since I don't totally understand (newbie) I will show you an example
of
the form.



Joe Smith
etc.

 Y type="radio"
name="person1yn" value="No"> N
So if the 'Y' radio button is chosen, you'll want to take that 'person'
and input them into the table?
First, the easy way would be to lose the radio button and just put a
"Choose Person" option in the  dropdown. Then, only process the
names if it's not "Choose Person"...
Even if you can't lose the radio buttons, you'll need to make 
everything
arrays so they are easier to process.



Choose Person
Joe Smith
...

Then, to process that (assuming POST) you'd use:

Foreach($_POST['person'] as $person_id)
{
if($person_id > 0)
{ $insert[] = "('$person_id')"; }
}
$sql = "INSERT INTO table (person_id) VALUES " . implode(',',$insert);
Then run $sql... The second part loops through each "person" select and
makes sure the value isn't zero before it creates the ('value') part of
the SQL. The implode() at the end of the $sql line takes each ('value')
part and joins them into a string separated by a comma.
Does that help at all?

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.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


Re: [PHP-DB] INSERT Question

2003-03-29 Thread Charles Kline
John,
Thanks. Yes that is a big help. The radio button is actually not used 
for that purpose (sorry that was a bit confusing of me to put in 
without an explanation). For each person selected, the radio button Y/N 
relates to whether they are an author of the report or just a 
contributer. I assume, the radio button can be handled the same way and 
I can just extrapolate your example to figure that out - I think ;)

- Charles

On Saturday, March 29, 2003, at 05:46 PM, John W. Holmes wrote:

Since I don't totally understand (newbie) I will show you an example
of
the form.



Joe Smith
etc.

 Y type="radio"
name="person1yn" value="No"> N
So if the 'Y' radio button is chosen, you'll want to take that 'person'
and input them into the table?
First, the easy way would be to lose the radio button and just put a
"Choose Person" option in the  dropdown. Then, only process the
names if it's not "Choose Person"...
Even if you can't lose the radio buttons, you'll need to make 
everything
arrays so they are easier to process.



Choose Person
Joe Smith
...

Then, to process that (assuming POST) you'd use:

Foreach($_POST['person'] as $person_id)
{
if($person_id > 0)
{ $insert[] = "('$person_id')"; }
}
$sql = "INSERT INTO table (person_id) VALUES " . implode(',',$insert);
Then run $sql... The second part loops through each "person" select and
makes sure the value isn't zero before it creates the ('value') part of
the SQL. The implode() at the end of the $sql line takes each ('value')
part and joins them into a string separated by a comma.
Does that help at all?

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.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


RE: [PHP-DB] INSERT Question

2003-03-29 Thread John W. Holmes
> Since I don't totally understand (newbie) I will show you an example
of
> the form.
> 
> 
> 
> Joe Smith
> etc.
> 
>  Y  name="person1yn" value="No"> N

So if the 'Y' radio button is chosen, you'll want to take that 'person'
and input them into the table?

First, the easy way would be to lose the radio button and just put a
"Choose Person" option in the  dropdown. Then, only process the
names if it's not "Choose Person"...

Even if you can't lose the radio buttons, you'll need to make everything
arrays so they are easier to process.



Choose Person
Joe Smith
...


Then, to process that (assuming POST) you'd use:

Foreach($_POST['person'] as $person_id)
{
if($person_id > 0)
{ $insert[] = "('$person_id')"; }
}
$sql = "INSERT INTO table (person_id) VALUES " . implode(',',$insert);

Then run $sql... The second part loops through each "person" select and
makes sure the value isn't zero before it creates the ('value') part of
the SQL. The implode() at the end of the $sql line takes each ('value')
part and joins them into a string separated by a comma.

Does that help at all?

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



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



Re: [PHP-DB] INSERT Question

2003-03-29 Thread Charles Kline
Since I don't totally understand (newbie) I will show you an example of 
the form.



Joe Smith
etc.

 Y  N


Joe Smith
etc.

 Y  N

and so on...




On Saturday, March 29, 2003, at 05:25 PM, John W. Holmes wrote:

I was wondering what is the best way to insert multiple records into a
table? Here is the scenario...
I have a form which has 5 select menus as part of the data that gets
entered. Most of the data goes into a table called tbl_reports. Each
of
these 5 menus contains the same list of people (from tbl_people). I
have another table which I am calling tbl_report_people which I want
to
INSERT a record for each person that is selected for any new report (I
hope this is making sense). So for example, a new report form is
filled
out and submitted. 3 of the people selects are used, so I need to add
to the tbl_report_people table the record_id and person_id for each
person selected.
The fastest way will be to create your INSERT dynamically and do them
all at once. The format would be:
INSERT INTO table (column1, column2) VALUES
(value1,value2),(value11,value22),(value111,value222)
If you're getting record_id and person_id from a form, you can just 
loop
through them and create each (value,value) part and then add on the
beginning. Without seeing your actual form, that'd be about the best
advice I can give.

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



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


RE: [PHP-DB] INSERT Question

2003-03-29 Thread John W. Holmes
> I was wondering what is the best way to insert multiple records into a
> table? Here is the scenario...
> 
> I have a form which has 5 select menus as part of the data that gets
> entered. Most of the data goes into a table called tbl_reports. Each
of
> these 5 menus contains the same list of people (from tbl_people). I
> have another table which I am calling tbl_report_people which I want
to
> INSERT a record for each person that is selected for any new report (I
> hope this is making sense). So for example, a new report form is
filled
> out and submitted. 3 of the people selects are used, so I need to add
> to the tbl_report_people table the record_id and person_id for each
> person selected.

The fastest way will be to create your INSERT dynamically and do them
all at once. The format would be:

INSERT INTO table (column1, column2) VALUES
(value1,value2),(value11,value22),(value111,value222)

If you're getting record_id and person_id from a form, you can just loop
through them and create each (value,value) part and then add on the
beginning. Without seeing your actual form, that'd be about the best
advice I can give. 

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



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



RE: [PHP-DB] INSERT question. 2 pointers.

2002-11-22 Thread Hutchins, Richard
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Friday, November 22, 2002 1:11 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] 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:[EMAIL PROTECTED]]
> Sent: Thursday, November 21, 2002 12:46 AM
> To: '[EMAIL PROTECTED]'
> Subject: [PHP-DB] 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:  [EMAIL PROTECTED]
> 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




RE: [PHP-DB] INSERT question...

2002-11-20 Thread NIPP, SCOTT V (SBCSI)
Thanks a bunch.  That fixed me right up.  Still learning a lot about
PHP and MySQL.  Hopefully I will be able to remember this as I am sure this
issue will come up for me again in the future.

-Original Message-
From: 1LT John W. Holmes [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 20, 2002 2:47 PM
To: NIPP, SCOTT V (SBCSI); 'Aaron Wolski'; [EMAIL PROTECTED]
Subject: Re: [PHP-DB] INSERT question...



>  $query = "INSERT INTO accounts (`id-sys`, rtime) VALUES('".$accnts[0]."',
> 'NOW()')";

Remove the quotes around NOW(). It's a function, not a string.

---John Holmes...

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




Re: [PHP-DB] INSERT question...

2002-11-20 Thread 1LT John W. Holmes

>  $query = "INSERT INTO accounts (`id-sys`, rtime) VALUES('".$accnts[0]."',
> 'NOW()')";

Remove the quotes around NOW(). It's a function, not a string.

---John Holmes...


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




RE: [PHP-DB] INSERT question...

2002-11-20 Thread NIPP, SCOTT V (SBCSI)
Great.  That is perfect.  The last minor issue is that the timestamp
is a datetime column, and needs to be such since I don't want this to change
when the record is updated.  This is correct, right?  If the column were a
timestamp data type, the value would change every time the record is
updated?  I am trying:

 $query = "INSERT INTO accounts (`id-sys`, rtime) VALUES('".$accnts[0]."',
'NOW()')";

This is entering the array element properly, but not the time.  The
datetime field is coming up with all zeroes.

-Original Message-
From: 1LT John W. Holmes [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 20, 2002 2:21 PM
To: NIPP, SCOTT V (SBCSI); 'Aaron Wolski'; [EMAIL PROTECTED]
Subject: Re: [PHP-DB] INSERT question...


> OK.  This sounds great, but now I am getting a completely different
> error message.
>
> You have an error in your SQL syntax near '-sys) VALUES('sn4265-turner')'
at
> line 1
>
> Here is the INSERT statement:
>
> $query = "INSERT INTO accounts (id-sys) VALUES('".$accnts[0]."')";
>
> Do I have to rename the column?  I would rather not if I can avoid
> it.  If I must, is this a problem with PHP or MySQL not understanding '-'
in
> a column name?  Thanks again.

Try putting backtics (not single quotes) around the column name.

$query = "INSERT INTO accounts (`id-sys`) VALUES ('".$accnts[0]."')";

if that don't work, you'll have to rename the column.

---John Holmes...

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




Re: [PHP-DB] INSERT question...

2002-11-20 Thread Ryan Gallagher
Quoting "1LT John W. Holmes" <[EMAIL PROTECTED]>:

> > OK.  This sounds great, but now I am getting a completely different
> > error message.
> >
> > You have an error in your SQL syntax near '-sys) VALUES('sn4265-turner')'
> at
> > line 1
> >
> > Here is the INSERT statement:
> >
> > $query = "INSERT INTO accounts (id-sys) VALUES('".$accnts[0]."')";
> >
> > Do I have to rename the column?  I would rather not if I can avoid
> > it.  If I must, is this a problem with PHP or MySQL not understanding '-'
> in
> > a column name?  Thanks again.
> 
> Try putting backtics (not single quotes) around the column name.
> 
> $query = "INSERT INTO accounts (`id-sys`) VALUES ('".$accnts[0]."')";
> 
> if that don't work, you'll have to rename the column.

Are backtics the same for MYSQL that brackets are for other dbs?  I would use
[id-sys], but then again i'm stuck with MS-SQL.
-- 
Ryan T. Gallagher




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




Re: [PHP-DB] INSERT question...

2002-11-20 Thread 1LT John W. Holmes
> OK.  This sounds great, but now I am getting a completely different
> error message.
>
> You have an error in your SQL syntax near '-sys) VALUES('sn4265-turner')'
at
> line 1
>
> Here is the INSERT statement:
>
> $query = "INSERT INTO accounts (id-sys) VALUES('".$accnts[0]."')";
>
> Do I have to rename the column?  I would rather not if I can avoid
> it.  If I must, is this a problem with PHP or MySQL not understanding '-'
in
> a column name?  Thanks again.

Try putting backtics (not single quotes) around the column name.

$query = "INSERT INTO accounts (`id-sys`) VALUES ('".$accnts[0]."')";

if that don't work, you'll have to rename the column.

---John Holmes...


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




RE: [PHP-DB] INSERT question...

2002-11-20 Thread NIPP, SCOTT V (SBCSI)
OK.  This sounds great, but now I am getting a completely different
error message.

You have an error in your SQL syntax near '-sys) VALUES('sn4265-turner')' at
line 1

Here is the INSERT statement:

$query = "INSERT INTO accounts (id-sys) VALUES('".$accnts[0]."')";

Do I have to rename the column?  I would rather not if I can avoid
it.  If I must, is this a problem with PHP or MySQL not understanding '-' in
a column name?  Thanks again.

-Original Message-
From: Aaron Wolski [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 20, 2002 1:28 PM
To: '1LT John W. Holmes'; NIPP, SCOTT V (SBCSI); [EMAIL PROTECTED]
Subject: RE: [PHP-DB] INSERT question...


Hmm


You learn something new everyday :)

Aaron

-Original Message-
From: 1LT John W. Holmes [mailto:[EMAIL PROTECTED]] 
Sent: November 20, 2002 2:27 PM
To: Aaron Wolski; 'NIPP, SCOTT V (SBCSI)'; [EMAIL PROTECTED]
Subject: Re: [PHP-DB] INSERT question...

> Try... $query = "INSERT INTO accounts (accnts,timestamp)
> VALUES(''.$accnts[0].'','TIMESTAMP(10)')";
>
> Might work?
>
> Aaron
>

For the OP, you don't really want to insert the text TIMESTAMP(10) into
a
column, do you? If you want the current 10-digit timestamp, then you can
just use NOW() or CURRENT_DATE, so long as your column is declared with
a
width of 10. In fact, if it's a timestamp, you don't need to do
anything,
it'll be updated with the current time upon insert. so you could
probably
just do this:

$query = "INSERT INTO accounts (accnts) VALUES (".$accnts[0].")";

---John Holmes...

>
> -Original Message-
> From: NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED]]
> Sent: November 20, 2002 2:16 PM
> To: '[EMAIL PROTECTED]'
> Subject: [PHP-DB] 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:  [EMAIL PROTECTED]
> 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




Re: [PHP-DB] INSERT question...

2002-11-20 Thread Ryan Gallagher
Quoting "NIPP, SCOTT V (SBCSI)" <[EMAIL PROTECTED]>:

>   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:  [EMAIL PROTECTED]
> Web:  http:\\ldsa.sbcld.sbc.com

I believe you will need to specify the target columns, and don't attempt to use
comma delimited nothings! ;-)

Example:
INSERT INTO accounts (col1, col2) VALUES ('val1', 'val2')


-- 
Ryan T. Gallagher
[EMAIL PROTECTED]
International Studies Abroad
http://www.studiesabroad.com
(512)480-8522



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




RE: [PHP-DB] INSERT question...

2002-11-20 Thread Aaron Wolski
Hmm


You learn something new everyday :)

Aaron

-Original Message-
From: 1LT John W. Holmes [mailto:[EMAIL PROTECTED]] 
Sent: November 20, 2002 2:27 PM
To: Aaron Wolski; 'NIPP, SCOTT V (SBCSI)'; [EMAIL PROTECTED]
Subject: Re: [PHP-DB] INSERT question...

> Try... $query = "INSERT INTO accounts (accnts,timestamp)
> VALUES(''.$accnts[0].'','TIMESTAMP(10)')";
>
> Might work?
>
> Aaron
>

For the OP, you don't really want to insert the text TIMESTAMP(10) into
a
column, do you? If you want the current 10-digit timestamp, then you can
just use NOW() or CURRENT_DATE, so long as your column is declared with
a
width of 10. In fact, if it's a timestamp, you don't need to do
anything,
it'll be updated with the current time upon insert. so you could
probably
just do this:

$query = "INSERT INTO accounts (accnts) VALUES (".$accnts[0].")";

---John Holmes...

>
> -Original Message-
> From: NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED]]
> Sent: November 20, 2002 2:16 PM
> To: '[EMAIL PROTECTED]'
> Subject: [PHP-DB] 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:  [EMAIL PROTECTED]
> 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




Re: [PHP-DB] INSERT question...

2002-11-20 Thread 1LT John W. Holmes
> Try... $query = "INSERT INTO accounts (accnts,timestamp)
> VALUES(''.$accnts[0].'','TIMESTAMP(10)')";
>
> Might work?
>
> Aaron
>

For the OP, you don't really want to insert the text TIMESTAMP(10) into a
column, do you? If you want the current 10-digit timestamp, then you can
just use NOW() or CURRENT_DATE, so long as your column is declared with a
width of 10. In fact, if it's a timestamp, you don't need to do anything,
it'll be updated with the current time upon insert. so you could probably
just do this:

$query = "INSERT INTO accounts (accnts) VALUES (".$accnts[0].")";

---John Holmes...

>
> -Original Message-
> From: NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED]]
> Sent: November 20, 2002 2:16 PM
> To: '[EMAIL PROTECTED]'
> Subject: [PHP-DB] 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:  [EMAIL PROTECTED]
> 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




RE: [PHP-DB] INSERT question...

2002-11-20 Thread Aaron Wolski
Try... $query = "INSERT INTO accounts (accnts,timestamp)
VALUES(''.$accnts[0].'','TIMESTAMP(10)')";

Might work?

Aaron



-Original Message-
From: NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED]] 
Sent: November 20, 2002 2:16 PM
To: '[EMAIL PROTECTED]'
Subject: [PHP-DB] 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:  [EMAIL PROTECTED]
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