Forum Moderators: coopster
Still quite new to php and just wrote this script for a webiste im writing for my local hockey team. The problem I have is that when you hit the submit button instead of printing the "the player has been updated" on the screen the browser goes to my index page.
What is annoying is I am running the same script for add a new team and this works fine I am a little bit confused and wonderded if anyone could help. The script does insert the data into my mysql database so there must be something going wrong between my isset submit part.
Also can anyone tell me the difference between print and echo statements.
Here is my script
<?
// Start Output Buffering
ob_start();
?>
<? session_start();?>
<snip>html head</snip>
<snip>login check and html text</snip>
<?
// Script for creating nascar diecast database also selects the database
if (isset ($_POST['submit'])) { // Handle The Form
$problem = FALSE;
// Check for each value.
if (empty ($_POST['team'])) {
$problem = TRUE;
print '<p><font color="red">Please enter a team name!</font></p>';
}
// Upload Kit
if (is_uploaded_file($_FILES['file']['tmp_name'])){
if (move_uploaded_file($_FILES['file']['tmp_name'], "../chc_uploads/{$_FILES['file']['name']}")) {
$problem = FALSE;
echo '<p align="center"><font color="red"><b>Player Image Was Uploaded</b></font></p>';
} else {
$problem = TRUE;
echo '<p>The file could not be moved because </p>';
$image = 'noimage.jpg' ;
}
$kit = $_FILES['file']['name'];
} else {
$image = 'noimage.jpg';
}
if (!$problem) { // If there is no problems
require_once ('../includes/connect.php'); // Define the Query
$query = "INSERT INTO players (player_id, team, name, pos, notes, photo) VALUES (0, '{$_POST['team']}' , '{$_POST['name']}', '{$_POST['pos']}', '{$_POST['notes']}', '$image')";
// Execute The Query
if (@mysql_query ($query)) {
print '<p align="center"><font color="red"><b>The entry has been added!</b></font></p>';
} else {
print '<p>Could Not add entry because: ' . mysql_error() . '
<p> the query being run was ' . $query . '</p>';
}
mysql_close(); //
}
}
// Display The Form
print' <form action="addaplayer.php" enctype="multipart/form-data" method="post">
<table width=100% cellpadding=5 cellspace=5 border=0>
<td valign="top">Current Team:</td>
<td valign="top">
<div align="left">
<select name="team">
<option value="1st XI"> </option>
<option value="2nd XI"> </option>
<option value="3rd XI"> </option>
<option value="4th XI"> </option>
<option value="Mickey mouse Team">The Owls</option>
<option value="Ladies 1st XI"> </option>
<option value="Ladies 2nd XI"> </option>
<option value="Colts"> </option>
</select>
</div>
</td>
</tr>
<td valign="top">Player Name:
<input type="text" name="name" size="35" />
</td>
<td valign="top">Position:
<select name="pos">
<option value="GK">Goalkeeper</option>
<option value="DF">Defence</option>
<option value="MD">Midfield</option>
<option value="AT">Attacker</option>
<option value="CO">Coach</option>
</select></td>
<td valign="top">Notes:<textarea name="notes" cols="25" rows="10"></textarea>
<input type="hidden" name="MAX_FILE_SIZE" value="50000" /></td>
<td valign="top">Player Photo: <input type="file" name="file" /></td>
<input type="submit" name="submit" value="Add This Player" />
<h4>PLEASE CLICK UPLOAD ONCE ONLY!</h4>
</form>';
?>
<snip>nested tables, html text</snip>
<?
ob_end_flush();
?>
Many Thanks
What a great website as well top!
[edited by: ergophobe at 6:07 pm (utc) on Oct. 1, 2004]
[edit reason] code dump trimmed [/edit]
Well I'm stumped.
The problem I have is that when you hit the submit button instead of printing the "the player has been updated" on the screen the browser goes to my index page
I can't find the words 'the player has been updated' in this script.
I also can't find a redirect that goes to any other page.
I'm assuming the script listed above is 'addaplayer.php'?
Tim
Hopefully the problem is obvious to someone else. It's getting late and my brain is slowing down ;-)
- you have mod_rewrite running and are redirecting to index.php (as for example if using friendly urls)
- you are using a header() redirect in PHP and there's a problem there
- you have some other sort of redirect.
Could any of those be true?
Tom