Re: [PHP] [php] INSERT and immediately UPDATE

2009-10-28 Thread Mari Masuda
Maybe you could use http://us.php.net/manual/en/function.mysql-insert-id.php 
 to get the inserted id.


On Oct 28, 2009, at 12:21 PM, Allen McCabe wrote:


Hey everyone, I have an issue.

I need my (employee) users to be able to insert shows into the our  
MySQL
database and simultaneously upload an image file (and store the path  
in the

table).

I have accomplished this with a product-based system (adding  
products and
uploading images of the product), and accomplished what I needed  
because the

product name was unique; I used the following statements:

$prodName = $_POST['prodName'];
$prodDesc = $_POST['prodDesc'];
$prodPrice = $_POST['prodPrice'];

$query2  = INSERT INTO product (pID, pName) VALUES (NULL,  
'$prodName');;

$result2 = mysql_query($query2) or die(mysql_error());

$query  = SELECT pID FROM product WHERE pName = '$prodName';;
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die (mysql_error());

$prodID = $row['pID'];


I had to select the new product to get the product id to use in the  
new

unique image name.

The problem I am facing now, is that with the shows that my users  
add will
have multitple show times; this means non-unique titles. In fact,  
the only
unique identifier is the show id. How can I insert something  
(leaving the
show_id field NULL so that it is auto-assigned the next ID number),  
and then

immediately select it?

PHP doesn't seem to be able to immediately select something it has  
just

inserted, perhaps it needs time to process the database update.

Here is the code I have now (which does not work):

$query2  = INSERT INTO afy_show (show_id, show_title, show_day_w,
show_month, show_day_m, show_year, show_time, show_price,  
show_description,

show_comments_1, show_seats_reqd) VALUES (NULL, '{$show_title}',
'{$show_day_w}', '{$show_month}', '{$show_day_m}', '{$show_year}',
'{$show_time}', '{$show_price}', '{$show_description}',
'{$show_comments_1}', '{$show_seats_reqd}');;
$result2 = mysql_query($query2) or die(mysql_error());

$query3 = SELECT * FROM afy_show WHERE *show_id = '$id'*;;
$result3 = mysql_query($query3) or die('Record cannot be located!' .
mysql_error());
$row3 = mysql_fetch_array($result3);
$show_id = $row3['show_id'];

How do I select the item I just inserted to obtain the ID number??



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



Re: [PHP] [php] INSERT and immediately UPDATE

2009-10-28 Thread Ashley Sheridan
On Wed, 2009-10-28 at 12:21 -0700, Allen McCabe wrote:

 Hey everyone, I have an issue.
 
 I need my (employee) users to be able to insert shows into the our MySQL
 database and simultaneously upload an image file (and store the path in the
 table).
 
 I have accomplished this with a product-based system (adding products and
 uploading images of the product), and accomplished what I needed because the
 product name was unique; I used the following statements:
 
 $prodName = $_POST['prodName'];
 $prodDesc = $_POST['prodDesc'];
 $prodPrice = $_POST['prodPrice'];
 
 $query2  = INSERT INTO product (pID, pName) VALUES (NULL, '$prodName');;
 $result2 = mysql_query($query2) or die(mysql_error());
 
 $query  = SELECT pID FROM product WHERE pName = '$prodName';;
 $result = mysql_query($query) or die(mysql_error());
 $row = mysql_fetch_array($result) or die (mysql_error());
 
 $prodID = $row['pID'];
 
 
 I had to select the new product to get the product id to use in the new
 unique image name.
 
 The problem I am facing now, is that with the shows that my users add will
 have multitple show times; this means non-unique titles. In fact, the only
 unique identifier is the show id. How can I insert something (leaving the
 show_id field NULL so that it is auto-assigned the next ID number), and then
 immediately select it?
 
 PHP doesn't seem to be able to immediately select something it has just
 inserted, perhaps it needs time to process the database update.
 
 Here is the code I have now (which does not work):
 
 $query2  = INSERT INTO afy_show (show_id, show_title, show_day_w,
 show_month, show_day_m, show_year, show_time, show_price, show_description,
 show_comments_1, show_seats_reqd) VALUES (NULL, '{$show_title}',
 '{$show_day_w}', '{$show_month}', '{$show_day_m}', '{$show_year}',
 '{$show_time}', '{$show_price}', '{$show_description}',
 '{$show_comments_1}', '{$show_seats_reqd}');;
  $result2 = mysql_query($query2) or die(mysql_error());
 
  $query3 = SELECT * FROM afy_show WHERE *show_id = '$id'*;;
  $result3 = mysql_query($query3) or die('Record cannot be located!' .
 mysql_error());
  $row3 = mysql_fetch_array($result3);
  $show_id = $row3['show_id'];
 
 How do I select the item I just inserted to obtain the ID number??


