Jump to content

Form Processing Problem


DannGrant

Recommended Posts

Hi,

 

I'm developing a website for a Golf Society and am currently looking for a way to manage golf courses.

 

I have done this by creating two tables within my database:

 

courses: containing the fields (course_id, name, total_par)

 

and then

 

holes: containing the fields (hole_id, course_id, hole_number, par, stroke_index, yardage)

 

as each course contains 18 holes i have a form with 18 rows making the user enter the values for each hole

 

i'm having trouble working out how to process the form as i don't have much experience with loops or anything else and am hoping somebody can help me.

 

when the user clicks submit the form needs to submit each row to the holes table.

 

thanks in advance.

 

:)

 

Link to comment
https://forums.phpfreaks.com/topic/193465-form-processing-problem/
Share on other sites

I'm assuming you have a form with multiple rows of values for these fields?:

hole_id, course_id, hole_number, par, stroke_index, yardage

 

And you want each one to go in as a new row in the DB table.

You could execute a new insert query for each one? That would be the easy way.

$query = "insert first hole values";

execute

$query = "insert second hole values";

execute

And so on...

 

Or something like this...

$myarray[] = "$hole_id, $course_id, $hole_number, $par, $stroke_index, $yardage";

$myarray[] = "$hole_id2, $course_id2, $hole_number2, $par2, $stroke_index2, $yardage2";

$myarray[] = "$hole_id3, $course_id3, $hole_number3, $par3, $stroke_index3, $yardage3";

for each hole...

 

foreach($myarray as $x){

  $myrow = explode(",",$x);

  $query = "INSERT INTO mytable (hole_id, course_id, hole_number, par, stroke_index, yardage) values "

      ."('$myrow[0]', '$myrow[1]', '$myrow[2]', '$myrow[3]', '$myrow[4]', '$myrow[5]')";

  execute query

}

Archived

This topic is now archived and is closed to further replies.

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