<?php
require_once('auth.php');
include "header.php";
$account = $_SESSION['SESS_MEMBER_ID'];
?>
<form id="tickets" name="tickets" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table border="0" width="39%" height="128">
<tr>
<td width="45%" height="19"><strong>Title: </strong></td>
<td width="55%" height="19"><input maxlength="25" name="name" type="text" value="" size="31"> <i>* Max length 25 *</i></td>
</tr>
<tr>
<td width="45%" height="19"><strong>Subject: </strong></td>
<td width="55%" height="19"><select name="subject">
<option value="General Question">General Question</option>
<option value="Report Player">Report Player</option>
<option value="Report Admin">Report Admin</option>
<option value="Unban Request">Unban Request</option>
<option value="Items / Vehicles">Items / Money / Vehicles</option>
<option value="Script error / Bugs">Script error / Bugs</option>
</select></td>
</tr>
<tr>
<td width="45%" height="19"><strong>Priority: </strong></td>
<td width="55%" height="19"><select name="priority">
<option value="Normal">Normal</option>
</select></td>
</tr>
<tr> <td><input type="hidden" name="gamename" value="{$user->gamename}"/></td> </tr>
<tr>
<td width="45%" height="19"><strong>Text: </strong></td>
<td width="55%" height="19"><textarea rows="9" name="text" cols="37"></textarea></td>
</tr>
<tr>
<td width="45%" height="47"><input type="submit" name="tickets" id="tickets" value="Submit" /></td>
</tr>
</table>
</form>
<?php
// Make a MySQL Connection
mysql_connect("localhost", "xxxx", "xxxx") or die(mysql_error());
mysql_select_db("xxxx") or die(mysql_error());
if(isset($_POST['tickets'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$priority = $_POST['priority'];
$gamename = $_POST['gamename'];
$text = $_POST['text'];
$id = $_SESSION['SESS_MEMBER_ID'];
$account = $_SESSION['SESS_FIRST_NAME'];
$text2 = str_replace("<", "[", $text);
$text3 = str_replace(">", "]", $text2);
$text4 = str_replace("[br /]", "<br />", $text3);
$text5 = str_replace("[br/]", "<br />", $text4);
$text6 = str_replace("[br]", "<br />", $text5);
$text7 = str_replace("[b]", "<b>", $text6);
$text8 = str_replace("[/b]", "</b>", $text7);
$text9 = nl2br($text8);
$sql = "INSERT INTO tickets (tid ,uid ,status ,name , text ,subject ,priority ,username) VALUES ('NULL' , '$id' , 'Unassigned' , '$name' , '$text9' , '$subject' , '$priority' , '$account')";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
}
include "footer.php";
?>
Thats my code, I am using an include to include my header, I have tried to use header (Location:) but I always get the “Headers already sent out” problem. Any suggestions.
Cups
July 20, 2011, 2:43pm
2
Sorry, cannot see where you are calling header('Location: '); but the one rule is that you must output absolutely NOTHING before calling Header.
Check really carefully even a wayward space char, new line or for example starting your PHP output after a space as in this file:
<?php
// do things
?>
Will cause the warning. Even a warning somewhere else, with error reporting turned on will cause Header to fail.
If you cannot find it, check your PHP error log, it might show in there.
Ive put it in, then removed it. Was hoping someone could tell me how I could put it in the script above.
Is there anyway without changing the whole script to redirect after the form is submitted.
I would put the submit handling script on top of the file like this:
<?php
require_once('auth.php');
include "header.php";
// Make a MySQL Connection
mysql_connect("localhost", "xxxx", "xxxx") or die(mysql_error());
mysql_select_db("xxxx") or die(mysql_error());
if(isset($_POST['tickets'])){
$name = $_POST['name'];
$subject = $_POST['subject'];
$priority = $_POST['priority'];
$gamename = $_POST['gamename'];
$text = $_POST['text'];
$id = $_SESSION['SESS_MEMBER_ID'];
$account = $_SESSION['SESS_FIRST_NAME'];
$text2 = str_replace("<", "[", $text);
$text3 = str_replace(">", "]", $text2);
$text4 = str_replace("[br /]", "<br />", $text3);
$text5 = str_replace("[br/]", "<br />", $text4);
$text6 = str_replace("[br]", "<br />", $text5);
$text7 = str_replace("[b]", "<b>", $text6);
$text8 = str_replace("[/b]", "</b>", $text7);
$text9 = nl2br($text8);
$sql = "INSERT INTO tickets (tid ,uid ,status ,name , text ,subject ,priority ,username) VALUES ('NULL' , '$id' , 'Unassigned' , '$name' , '$text9' , '$subject' , '$priority' , '$account')";
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
else{
header("Location: yourlocationtogo.php");
die();
}
}
$account = $_SESSION['SESS_MEMBER_ID'];
?>
<form id="tickets" name="tickets" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table border="0" width="39%" height="128">
<tr>
<td width="45%" height="19"><strong>Title: </strong></td>
<td width="55%" height="19"><input maxlength="25" name="name" type="text" value="" size="31"> <i>* Max length 25 *</i></td>
</tr>
<tr>
<td width="45%" height="19"><strong>Subject: </strong></td>
<td width="55%" height="19"><select name="subject">
<option value="General Question">General Question</option>
<option value="Report Player">Report Player</option>
<option value="Report Admin">Report Admin</option>
<option value="Unban Request">Unban Request</option>
<option value="Items / Vehicles">Items / Money / Vehicles</option>
<option value="Script error / Bugs">Script error / Bugs</option>
</select></td>
</tr>
<tr>
<td width="45%" height="19"><strong>Priority: </strong></td>
<td width="55%" height="19"><select name="priority">
<option value="Normal">Normal</option>
</select></td>
</tr>
<tr> <td><input type="hidden" name="gamename" value="{$user->gamename}"/></td> </tr>
<tr>
<td width="45%" height="19"><strong>Text: </strong></td>
<td width="55%" height="19"><textarea rows="9" name="text" cols="37"></textarea></td>
</tr>
<tr>
<td width="45%" height="47"><input type="submit" name="tickets" id="tickets" value="Submit" /></td>
</tr>
</table>
</form>
<?php
include "footer.php";
?>
I hope there are no any output in those included files auth.php and header.php. Otherwise there will be headers/warnings.
Like Raju said, put your processing code in first. However, move the header.php (which I assume contains stuff like <html><head> etc to just before your form:
$account = $_SESSION['SESS_MEMBER_ID'];
?>
<?php include "header.php"; ?>
<form id="tickets" name="tickets" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
It’s the stuff in header that is messing you up.