jktress Posted May 2, 2006 Share Posted May 2, 2006 I am creating a fantasy formula 1 game. Sanfly helped me out, but I can't seem to get the right values inserted into my table. Instead, this code inserts blank rows into my table (20 or so of them) I can't seem to figure out the trouble.I select a race date and the variable is sent in the URL to race.php. Then I enter appropriate driver points into a table called driverPoints in a mySQL database. [code]<?php require_once('Connections/formula1.php');//select a database@mysql_select_db($database_formula1) or die( "Unable to select database"); //the query is set to a variable $q = "SELECT * FROM circuits ORDER BY race_date";//the result of the query is set to a variable$r = mysql_query($q) or die(mysql_error());//the fetch_array loop is looking through the results of my query and returning all the rows! It looks like it is storing them in two variables while($row = mysql_fetch_array($r)){ $race_name = $row['circuitName']; $race_id = $row['race_id']; $race_date = $row['race_date']; echo "$race_name - $race_date (<a href=\"races.php?action=addpoints&rid=$race_id\">Add Points</a>)<br>"; }?>[/code]Here is the form where I enter the points the drivers earned during the race. [code]<?php//get the race id and set it to a variable$rId = $_GET['rId'];//double check that you are coming from the post pageif($_GET['action'] = "addpoints" && $_GET['rId'] == $rId){ ?> <form method="post" action="races.php?action=addpoints2"> <table> <tr> <td>Driver name</td> <td>Points</td> </tr><? require('Connections/formula1.php');@mysql_select_db($database_formula1) or die( "Unable to select database");$q = "SELECT * FROM drivers"; $r = mysql_query($q) or die(mysql_error()); while($row = mysql_fetch_array($r)){ $driver_id = $row['driver_id']; $driver_name = $row['nameD']; ?> <tr> <td><?=$driver_name?> <input type="hidden" name="rp_driver[]" value="<?=$driver_id?>"></td> <td><input type="text" name="rp_points[]" size="10"></td> </tr> <? } ?> <tr> <td colspan="2"> <input type="hidden" name="rp_race" value="<?=$rId?>"> <input type="submit" value="Update the Points"> </td> </tr> </table> </form><?php }if($_GET['action'] = "addpoints2"){ // Get Posted Variables $rp_race = $_POST['rp_race']; $rp_driver = $_POST['rp_driver']; $rp_points = $_POST['rp_points']; $dp = array(); $dp['driver'] = $rp_driver; $dp['points'] = $rp_points; $num = count($dp); for($i = 0; $i < $num; $i ++){ $dp_driver = $dp['driver'][$i]; $dp_points = $dp['points'][$i]; require('Connections/formula1.php'); @mysql_select_db($database_formula1) or die( "Unable to select database"); $q = "INSERT INTO driverPoints (rp_race, rp_driver, rp_points) VALUES ('$rp_race', '$rp_driver', '$rp_points')"; $r = mysql_query($q) or die(mysql_error()); } echo "done, link to whatever here";}?>[/code]I have gone through the code a few times and still can't seem to figure out the problem. Any ideas? Link to comment https://forums.phpfreaks.com/topic/8866-still-some-trouble/ Share on other sites More sharing options...
sasa Posted May 2, 2006 Share Posted May 2, 2006 change lines[code]$num = count($dp);...$q = "INSERT INTO driverPoints (rp_race, rp_driver, rp_points) VALUES ('$rp_race', '$rp_driver', '$rp_points')";[/code]to[code]$num = count($rp_driver);...$q = "INSERT INTO driverPoints (rp_race, rp_driver, rp_points) VALUES ('$rp_race', '$dp_driver', '$dp_points')";[/code] Link to comment https://forums.phpfreaks.com/topic/8866-still-some-trouble/#findComment-32726 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.