Have a look at mysql_insert_id() which returns the auto insert id value
of the last row to be inserted by the current script. If you use if
right after the insert query (without any other queries in between) then
you have the id for that row. Whatever you do, don't look for the
MAX(id) value! I've seen people do this before, and then wonder why the
database gets all corrupted when more than one person uses the system at
the same time!

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] [php] INSERT and immediately UPDATE

2009-10-28 Thread Floyd Resler

Allen,
	Use mysql_insert_id().  This will return the id of the last record  
inserted.


Take care,
Floyd

On Oct 28, 2009, at 3:21 PM, Allen McCabe wrote:


Hey everyone, I have an issue.

I need my (employee) users to be able to insert shows into the our  
MySQL
database and simultaneously upload an image file (and store the path  
in the

table).

I have accomplished this with a product-based system (adding  
products and
uploading images of the product), and accomplished what I needed  
because the

product name was unique; I used the following statements:

$prodName = $_POST['prodName'];
$prodDesc = $_POST['prodDesc'];
$prodPrice = $_POST['prodPrice'];

$query2  = INSERT INTO product (pID, pName) VALUES (NULL,  
'$prodName');;

$result2 = mysql_query($query2) or die(mysql_error());

$query  = SELECT pID FROM product WHERE pName = '$prodName';;
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die (mysql_error());

$prodID = $row['pID'];


I had to select the new product to get the product id to use in the  
new

unique image name.

The problem I am facing now, is that with the shows that my users  
add will
have multitple show times; this means non-unique titles. In fact,  
the only
unique identifier is the show id. How can I insert something  
(leaving the
show_id field NULL so that it is auto-assigned the next ID number),  
and then

immediately select it?

PHP doesn't seem to be able to immediately select something it has  
just

inserted, perhaps it needs time to process the database update.

Here is the code I have now (which does not work):

$query2  = INSERT INTO afy_show (show_id, show_title, show_day_w,
show_month, show_day_m, show_year, show_time, show_price,  
show_description,

show_comments_1, show_seats_reqd) VALUES (NULL, '{$show_title}',
'{$show_day_w}', '{$show_month}', '{$show_day_m}', '{$show_year}',
'{$show_time}', '{$show_price}', '{$show_description}',
'{$show_comments_1}', '{$show_seats_reqd}');;
$result2 = mysql_query($query2) or die(mysql_error());

$query3 = SELECT * FROM afy_show WHERE *show_id = '$id'*;;
$result3 = mysql_query($query3) or die('Record cannot be located!' .
mysql_error());
$row3 = mysql_fetch_array($result3);
$show_id = $row3['show_id'];

How do I select the item I just inserted to obtain the ID number??



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



Re: [PHP] [php] INSERT and immediately UPDATE

