Form not submitting to database?

Hello All,

I’m trying to write an online form for a local football (soccer) team which goes through the starting line-up and puts all the data saved row-by-row into a mysql database. However, my data is not being saved in the database and I can’t work out why - anyone help please:


<?

if(isset($_REQUEST['Submit']))
{

$report_id = $_GET['report_id'];
$currentSeason = $_GET['currentSeason'];

foreach($_REQUEST['r'] as $position => $row) 
    
  {   $row = implode("', '",$row);
      $result = mysql_query("Insert into player_stats (position,shirt_number,player_id,goals,cards,substituted,used_sub,injury,season,report_id)   
                             values('$position','$row','$currentSeason','$report_id')");
  }

header("Location: ../menu.php");

} //End of POST submit

?>


<form id="form1" name="form1" method="post" action="">

<B>GOALKEEPER</B>
<p><input name="r[Goalkeeper][shirt_number]" type="text" value="1" size="2" /></p>
<p><input name="r[Goalkeeper][player_id]" type="text" value="1" size="2" /></p>
<p><input name="r[Goalkeeper][goals]" type="text" size="2" /></p>
<p><input name="r[Goalkeeper][cards]" type="text" size="2" /></p>
<p><input name="r[Goalkeeper][substituted]" type="text" size="2" /></p>
<p><input type="hidden" name="r[Goalkeeper][used_sub]" value="1" /></p>
<p><input name="r[Goalkeeper][injury]" type="text" size="2" /></p>

<B>PLAYER TWO</B>
<p><input name="r[Player Two][shirt_number]" type="text" value="1" size="2" /></p>
<p><input name="r[Player Two][player_id]" type="text" value="1" size="2" /></p>
<p><input name="r[Player Two][goals]" type="text" size="2" /></p>
<p><input name="r[Player Two][cards]" type="text" size="2" /></p>
<p><input name="r[Player Two][substituted]" type="text" size="2" /></p>
<p><input type="hidden" name="r[Player Two][used_sub]" value="1" /></p>
<p><input name="r[Player Two][injury]" type="text" size="2" /></p>

<button type="submit" name="Submit" value="Submit">Submit Data</button>

</form>


Where are you sending the $_GET variables?
if you echo out the query you get:

Insert into player_stats (position,shirt_number,player_id,goals,cards,substituted,used_sub,injury,season,report_id) values(‘Player Two’,‘1’, ‘1’, ‘3’, ‘54’, ‘55’, ‘1’, ‘6’,‘’,‘’)

so the last 2 fields are still blank as the $_GET variables arent being sent.

Echo your query and see what you get.

Thanks Spike,

Yep, I tried adding or die(mysql_error()); but I get no error message back when I hit submit which is very annoying!

I don’t get why I am missing two fields though:

position,shirt_number,player_id,goals,cards,substituted,used_sub,injury
// All held in $row which I explode on


season,report_id
//Grabbed from my $_GET values in the script
//$report_id = $_GET['report_id']; 
//$currentSeason = $_GET['currentSeason']; 

It’s almost like i’m hitting submit and my form is ignoring the foreach where it inserts the data in the database as I don’t even get a MYSQL error as mentioned earlier when I add or die(mysql_error) ?

Any other thoughts greatly welcome again?

Thanks

You have more fields stated in your query than you do submitted form fields.
You have:


(position,shirt_number,player_id,goals,cards,substituted,used_sub,injury,season,report_id)

but miss the last 2 fields when inserting


'$position','$row','$currentSeason','$report_id'

if you add 'or die(mysql_error()) to the end of the query line it would probably say something like ‘field count worng’;


$result = mysql_query("Insert into player_stats (position,shirt_number,player_id,goals,cards,substituted,used_sub,injury,season,report_id)   

                             values('$position','$row','$currentSeason','$report_id')") or die(mysql_error());

  }


Hi,

Thanks for your help. I get the $_GET values from the URL string, so for example it could read:

file.php?report_id=12&currentSeason=1011

However I don’t think it’s anything to do with the query, I just think that for some reason my form never processes the query for example within my code i’ve asked it to print “I AM A MONKEY” when I hit submit and it never prints it.

I can even change the table name and when I hit submit I get no errors, so for some reason which I can’t see my foreach loop is being ignored it seems


<? 

if(isset($_REQUEST['Submit'])) 
{ 

$report_id = $_GET['report_id']; 
$currentSeason = $_GET['currentSeason']; 

foreach($_REQUEST['r'] as $position => $row) 

{ 
$row = implode("', '",$row); 
$result = mysql_query("Insert into a_table_that_does_not_exist(position,shirt_number,player_id,goals,cards,substituted,used_sub,injury,season,report_id) 
values('$position','$row','$currentSeason','$report_id')"); 
echo "I am a Monkey";
} 

header("Location: ../menu.php"); 

} //End of POST submit 

?> 

All to do with a scipt I put into my system with regards to mysql_real_escape_string. As soon as I saw the error message I knew exactly what it was, but not seeing the error was the problem. Thanks for your help :tup:

lol what was the error?

Aha, got it. Error reporting not turned on for the server - doh! Thanks