If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Basic insertion in the database.

Hi,

i have a registration form (screenshot attached). I create two table to store them, one customer_master, send item_details. but i want to know how to get values of these (item) textboxes to insert into the database.
Here is the code by which these fields are generating.

Before you go further, find another MySQL interface since the MySQL_* functions are about to be removed. Look to see if your host supports either mysqli or pdo for database access.

As it stands now, you need to change from using a function that retrieves just one value at a time to one that retrieves a whole record with one call. Much more efficient that way. Once you learn how to do that then you use a loop to cycle thru each record and ouput a table row with the current row's values.

You need to re-think your goal here and what you want to do. As it stands you are putting your whole table of data on-screen and then allowing the user to change any record, any field. You have no form tag and no submit button so how do you send those changes back to php? When I have done that, I create a form for each table row and add a submit button to each. Then my php has everything it needs to identify the row to be updated and all the data.

Hi ginerjm,
Showing data is not a concern for me,
i want to insert these data after taking values of these 29 fields/rows , and the rest 4 blank rows are for additional data that may be fill if necessary and will go with these 25 rows into the database table.

If I understand, you want to display the contents of your table and then allow for the adding of additional records. If you are not allowing for updates to the data, then I would not use input tags for the existing data, only for the blank row that you will use to add a record.

As for adding recs, place a 'submit' button at the end of each blank record on the display so that you can recognize and insert the data correctly. Here's how I would create the 'blank' rows:

To process this one would check for a $_POST['submit'] with a value of "Add New Record" and if found, check for it's id value and extract the number at the end of it and then grab the name= values that end with the number.
Of course if you only did one blank row at a time, then you would not need to do that.

hi,
I change my code accordingly but this show error, going to else part
here is my code..
<?php
require_once("config.php");
$query_for_result=mysqli_query($con,"SELECT * FROM items ORDER BY id ASC");
$num=mysqli_num_rows($query_for_result);
mysqli_close($con);

Anyway - you say you have an error . What is the error message please? Could it have anything to do with the fact that you layout a page and then start checking for input while the user hasn't seen it yet?