Jump to content

[SOLVED] Query / Post Help


hossfly007

Recommended Posts

I am trying to create a loop to insert data into my database and i am needing alittle help:

 

$players = "{$_POST['players']}";
$j=1;

while($j<=$players) 
{
$query = "INSERT INTO sl_data VALUES (
'0', 
'{$_POST['name$j']}',
'{$_POST['date$j']}',
'{$_POST['rank$j']}',
'{$_POST['oscore$j']}',
'{$_POST['nscore$j']}',
'{$_POST['ohand$j']}',
'{$_POST['nhand$j']}',
'{$_POST['points$j']}',)";
$j++; 
$text .= "$query"; 
}

 

The issue i am having is the $j will not show up as a number when i load the page. it just shows this:

 

INSERT INTO sl_data VALUES ( '0', '', '', '', '', '', '', '', '', )
INSERT INTO sl_data VALUES ( '0', '', '', '', '', '', '', '', '', )

 

I am thinking that {$_POST['name$j']} will not work. But i have no idea how to put a variable in a variable.    Any ideas? Thanks for the help!!

 

Just for reference here is my form:

 

$text .= "<form action='sl_submit.php?action=step3' method='post'>";

$players = "{$_POST['players']}";
$i=1;
while($i<=$players) 
{ $text .= "
<tr>
<td><input type='text' name='rank$i' size='20' class='tbox'></td>
<td><input type='text' name='name$i' size='20' class='tbox'></td>
<td><input type='text' name='ohand$i' size='20' class='tbox'></td>
<td><input type='text' name='oscore$i' size='20' class='tbox'></td>
<td><input type='text' name='nhand$i' size='20' class='tbox'></td>
<td><input type='text' name='nscore$i' size='20' class='tbox'></td>
<td><input type='text' name='points$i' size='20' class='tbox'></td>
</tr>"; $i++; } 
$text .= "
<tr><td>
<input type='hidden' name='players' value='{$_POST['players']}'>
<input type='hidden' name='date' value='{$_POST['date']}'>
<input type='hidden' name='location' value='{$_POST['location']}'>
<input type='submit' value='Submit' class='tbox'></td></tr></table></form>";

 

 

Link to comment
Share on other sites

I am trying to add information into a database without adding the information one at a time.

 

Ex. - This is being used for a singles league, Where you have to input the rank, players name, handicap, old handicap, score, adjusted score, points.

 

If 20 players come one day that's 20 single queries i would have to do. I am trying to just do all of it at one time. Create a form (the while statement) to create as many inputs as there are players. and then submit all of the information in one loop.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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