On a previous thread, a member was nice enough to help me out. The script worked fine, until I added other variables. Now, it won't register in the database. My eyes are not working. Any ninjas? Thanks

reg.php

<?php

require( 'config.php' );

$con = mysql_connect( $mySQLhost,$mySQLuser,$mySQLpass ) or die( 'Error: ' . mysql_error() );
mysql_select_db( $mySQLdb );

$error = 0;

if ( isset( $_POST['submit'] ) ) {
	array_map( 'mysql_real_escape_string',$_POST ); //Protects against SQL injection
	foreach( $_POST as $key => $value ) {
		if ( $value == '' ) {
			$error++;
		}
		${$key} = $value;
	}
	if ( $error > 0 ) {
		echo "One or more fields are missing information";
	}
	elseif ( $error == 0 ) {
		$sql   = "INSERT INTO {$mySQLtable} ('first','last','age','city','state','fifteen','fifteenl','fifteend','mile','milel','miled','fivek','fivekl','fivekd','tenk','tenkl','tenkd','half','halfl','halfd','full','fulll','fulld') VALUES ('{$first}','{$last}','{$age}','{$city}','{$state}','{$fifteen}','{$fifteenl}','{$fifteend}','{$mile}','{$milel}','{$miled}','{$fivek}','{$fivekl}','{$fivekd}','{$tenk}','{$tenkl}','{$tenkd}','{$half}','{$halfl}','{$halfd}','{$full}','{$fulll}','{$fulld}')";
		$query = mysql_query( $sql,$con );
		if ( $query ) {
			echo $regSuccess;
		}
		else {
			echo $regFailed;
		}
	}
}

echo '<p><a href="' . $pathList . '">View current list of participants</a></p>';

mysql_close( $con );

?>

index.php

<table>
	<tr>
	 <td><label for="event" id="event" style="font-size:28px;padding-right:5px">1500m:</label><br /></td>
	 <td><label for="txtdistance">TIME:</label><br /><input type="text" name="fifteen" title="" id="time" size="5" class='input-text' /></td>
	 <td><label for="txttime">LOCATION:</label><br /><input type="text" name="fifteenl" title="" id="fifteenl" size="5" class='input-text' /></td>
	 <td><label for="txtlocation">DATE:</label><br /><input type="text" name="fifteend" title="" id="fifteend" size="5" class='input-text' /></td>
	</tr>



	<tr>
	 <td><label for="event" id="event" style="font-size:28px;padding-right:5px">Mile:</label><br /></td>
	 <td><label for="txtdistance">TIME:</label><br /><input type="text" name="mile" title="" id="time" size="5" class='input-text' /></td>
	 <td><label for="txttime">LOCATION:</label><br /><input type="text" name="milel" title="" id="milel" size="5" class='input-text' /></td>
	 <td><label for="txtlocation">DATE:</label><br /><input type="text" name="miled" title="" id="miled" size="5" class='input-text' /></td>
	</tr>



	<tr valign="top">
	 <td><label for="event" id="event" style="font-size:28px;padding-right:5px">5k:</label><br /></td>
	 <td><label for="txtdistance">TIME:</label><br /><input type="text" name="fivek" title="" id="time" size="5" class='input-text' /></td>
	 <td><label for="txttime">LOCATION:</label><br /><input type="text" name="fivekl" title="" id="fivekl" size="5" class='input-text' /></td>
	 <td><label for="txtlocation">DATE:</label><br /><input type="text" name="fivekd" title="" id="fivekd" size="5" class='input-text' /></td>
	</tr>



	<tr>
	 <td><label for="event" id="event"style="font-size:28px;padding-right:5px">10k:</label><br /></td>
	 <td><label for="txtdistance">TIME:</label><br /><input type="text" name="tenk" title="" id="time" size="5" class='input-text' /></td>
	 <td><label for="txttime">LOCATION:</label><br /><input type="text" name="tenkl" title="" id="tenkl" size="5" class='input-text' /></td>
	 <td><label for="txtlocation">DATE:</label><br /><input type="text" name="tenkd" title="" id="tenkd" size="5" class='input-text' /></td>
	</tr>



	<tr>
	 <td><label for="event" id="event" style="font-size:28px;padding-right:5px">13.1:</label><br /></td>
	 <td><label for="txtdistance">TIME:</label><br /><input type="text" name="half" title="" id="time" size="5" class='input-text' /></td>
	 <td><label for="txttime">LOCATION:</label><br /><input type="text" name="halfl" title="" id="halfl" size="5" class='input-text' /></td>
	 <td><label for="txtlocation">DATE:</label><br /><input type="text" name="halfd" title="" id="halfd" size="5" class='input-text' /></td>
	</tr>



	<tr>
	 <td><label for="event" id="event" style="font-size:28px;padding-right:5px">26.2:</label><br /></td>
	 <td><label for="txtdistance">TIME:</label><br /><input type="text" name="full" title="" id="time" size="5" class='input-text' /></td>
	 <td><label for="txttime">LOCATION:</label><br /><input type="text" name="fulll" title="" id="fulll" size="5" class='input-text' /></td>
	 <td><label for="txtlocation">DATE:</label><br /><input type="text" name="fulld" title="" id="fulld" size="5" class='input-text' /></td>
	</tr>
</table>

I tried to make the table better organized. emphasis on "tried".

Thanks

Recommended Answers

