Jump to content

How Can create insert function?


bashaclick

Recommended Posts

HI All,

I would like create query when I add some one is look what the last number in field and add one ?

 

example :

you can see the img in attach

IDT is primary key + auto increment

Customer_id is number field

customer _name is name

 

how can create this login

 

IDT    Customer_ID    Customer_name

112          5                    bbbb

113          6                    ccccc

114          7                    eeeee

 

Also I need the inster function and is look the last field in customer_ID and Increase one ( +1)

 

 

Any help PLZ/

 

THanks

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/232241-how-can-create-insert-function/
Share on other sites

HI All,

I would like create query when I add some one is look what the last number in field and add one ?

 

example :

you can see the img in attach

IDT is primary key + auto increment

Customer_id is number field

customer _name is name

 

how can create this login

 

IDT    Customer_ID    Customer_name

112          5                    bbbb

113          6                    ccccc

114          7                    eeeee

 

Also I need the inster function and is look the last field in customer_ID and Increase one ( +1)

 

 

Any help please/

 

THanks

 

Probably a better way of doing this then what I'm showing you....

 

Well you can do something like this:

 

$extract = mysql_query("SELECT customer_id FROM tablenamehere ORDER BY customer_id DESC");
$extract_e = mysql_fetch_assoc($extract);

mysql_insert("INSERT INTO tablenamehere VALUES (null, '". $extract_e['customer_id'] + 1 ."', '$customer_name')");

Thank you this my simple code

 mysql_connect("localhost", "root", "asdasd") or 
       die("Could not connect: " . mysql_error()); 
      mysql_select_db("attawy"); 
    $extract = mysql_query("SELECT customer_id FROM orders ORDER BY customer_id DESC");
$extract_e = mysql_fetch_assoc($extract);

   mysql_query("INSERT INTO orders (customers_id,customers_name) values ('". $extract_e['customer_id'] + 1 ."','kossu')"); 

 

and show me error

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

 

!!!

 

Any Idea

 

Thank

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.