Jump to content

[SOLVED] Just when you think you have it licked


TimUSA

Recommended Posts

sorry for all the questions here, but this is not submitting any information to the DB at all...

if (isset($_POST['Submit'])) {
mysql_real_escape_string($_POST['series']);
$seriesresult = mysql_query("
SELECT seriesID
FROM series_table
WHERE seriesName = '{$_POST['series']}'
");
while ($row = mysql_fetch_row($seriesresult)){
$seriesID = $row[0];
mysql_real_escape_string($_POST['date']);
mysql_real_escape_string($_POST['host']);
mysql_real_escape_string($_POST['factor']);
mysql_real_escape_string($_POST['boats']);
mysql_query("
INSERT INTO race_table (raceDate, hostName, factor, boatsInRace, seriesID) 
VALUES ('{$_POST['date']}', '{$_POST['host']}', '{$_POST['factor']}', '{$_POST['boats']}', '{$seriesID}')");
}

//Get the ID of the last race entered.
$query="SELECT raceID FROM race_table";
$result=mysql_query($query);
$raceID=mysql_insert_id($result);

//enter information to the race_screenshots_table
mysql_real_escape_string($_POST['image']);
mysql_query("
INSERT INTO race_screenshots_table (imageURL, raceID)
VALUES ('{$_POST['image']}', '{$raceID}')");

//enter information to the pts_table
$times = $_POST['boats'];
$x = 0;
while ($x < $times) {
mysql_real_escape_string($_POST['name'][$x]);
mysql_real_escape_string($_POST['position'][$x]);
mysql_real_escape_string($_POST['points'][$x]);
mysql_real_escape_string($_POST['ladder'][$x]);
while ($_POST['factor'] == "2") {
mysql_query("
INSERT INTO pts_table (skipperName, position, racePoints, matchPoints, raceID)
VALUES ('{$_POST['name'][$x]}', '{$_POST['position'][$x]}', '{$_POST['points'][$x]}', '{$_POST['ladder'][$x]}', '{$raceID}')");
}
mysql_query("
INSERT INTO pts_table (skipperName, position, racePoints, fleetPoints, raceID)
VALUES ('{$_POST['name'][$x]}', '{$_POST['position'][$x]}', '{$_POST['points'][$x]}', '{$_POST['ladder'][$x]}', '{$raceID}')");
$x++;
}
}

Link to comment
Share on other sites

functions like mysql_real_escape_string in php simply return the escaped string, they don't assign it to certain variables like more object oriented languages do... you have to do that yourself

for example:

 

while ($row = mysql_fetch_row($seriesresult)){
   $seriesID = $row[0];
   $date = mysql_real_escape_string($_POST['date']);
   // ...
   mysql_query("INSERT INTO race_table (raceDate, hostName, factor, boatsInRace, seriesID) VALUES ($date" //...
}

Link to comment
Share on other sites

While were at it. Whats with all the loops? Also, this...

 

mysql_real_escape_string($_POST['date']);
mysql_real_escape_string($_POST['host']);
mysql_real_escape_string($_POST['factor']);
mysql_real_escape_string($_POST['boats']);

 

does nothing. You need to assign the result from mysql_real_escape_string() to a variable. eg;

 

$date = mysql_real_escape_string($_POST['date']);

 

I would do all that prior to any other logic as calling functions can be very inificient escpecially when within a loop. Basically your calling the smae function multiple times (once for each loop) when you dont need to.

Link to comment
Share on other sites

sorry about the indents. i am a noob and dont really know how to do it correctly. i will work on it and come back!

 

but just for the record...something like this?

$series = mysql_real_escape_string($_POST['series']);
$seriesresult = mysql_query("
SELECT seriesID
FROM series_table
WHERE seriesName = '{$series}'
");

Link to comment
Share on other sites

Done some cleanup and some indenting...still not working?

ok the form that submits is as follows:

<?
//////ENTRY PAGE 3//////

//////CONFIGURATION//////
global $scripturl;


//DISPLAY THE FORM
if (isset($_POST['submitted'])) 
{
echo'
<form action="'.$scripturl.'?page=18'.$GET['page'].'" method="post">
<INPUT id="submitted" name="Submit" type="hidden" value="TRUE" />';
//HOSTING INFORMATION
echo'
<hr style="width: 100%; height: 2px;" />
<h4>Hosting Information</h4>
        <hr style="width: 100%; height: 2px;" />';
	//Race Information From Page 2
	echo'
	<table>
	<tr>
	<td><p><b>Host :</b></P><input type="text" READONLY name="host" value="' . $_POST['host'] . '" /></td>
	<td><p><b>Date :</b></P><input type="text" READONLY name="date" value="' . $_POST['date'] . '" /></td>
	<td><p><b>Number of Boats :</b></P><input type="text" READONLY name="boats" value="' . $_POST['boats'] . '" /></td>
	<td><p><b>Race Series :</b></P><input type="text" READONLY name="series" value="' . $_POST['series'] . '" /></td>
	<td><p><b>Race Factor :</b></P><input type="text" READONLY name="factor" value="' . $_POST['factor'] . '" /></td>
	</tr>
	</table>';

//DISPLAY SCREENSHOT
echo'
        <hr style="width: 100%; height: 2px;" />	
        <img width="640" height="480" src="' . $_POST['image'] . '" alt="" />
<tr><td>
<p><b>Image Address: </b></P>
<input type="text" READONLY name="image" style="WIDTH: 800px" value="' . $_POST['image'] . '" />
</td></tr>
</table>';

//DISPLAY RESULTS
echo'
<hr style="width: 100%; height: 2px;" />
<h4>CONFIRM RESULTS</h4>
<hr style="width: 100%; height: 2px;" />';


//ladder calculation


	//Setup Loop
	$times = $_POST['boats'];
	$x = 0;

	while ($x < $times) 
	{
	//points calculation		
		while ($_POST['position'][$x] == "DNF") 
		{
		$_POST['position'][$x] = $_POST['boats'] + 1;
		$points = 50 - $_POST['position'][$x] - 6;	
		$comment = " - DNF";
		}

		while ($_POST['position'][$x] == "DNS") 
		{
		$_POST['position'][$x] = $_POST['boats'] + 1;
		$points = 50 - $_POST['position'][$x] - 6;	
		$comment = " - DNS";
		}

		if ($_POST['position'][$x] == "1")
		$points = 50;

		else if ($_POST['position'][$x] == "2")
		$points = 47;

		else if ($_POST['position'][$x] == "3")
		$points = 44.3;

		else if ($_POST['position'][$x] == "4")
		$points = 42;

		else if ($_POST['position'][$x] == "5")
		$points = 40;

		else if ($_POST['position'][$x] == "6")
		$points = 38.3;

		else 
		{
		$points = 50 - $_POST['position'][$x] - 6;
		}
		$ladder = $points * $_POST['factor'];
	echo'
	<table>
	<tr>
	<td><p>Skipper: </p><input type="text" READONLY name="name[ ]" value="' . $_POST['name'][$x] . '" /></td>
	<td><p>Finish Position: </p><input type="text" READONLY name="position[ ]" value="' . $_POST['position'][$x] . $comment . '" /></td>
	<td><p>Points This Race: </p><input type="text" READONLY name="points[ ]" value="' . $points . '" /></td>
	<td><p>Ladder Points: </p><input type="text" READONLY name="ladder[ ]" value="' . $ladder . '" /></td>
	</tr>
	</table>';
	$x++;
	}

//FINALLY SUBMIT
	echo'
	<hr style="width: 100%; height: 2px;" />
	<h4>Submit Results: </h4>
	<hr style="width: 100%; height: 2px;" />
	<table>
	<tr>
	<td><INPUT type="submit" value="Submit"><INPUT type="reset" value="Reset"></td>
	</tr>
	</table></form>';
}

 

and with some cleanup the previously posted code is:

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

$date = mysql_real_escape_string($_POST['date']);
$host = mysql_real_escape_string($_POST['host']);
$factor = mysql_real_escape_string($_POST['factor']);
$boats = mysql_real_escape_string($_POST['boats']);
$series = mysql_real_escape_string($_POST['series']);
$image = mysql_real_escape_string($_POST['image']);

$seriesresult = mysql_query("
SELECT seriesID
FROM series_table
WHERE seriesName = '$series'
");
	while ($row = mysql_fetch_row($seriesresult))
	{
	$seriesID = $row[0];
		mysql_query("
		INSERT INTO race_table (raceDate, hostName, factor, boatsInRace, seriesID) 
		VALUES ('$date', '$host', '$factor', '$boats', '$seriesID')");
	}

//Get the ID of the last race entered.
$query="SELECT raceID FROM race_table";
$result=mysql_query($query);
$raceID=mysql_insert_id($result);

//enter information to the race_screenshots_table
		mysql_query("
		INSERT INTO race_screenshots_table (imageURL, raceID)
		VALUES ('$image', '$raceID')");

//enter information to the pts_table
$times = $_POST['boats'];
$x = 0;
	while ($x < $times) 
	{
		$name = mysql_real_escape_string($_POST['name'][$x]);
		$position = mysql_real_escape_string($_POST['position'][$x]);
		$points = mysql_real_escape_string($_POST['points'][$x]);
		$ladder = mysql_real_escape_string($_POST['ladder'][$x]);
			if ($_POST['factor'] == "2") 
			{
				mysql_query("
				INSERT INTO pts_table (skipperName, position, racePoints, matchPoints, raceID)
				VALUES ('$name', '$position', '$points', '$ladder', '$raceID')");
			}
			else
				mysql_query("
				INSERT INTO pts_table (skipperName, position, racePoints, fleetPoints, raceID)
				VALUES ('$name', '$position', '$points', '$ladder', '{$raceID}')");
	$x++;
	}
}

 

Not sure whats not working here, but getting closer maybe

Link to comment
Share on other sites

start from the top of your problem code, try testing each piece little by little to identify the problem area

also echo out your inputs and outputs in your variables to make sure they are what you think they are

 

when posting php code in code bbtags you need to enclose the code in <?php ?> tags as well as the code blocks

 

ie:

bbcode

<?php

code

?>

bbcode

($10 says Tim Doesn't do this on his next post)

Link to comment
Share on other sites

ok stops working here:

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

$date = mysql_real_escape_string($_POST['date']);
$host = mysql_real_escape_string($_POST['host']);
$factor = mysql_real_escape_string($_POST['factor']);
$boats = mysql_real_escape_string($_POST['boats']);
$series = mysql_real_escape_string($_POST['series']);
$image = mysql_real_escape_string($_POST['image']);

$seriesresult = mysql_query("
SELECT seriesID
FROM series_table
WHERE seriesName = '$series'
");
	while ($row = mysql_fetch_row($seriesresult))
	{
	$seriesID = $row[0];
		mysql_query("
		INSERT INTO race_table (raceDate, hostName, factor, boatsInRace, seriesID) 
		VALUES ('$date', '$host', '$factor', '$boats', '$seriesID')");
	}

//////STOPS WORKING FROM HERE//////

//Get the ID of the last race entered.
$query="SELECT raceID FROM race_table";
$result=mysql_query($query);
$raceID=mysql_insert_id( );

echo $result;
}

 

$result echos Resource id #48

Link to comment
Share on other sites

$date = mysql_real_escape_string($_POST['date']);

$host = mysql_real_escape_string($_POST['host']);

$factor = mysql_real_escape_string($_POST['factor']);

$boats = mysql_real_escape_string($_POST['boats']);

$series = mysql_real_escape_string($_POST['series']);

$image = mysql_real_escape_string($_POST['image']);

 

$seriesresult = mysql_query("

SELECT seriesID

FROM series_table

WHERE seriesName = '$series'

");

$row = mysql_fetch_row($seriesresult);

$seriesID = $row[0];

mysql_query("

INSERT INTO race_table (raceDate, hostName, factor, boatsInRace, seriesID)

VALUES ('$date', '$host', '$factor', '$boats', '$seriesID')");

$raceID = mysql_insert_id();

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.