I just want to ask if it is possible to create variables on a php file so that the new input fields that I will create using a Content Management System (CMS) will have it’s data stored on that new variables so I can query all those data to the database. (I’m sorry I’m so bad at explaining).
For example, I have this 4 Input Fields which has its own variable to house their data; Lastname, Firstname, Middlename, and Phone Number
sample code:
<div class="box-divide"> <b>Lastname:</b> <input type="text" name="last_name" id="ln" placeholder="Lastname" required> </div> <div class="box-divide"> <b>Firstname:</b> <input type="text" name="first_name" id="fn" placeholder="Firstname" required> </div> <div class="box-divide"> <b>Middlename:</b> <input type="text" name="middle_name" id="mn" placeholder="Middlename" required> </div> <div class="box-divide"> <b>Phone Number:</b> <input type="tel" name="phoneNum" id="pn" value="" placeholder="+639123456789" maxlength="13" required> </div>
and I add this php codes to print new input fields:
<?php //Select All Items for new Field $sqlFD = "SELECT * FROM app_fields_lists"; $resFD = mysqli_query($conn, $sqlFD); if (mysqli_num_rows($resFD) > 0) { while ($rowFD = mysqli_fetch_assoc($resFD)) { $idFD = $rowFD['id']; $field_name = $rowFD['field_name']; $uCapAFA = strtolower($field_name); // TO LOWER CASE STRING $uCapAFA = str_replace(" ", "_", $uCapAFA); // REPLACE SPACE TO UNDERSCORE "_" TO CREATE/ADD TABLE COLUMN ?> <div class="box-divide"> <b><?php echo $field_name ?>:</b> <input type="text" name="<?php echo $uCapAFA ?>" id="<?php echo $uCapAFA ?>" value="" placeholder="<?php echo $uCapAFA ?>" required> </div> <?php } } ?>
All are successful on the CMS part. I’m sorry I can’t show you guys the codes on the CMS part. I was able to alter the table I want to add the new input fields to. And can also delete/drop columns when I delete a column.
All was going fine but now I’m stuck. I can’t think of a doable solution on this problem. Was thinking of using loop too but I don’t know what follows after making the first part.
This all seems like a real headache, but I don’t have anyone to ask about this, that’s why I’m trying to push my luck in here. Thanks in advance!
Advertisement
Answer
I know this feeling all to well.
“This all seems like a real headache, but I don’t have anyone to ask about this, that’s why I’m trying to push my luck in here. Thanks in advance!”
I re-read your question twice and it boggles me: So to my understanding:
- You have a form with inputs (generated statically ?)
- When the user inputs data you store it in the db.
- Then you re-create the form using PHP ?
What happens to the page when the user inputs the data ?
- Does it refresh ?
- Does The form push to the db ?
- Why do you need to re-generate the form using PHP ?
Have you tried using ajax in the mix between the form and user inputs ?
EG: User Form -> User Inputs Data (Submits Form) -> ajax handles the posting to the php file -> let ajax wait for a response from php on success -> refresh the page using jquery.
That would automatically do the same thing over and over for every user that submits the form.
On another note you should switch to PDO as mysqli is not secure at all if you do not escape queries correctly.
Going to need a little bit more of the logic as it seems that you might have over complicated a simple process which is completely fine as it happens from time to time