PHP and mySQL
Posted: Tue Feb 03, 2004 3:20 am
I am currently making a script to log complaints against staff members and am having a few problems. This is the index page
When the user enters the data and presses submit, it sends them to action.php:
The action in turn prints all of the data they enter and asks if it is correct. If so, they press Yes and it targets itself and attempts to connect to the database and enter the data. If not, they press No and it directs them back to the first form.
Where I'm having the problem now is getting the action page to work correctly. When I submit the data from the index page, the action page prints it out fine, but when I press YES it simply refreshes the action page and erases all of the data without entering it into the database or displaying any sort of error. Have any clue why it might be doing this?
Code: Select all
<style type="text/css">
<!--
body,td,th {
color: #FFFFFF;
}
body {
background-color: #888888;
}
a:link {
color: #FFFFFF;
}
a:visited {
color: #FFFFFF;
}
a:hover {
color: #FFFFFF;
}
a:active {
color: #FFFFFF;
}
-->
</style>
<form action="action.php" method="POST">
<table width="100%">
<tr>
<td align="right" bgcolor="#000000">Username:</td>
<td bgcolor="#000000"><input type='text' size='30' maxlength='30' name='username' value='' class='textinput' /></td>
</tr>
<tr>
<td align="right" bgcolor="#000000">Email Address: </td>
<td bgcolor="#000000"><input type='text' size='60' maxlength='60' name='email' value='' class='textinput' /></td>
</tr>
<tr>
<td align="right" bgcolor="#000000">Complaint Filed Against: </td>
<td bgcolor="#000000"><input name='filed' type='text' class='textinput' id="filed" value='' size='30' maxlength='30' /></td>
</tr>
<tr>
<td align="right" bgcolor="#000000">Complaint:</td>
<td bgcolor="#000000"><textarea cols='60' rows='12' name='complaint' class='textinput'></textarea></td>
</tr>
<tr>
<td align="right" bgcolor="#000000">URL to Proof:</td>
<td bgcolor="#000000"><input name='proofurl' type='text' class='textinput' id="proofurl" value='' size='60' maxlength='60' /></td>
</tr>
</table>
<div align="center">
<input name="send" type="submit" id="send" value="Submit" />
</div>
</form>Code: Select all
<?
$username= $_POSTї'username'];
$email = $_POSTї'email'];
$filed = $_POSTї'filed'];
$complaint = $_POSTї'complaint'];
$proofurl = $_POSTї'proofurl'];
$ip = $_SERVERї'REMOTE_ADDR'];
$time = date ("l dS F Y at h:i:s a");
if($YES)
{
// connect to mysql
$mysql = mysql_connect( 'localhost', 'DBUSER', 'DBPASS' );
if(!$mysql)
{
echo 'Cannot connect to database.';
exit;
}
// select the appropriate database
$mysql = mysql_select_db( 'DB' );
if(!$mysql)
{
echo 'Cannot select database.';
exit;
}
$query = "insert into grb (username,email,filed,complaint,proofurl,ip,time) values ('$username','$email','$filed','$complaint','$proofurl','$ip','$time')";
$result = mysql_query($query);
if ($result)
echo mysql_affected_rows()." Complaint Filed Successfully.";
}
?>
<html><body>
<b>Username:</b> <span style='color:red'><b><?php echo $_POSTї'username'];?></b></span><br>
<b>Email:</b> <span style='color:red'><b><?php echo $_POSTї'email'];?></b></span><br>
<b>Complaint Filed Against:</b> <span style='color:red'><b><?php echo $_POSTї'filed'];?></b></span><br>
<b>Complaint:</b> <span style='color:red'><b><?php echo $_POSTї'complaint'];?></b></span><br>
<b>Url to Proof:</b> <span style='color:red'><b><?php echo $_POSTї'proofurl'];?></b></span><br>
<b><?php echo "Is this correct?";?></b>
<form name="form1" method="post" target="_self" enctype="multipart/form-data">
<input type="submit" name="YES" value="Yes"></input>
</form>
<form name="form1" method="post" action="javascript:history.go(-1);" enctype="multipart/form-data">
<input type="submit" name="NO" value="No"></input>
</form>
</body></html>Where I'm having the problem now is getting the action page to work correctly. When I submit the data from the index page, the action page prints it out fine, but when I press YES it simply refreshes the action page and erases all of the data without entering it into the database or displaying any sort of error. Have any clue why it might be doing this?