TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-20-2008, 02:04 PM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default form refresh problem

hi,

this form i made when i refresh witout entering anything a new row is created automatically. heres the code


ps:

in the first column, i tried to make the number a link but since its dynamic how do i make it a link to pull data from a row from the database.


Code:
<?php

$conn = mysql_connect("","","");
mysql_select_db("queue");

$queue_id = $_POST['queue_id'];
$status = $_POST['status'];
$datestart = $_POST['startdate'];
$dateend = $_POST['datestop'];
$domain = $_POST['domain'];
$company = $_POST['company'];
$assign = $_POST['assignby'];


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


#-----------------------------------------------
#		check for empty fields
#-----------------------------------------------

if(


!$_POST['queue_id']  ||
!$_POST['status']    ||
!$_POST['startdate'] ||
!$_POST['datestop']  ||
!$_POST['domain']    ||
!$_POST['company']    ||
!$_POST['assignby']    )




{ die('all fields are required go back and enter all the fields'); }


#-----------------------------------------------
#		security check
#-----------------------------------------------

$queue_id = addslashes($queue_id);
$status = addslashes($status);
$datestart = addslashes($datestart);
$dateend = addslashes($dateend);
$domain = addslashes($domain);
$company = addslashes($company);
$assign = addslashes($assign);


$queue_id = htmlentities($queue_id);
$status = htmlentities($status);
$datestart = htmlentities($datestart);
$dateend = htmlentities($dateend);
$domain = htmlentities($domain);
$company = htmlentities($company);
$assign = htmlentities($assign);




#-----------------------------------------------
#		save data
#-----------------------------------------------


$query = "INSERT INTO queue VALUES(null,'$queue_id','$status','$datestart','$dateend','$domain','$company','$assign')";
$save = mysql_query($query) or die(mysql_error());

}



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>

<style type="text/css">

th {
	 padding:8px;
	 background-color:navy;
	 border:1px solid black;
	 color:white;
}

td{
	
	padding:8px;
	background-color:#6699CC;
	border-left:1px dashed gray;
    border-right:1px dashed gray;
	color:white;
}

a:active,a {
	
	text-decoration:none;
	color:yellow;
	font-family:Verdana;
	font-size:10pt;
}

a:hover {
	
	text-decoration:underline;
	color:yellow;
	font-family:Verdana;
	font-size:10pt;
}



.style1 {
	background-color: #FFFF00;
}



</style>
</head>

<body>

<strong><span class="style1">&nbsp; Add a Request</span></strong><br />
<br />

<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<table>
<thead>
<tr>
<th>Queue #</th>
<th>Status</th>
<th>Date Started</th>
<th>Date Completed</th>
<th>Domain</th>
<th>Company name</th>
<th>Assigned by</th>
</tr>
</thead>



<tr>
<td><input type="text" name="queue_id"  style="width: 75px"></td>

<td><select name="status" style="width: 124px">
<option></option>
<option value="notstart">Not Started</option>
<option value="pending">Pending</option>
<option value="waiting">Waiting on someone</option>
<option value="complete">Completed</option>
</select></td>

<td><input type="text" name="startdate"></td>
<td><input type="text" name="datestop"></td>
<td><input type="text" name="domain"></td>
<td><input type="text" name="company"></td>
<td><input type="text" name="assignby"></td>

</tr>


</table>
<p>
<input type="submit" name="btn_submit" value="submit" style="width: 85px; height: 22px"></p>

<table>
<thead>
<tr>

<?php
$query_table = "SELECT * FROM queue ORDER BY 'queue_id'";
$result = mysql_query($query_table);

$header = "<p><strong><span class=\"style1\">Queue History</span></strong></p>";
$header .= "<th>Queue #</th>";
$header .= "<th>Status</th>";
$header .= "<th>Date Started</th>";
$header .= "<th>Date Completed</th>";
$header .= "<th>Domain</th>";
$header .= "<th>Company name</th>";
$header .= "<th>Assigned by</th>";



if(mysql_num_rows($result) == 0) {


echo "no records found";

}

else { 

echo $header;

}


?>




</tr>
</thead>

<?php

$query_table = "SELECT * FROM queue ORDER BY 'queue_id'";
$result = mysql_query($query_table);

if(mysql_num_rows($result)) {
$block = "<tbody><tr>";
while($row = mysql_fetch_assoc($result)) {

$block .= "<td><a href=\"edit.php?id=\"{$row['queue_id']}\">{$row['queue_id']}</a></td>";
$block .= "<td>{$row['status']}</td>";
$block .= "<td>{$row['date_started']}</td>";
$block .= "<td>{$row['date_end']}</td>";
$block .= "<td>{$row['domain']}</td>";
$block .= "<td>{$row['company']}</td>";
$block .= "<td>{$row['assigned_by']}</td>";
$block .= "</tr></tbody>";

}
echo $block;

}

?>










</form>
</body>

</html>
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 02-20-2008, 02:14 PM   #2 (permalink)
The Wanderer
 
Join Date: Feb 2008
Posts: 10
Thanks: 0
Pete is on a distinguished road
Default

by new row do you mean it inserts into your database but blank?
Pete is offline  
Reply With Quote
Old 02-20-2008, 03:55 PM   #3 (permalink)
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default

If it reenters a copy of the row on refresh, make a check that checks to see if there is a row already with those values and if there is don't enter it!
Gareth is offline  
Reply With Quote
Old 02-21-2008, 02:47 AM   #4 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

here is a before and after screenshot of what happends.

here is the before screenshot
(i entered data into the field above and press submit and that new row got created.)


and when after that row is created if i click on the refresh button on the browser (automatically) the data is re-submited and creating the row again.

__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 02-21-2008, 11:09 AM   #5 (permalink)
The Contributor
 
flyingbuddha's Avatar
 
Join Date: Jan 2008
Location: Birmingham, UK
Posts: 60
Thanks: 10
flyingbuddha is on a distinguished road
Default

You could do one of a couple of things to prevent double-posts.

1. Before submitting your new data, check the last record's field contents aren't exactly the same as the one previous. (Not very fail-safe)

2. Issue a header to redirect to the current page:
PHP Code:
// not a great example as I'm not sanitizing the url
header("Location: {$_SERVER['PHP_SELF']}");
exit; 
__________________
Pro. Geek
http://www.mikeholloway.co.uk
flyingbuddha is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 02:33 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design