2009-10-28 Thread Martin Scotta
On Wed, Oct 28, 2009 at 4:21 PM, Allen McCabe allenmcc...@gmail.com wrote:

 Hey everyone, I have an issue.

 I need my (employee) users to be able to insert shows into the our MySQL
 database and simultaneously upload an image file (and store the path in the
 table).

 I have accomplished this with a product-based system (adding products and
 uploading images of the product), and accomplished what I needed because
 the
 product name was unique; I used the following statements:

 $prodName = $_POST['prodName'];
 $prodDesc = $_POST['prodDesc'];
 $prodPrice = $_POST['prodPrice'];

 $query2  = INSERT INTO product (pID, pName) VALUES (NULL, '$prodName');;
 $result2 = mysql_query($query2) or die(mysql_error());

 $query  = SELECT pID FROM product WHERE pName = '$prodName';;
 $result = mysql_query($query) or die(mysql_error());
 $row = mysql_fetch_array($result) or die (mysql_error());

 $prodID = $row['pID'];


 I had to select the new product to get the product id to use in the new
 unique image name.

 The problem I am facing now, is that with the shows that my users add will
 have multitple show times; this means non-unique titles. In fact, the only
 unique identifier is the show id. How can I insert something (leaving the
 show_id field NULL so that it is auto-assigned the next ID number), and
 then
 immediately select it?

 PHP doesn't seem to be able to immediately select something it has just
 inserted, perhaps it needs time to process the database update.

 Here is the code I have now (which does not work):

 $query2  = INSERT INTO afy_show (show_id, show_title, show_day_w,
 show_month, show_day_m, show_year, show_time, show_price, show_description,
 show_comments_1, show_seats_reqd) VALUES (NULL, '{$show_title}',
 '{$show_day_w}', '{$show_month}', '{$show_day_m}', '{$show_year}',
 '{$show_time}', '{$show_price}', '{$show_description}',
 '{$show_comments_1}', '{$show_seats_reqd}');;
  $result2 = mysql_query($query2) or die(mysql_error());

  $query3 = SELECT * FROM afy_show WHERE *show_id = '$id'*;;
  $result3 = mysql_query($query3) or die('Record cannot be located!' .
 mysql_error());
  $row3 = mysql_fetch_array($result3);
  $show_id = $row3['show_id'];

 How do I select the item I just inserted to obtain the ID number??


mysql_insert_id http://ar.php.net/manual/en/function.mysql-insert-id.php
mysqli-insert_id http://ar.php.net/manual/en/mysqli.insert-id.php


-- 
Martin Scotta


Re: [PHP] [php] INSERT and immediately UPDATE

2009-10-28 Thread Allen McCabe
You all are great! Thank you so much.



On Wed, Oct 28, 2009 at 12:27 PM, Martin Scotta martinsco...@gmail.comwrote:



 On Wed, Oct 28, 2009 at 4:21 PM, Allen McCabe allenmcc...@gmail.comwrote:

 Hey everyone, I have an issue.

 I need my (employee) users to be able to insert shows into the our MySQL
 database and simultaneously upload an image file (and store the path in
 the
 table).

 I have accomplished this with a product-based system (adding products and
 uploading images of the product), and accomplished what I needed because
 the
 product name was unique; I used the following statements:

 $prodName = $_POST['prodName'];
 $prodDesc = $_POST['prodDesc'];
 $prodPrice = $_POST['prodPrice'];

 $query2  = INSERT INTO product (pID, pName) VALUES (NULL, '$prodName');;
 $result2 = mysql_query($query2) or die(mysql_error());

 $query  = SELECT pID FROM product WHERE pName = '$prodName';;
 $result = mysql_query($query) or die(mysql_error());
 $row = mysql_fetch_array($result) or die (mysql_error());

 $prodID = $row['pID'];


 I had to select the new product to get the product id to use in the new
 unique image name.

 The problem I am facing now, is that with the shows that my users add will
 have multitple show times; this means non-unique titles. In fact, the only
 unique identifier is the show id. How can I insert something (leaving the
 show_id field NULL so that it is auto-assigned the next ID number), and
 then
 immediately select it?

 PHP doesn't seem to be able to immediately select something it has just
 inserted, perhaps it needs time to process the database update.

 Here is the code I have now (which does not work):

 $query2  = INSERT INTO afy_show (show_id, show_title, show_day_w,
 show_month, show_day_m, show_year, show_time, show_price,
 show_description,
 show_comments_1, show_seats_reqd) VALUES (NULL, '{$show_title}',
 '{$show_day_w}', '{$show_month}', '{$show_day_m}', '{$show_year}',
 '{$show_time}', '{$show_price}', '{$show_description}',
 '{$show_comments_1}', '{$show_seats_reqd}');;
  $result2 = mysql_query($query2) or die(mysql_error());

  $query3 = SELECT * FROM afy_show WHERE *show_id = '$id'*;;
  $result3 = mysql_query($query3) or die('Record cannot be located!' .
 mysql_error());
  $row3 = mysql_fetch_array($result3);
  $show_id = $row3['show_id'];

 How do I select the item I just inserted to obtain the ID number??


 mysql_insert_id http://ar.php.net/manual/en/function.mysql-insert-id.php
 mysqli-insert_id http://ar.php.net/manual/en/mysqli.insert-id.php


 --
 Martin Scotta