All 11 Replies

What is the error it is throwing at you? If it is giving a syntax error it will give the problem and the line number.

yeah, i never tested it. should of mentioned that. let me know the error and i will tell you whats wrong.

also the sql query will fail. when a pasted into daniweb they changed the ` signs of the field names somehow.

i don't see anything wrong with it, but i can't be sure. make sure something is not wrong in the config.php as well.

I think you're code was good. It just won't upload to the database. The only error I get is the "Registration Failed" error that I've scripted in the $regFailed

I noticed those weird quotations, so I changed them, where I could see them. It's kind of subtle.

the weird quotation are necessary. this will make it so the query doesn't fail. replace them and it should be good.

i wouldn't of types those if they weren't needed.

If you have magic_quotes on, make sure you strip slashes before running the mysql_real_escape_string on your $_POST vars

whoops. I'll change them and let you know. thanks

Well, I changed the code as you suggested. Everything looks good, and everything is registering in the database -- EXCEPT the DATE field. However, on the first entry (fifteen, fifteenl, fifteend), everything registers, including the date. The date field does not register on any of the other entries. I can't find why. It looks correct to me, but what do I know:

reg.php

<?php

require( 'config.php' );

$con = mysql_connect( $mySQLhost,$mySQLuser,$mySQLpass ) or die( 'Error: ' . mysql_error() );
mysql_select_db( $mySQLdb );

// Remove HTML-tags and unnecessary spaces
$first = rtrim(ltrim(strip_tags($first)));
$last = rtrim(ltrim(strip_tags($last)));
$age = rtrim(ltrim(strip_tags($age)));
$city = rtrim(ltrim(strip_tags($city)));
$state = rtrim(ltrim(strip_tags($state)));

$fifteen = rtrim(ltrim(strip_tags($fifteen)));
$fifteenl = rtrim(ltrim(strip_tags($fifteenl)));
$fifteend = rtrim(ltrim(strip_tags($fifteend)));

$mile = rtrim(ltrim(strip_tags($mile)));
$milel = rtrim(ltrim(strip_tags($milel)));
$miled = rtrim(ltrim(strip_tags($miled)));

$fivek = rtrim(ltrim(strip_tags($fivek)));
$fivekl = rtrim(ltrim(strip_tags($fivekl)));
$fivekd = rtrim(ltrim(strip_tags($fivekd)));

$tenk = rtrim(ltrim(strip_tags($tenk)));
$tenkl = rtrim(ltrim(strip_tags($tenkl)));
$tenkd = rtrim(ltrim(strip_tags($tenkd)));

$half = rtrim(ltrim(strip_tags($half)));
$halfl = rtrim(ltrim(strip_tags($halfl)));
$halfd = rtrim(ltrim(strip_tags($halfd)));

$full = rtrim(ltrim(strip_tags($full)));
$fulll = rtrim(ltrim(strip_tags($fulll)));
$fulld = rtrim(ltrim(strip_tags($fulld)));


$error = 0;

if ( isset( $_POST['submit'] ) ) {
	array_map( 'mysql_real_escape_string',$_POST ); //Protects against SQL injection
	foreach( $_POST as $key => $value ) {
		if ( $value == '' ) {
			$error++;
		}
		${$key} = $value;
	}
	if ( $error > 0 ) {
		echo "One or more fields are missing information";
	}
	elseif ( $error == 0 ) {
		$sql   = "INSERT INTO {$mySQLtable} (`first`,`last`,`age`,`city`,`state`,`fifteen`,`fifteenl`,`fifteend`,`mile`,`milel`,`miled`,`fivek`,`fivekl`,`fivekd`,`tenk`,`tenkl`,`tenkd`,`half`,`halfl`,`halfd`,`full`,`fulll`,`fulld`) VALUES ('{$first}','{$last}','{$age}','{$city}','{$state}','{$fifteen}','{$fifteenl}','{$fifteend}','{$mile}','{$milel}','{$miled}','{$fivek}','{$fivekl}','{$fivekd}','{$tenk}','{$tenkl}','{$tenkd}','{$half}','{$halfl}','{$halfd}','{$full}','{$fulll}','{$fulld}')";
		$query = mysql_query( $sql,$con );
		if ( $query ) {
			echo $regSuccess;
		}
		else {
			echo $regFailed;
		}
	}
}

echo '<p><a href="' . $pathList . '">View current list of participants</a></p>';

mysql_close( $con );

?>

I highlighted what isn't registering in the database.

Thanks! I'm almost there!

for some reason it didn't highlight, but it is all the fields with 'd' after them. Except 'fifteend' - that one works.

What column types are you using in your database for the dates?

If you're using date/datetime, make sure you are inputting the same format as your database columns (generally YYYY-MM-DD).

Also try this mysql_query to make sure it's inserting ok:

$query = mysql_query( $sql,$con ) or die (mysql_error());

The first date, fifteend, is entering fine. And every other field is fine as well. Except all the other date fields, like: miled, fivekd, tenkd, halfd, fulld. don't know why the first date field is registering while the rest don't. I've looked through the syntax pretty carefully.

The error had to do with how I was entering the date. In phpmyadmin, for the date that was working, I had it listed as VARCHAR and not date, hence the reason why when I entered 02/22/1988 it worked. the other fields were entered as date, which is set up to be entered like this: 1988/22/12 - so problem solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.