HTML Form is not adding data to MySQL database?

:bulb: ?

@SamA74 That comment I wrote was directed toward @benanamen not @droopsnoot

For example, what about if you want to print an address label with the member name at the beginning of it? You don’t want it to come out as you’re storing it, because it looks awful, so you have to write some code to split it by comma and re-order it. If it’s stored as separate fields for firstname and lastname, you can still sort by lastname if you need to, and you can easily output it in the “correct” order.

1 Like

True, but I still don’t understand how you obtain the ID from the members table to put it in the attendance table… I know I have to separate the name out and store the ID, but what can I do to get the user ID by search? Is this a matter of using a hidden form input or do I have to use Ajax and JS? If this has already been answered, show me where so I can try to make sense of it.

This line here:

echo "<p>" . $row['id'] . " -+- " . $row['name'] . "</p>";

means that your search is now returning two things, and will display two things in the drop-down list. So instead of the image you showed with “DOE, John” in the drop-down, you’ll see 1 -+- DOE, John in the list. Presumably your code then inserts that into the “name” form field.

When you submit the form, your $_POST['member_name'] field will contain 1 -+- DOE, John. The little code snippet I posted above shows you how to split that into an array of values. In this example, your var_dump() of that array would show something like

array(2) { [0]=> string(1) "1" [1]=> string(9) "DOE, John" }

So you can see that the member id is now in $ary[0], so that’s what you use to insert into the attendance table.

Normally I’d use a drop-down as the selection, so you’d have code like

<select name="member_name">
<option value="1">DOE, John</option>
<option value="2">ELLIS, John</option>
<option value="3">LENNON, John</option>
</select>

and when you pick a choice from the drop-down, you would get the value submitted rather than the text (if they’re different), which would do it easier for you. But you’re not using a drop-down.

1 Like

Ok. I think I got it working. Now I just need to figure out how to generate the report to show what I need.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.