02-20-2008, 02:04 PM
|
#1 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
|
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"> 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
|
|
|
|