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
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')");

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.