-1
I don’t have much knowledge in PHP and I have a form where the user has some fields to fill and write in the SQL database, and a field of this form will be dynamic where the user can add as many fields as necessary from a button "+".
So far it’s working. I’m entering the data as desired... But I want this data being entered, to be added to a specific customer....
The system looks like this: 1 - Customer registration page 2 - Insert a service intended for this registered customer... I will insert this service after the customer is registered later....
I want is exactly what is happening with this forum... This question is related to my login and ID (Probably)...
I made a test system Minis to solve only this prolema with few fields: index php.
- jsFiddle demo Add$(window). load(Function(){ $(Function(){ //Create a function to Create Name and Phone fields Function createDivFields(num){ /* We create the variable, and assign the fields that will be created; We use square brackets in the field names to inform that the data in the form of an array; Add a div to create new extra fields; And a link to call the add event; */ var html = '; html += 'Course : '; html += 'Institutes u00e7 u00e3o: '; html += 'Load Hor u00e1ria : '; /*html += 'Add Phone';*/ html += '''; html += '''; Return html; } //Create function to add extra phone fields Function createFieldTel(num){ /* Note that you are informed that you will have a parameter; It will be through him we will identify from whom these fields belong; */ var tel = ' Telephone :'; tel += ''; tel += '
'; Return tel; } //creates a function to account for the fields created Function getTotalItems(){ //We count the total number of fields, and decrease 1 //Because the array starts its Intel with 0 Return $(".items"). length; } //Add name and phone $("#add"). click(Function(){ //Added at the end of element ( #boxFields) fields var totalField = getTotalItems(); $("#boxFields"). append(createDivFields(totalField)); Return false; }); //Add the extra fields $(". addTel"). live('click', Function(){ /* We use Live to assign the click event to the addTel link That’s because how we dynamically create this element he is not yet in the DOM, when the jQuery will perform */ //regains the position var position = $(this). attr('data-id'); //We return an element (Parent); //and then search . item, stating that it needs to be the first found //Add new fields at the end of the element (.item) $(this). Parent(). Children('.item:first'). append(createFieldTel(position)); Return false; }); }); });//]]>
form2.php
include 'connection.php'; $course = $_POST['course']; $local = $_POST['local']; $ch = $_POST['ch'];
$size = Count($stroke)-1; for ($f = 0; $f <= $size; $f++) {
$sql = "INSERT INTO test (course,location,ch) VALUES ('".$course[$f]."', '".$local[$f]."', '".$ch[$f]."')" or die ("
Problems when selecting the system database: ". mysqli_error() . "" );
$usuario_conect = mysqli_query($connect, $sql);
echo "$curso[$f] - $local[$f] - $ch[$f]
";} $registered = mysqli_affected_rows();
echo 'Registered users: ' . $registered;
mysqli_close ($usuario_conect);
Database Test bench
Client table id, name, service
service table id_servico, servico, ch
So, I need to connect the services that are entered to the customer for each service... Knowing that all this information is dynamically inserted via form... THERE IS NO AMOUNT OF PRE-DEFINIDOS SERVICES, they want to have the freedom to enter as many services as necessary and call each customer to the requested service... I hope you help me... kkkkk
This is my comrade... That’s about it... I do the JAVASCRIPT POST with all the values in an ARRAY... The problem is this: When I preview the customer I want all the services added to that customer.... How am I going to do this in the database? Am I going to insert a new table for each service? How am I going to retrieve this data in the MYSQL database ? These are my doubts... Got it ?
– Iso0406
In such cases I use a link table, In this case I would have Customer Ids and Service Ids, both fields are primary keys. Ex (This is SQL server but should be similar in Mysql):
Select * from Clientes C
left join Clientes_Servicos CS on C.ID=CS.ID_Cliente
left join Servicos S on CS.ID_Servico=S.ID
– CFG
Thanks brother for the help..... In fact I will do just that... A table that connects services to customers... hugs
– Iso0406