Re: [PHP] PHP Insert Data Form

2003-01-01 Thread Michael J. Pawlowsky


Here's what I suggest.  go to http://www.vtwebwizard.com/tutorials/mysql/

This guys has a really nice tutorial along with a nice class for MySQL that makes 
inserting data nice and easy.

Cheers,
Mike







*** REPLY SEPARATOR  ***

On 01/01/2003 at 11:35 PM Edson Waite wrote:

Hi All,

Hope everyone had a safe and happy New Year, I am still having trouble
getting an insert data form to work. Below is the code. I was also
wondering
if anyone could tell me the PHP Configuration settings necessary to allow a
form to insert data into a MySQL database.

To view this page, http://www.airforcemuseum.com/newentry.htm


Thanks in advance,
Ed Waite




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




Re: [PHP] [php] INSERT INTO

2002-12-17 Thread Jason Wong
On Tuesday 17 December 2002 15:12, John Taylor-Johnston wrote:

 I'm particularily concerned aboute single quotes. How do I escape them?
 Should I?

 Here is what I think is right.

 --snip--
 $myconnection = mysql_connect($server,$user,$pass);
 mysql_select_db($db,$myconnection);

 $query = INSERT INTO testals VALUES (addslashes($part1),
 addslashes($part2), addslashes($part3), addslashes($part4));;

Functions inside a string would have no effect. Do this instead:

  $part1 = addslashes($part1); 
  ...
  ...
  $query = INSERT INTO testals VALUES ($part1,...

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
I'm sitting on my SPEED QUEEN ... To me, it's ENJOYABLE ... I'm WARM
... I'm VIBRATORY ...
*/


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




Re: [PHP] [php] INSERT INTO

2002-12-17 Thread Marek Kilimajer
For 40 variables I would recomend keeping them in a single array and 
then loop the array:

$vars['part1']='something';
$vars['part2']='something else';

foreach($vars as k = $v) {
   $vars[$k]=addslashes($v);
}


John Taylor-Johnston wrote:

Yes I'm reading the FM :) http://www.php.net/manual/en/ref.mysql.php

I should know this. How will I PHP this SQL into my MySQL table?

INSERT INTO testals VALUES ($part1, $part2, $part3, $part4);

I'm particularily concerned aboute single quotes. How do I escape them? Should I?

Here is what I think is right.

--snip--
$myconnection = mysql_connect($server,$user,$pass);
mysql_select_db($db,$myconnection);

$query = INSERT INTO testals VALUES (addslashes($part1), addslashes($part2), addslashes($part3), addslashes($part4));;

mysql_query($query);

mysql_close($myconnection);
--snip--

That's it, right? I have about 40 variables. I wanted to run the code through here before I start.

Thanks,
John


 



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