Hi!
My script below, if I hit F5 or 'refresh', will add a blank entry into the table below the select box.. How can I stop this from happening? And another thing I noticed, the 'delete' column is not deleting entries.. Is the syntax of the delete link incorrect?
Code:
<html>
<head>
<title>Add Participants</title>
</head>
<body>
<?php
// Connect to database
$connect= mysql_connect("localhost","root")
or die("Could not connect to database in localhost !");
mysql_select_db("testdiw")
or die("Could not select that database !");
echo '
<TABLE BORDER="0" width=600 cellspacing=0>
<tr>
<form name="form3" method="post">
<TR>
<TD> <CENTER>
<select name="company_id" tabindex="4"><option value="-notset-">- Select a participant -</option> ';
//--- CREATE SELECT ---
$sql = "SELECT DISTINCT name FROM part_name ORDER BY name";
$name = mysql_query($sql) or die($sql . '<br />' . mysql_error());
while ($row = mysql_fetch_array($name)) {
echo '<option value="' . $row['name'] . '">' . $row['name'] . '</option>';
}
;
echo ' </CENTER></TD>
</TR>
<TR>
<TD COLSPAN=2><BR><CENTER><input type="submit" name="Submit" value="Submit" action="required"></CENTER></TD></FORM>
</TR>
</TABLE> ';
?>
<?PHP
$connect= mysql_connect("localhost","root")
or die("Could not connect to database in localhost !");
$result=mysql_select_db("testdiw")
or die("Could not select that database !");
$sqlquery = "INSERT INTO attendees VALUES('', '". $_POST['company_id'] ."')";
$queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query !");
$sqlquery = "SELECT * from attendees";
?>
<?PHP
$connect= mysql_connect("localhost","root")
or die("Could not connect to database in localhost !");
$result=mysql_select_db("testdiw")
or die("Could not select that database !");
$sqlquery1 = "SELECT participant_id, company_id FROM attendees ORDER BY company_id";
$queryresult1 = mysql_query($sqlquery1) or die(" Could not execute mysql query !");
$row = mysql_fetch_row($queryresult1);
$participant_id = $row[0];
$company_id = $row[1];
$byebye = $row[2];
$byebye = "delete from attendees where company_id='".$_POST['company_id']."' LIMIT 1";
$tdcount = 1;
$numtd = 1; // number of cells per row
echo '
<TABLE width="48%" ALIGN="left" CELLSPACING=2>
<tr>
<td>Participant ID </td>
<td> Participant Name</td>
<td> Action</td>';
while($row = mysql_fetch_array($queryresult1)) {
if ($tdcount == 1) echo "<tr>";
echo '<td> '.$row['participant_id'],'</td><td>'.$row['company_id'].'</td><td><a href="?participant_id='".$_POST['participant_id']."'&action=delete">Delete</a></td>';
if ($tdcount == $numtd) {
echo "</tr>";
$tdcount = 1;
} else {
$tdcount++;
}
}
// time to close up our table
if ($tdcount!= 1) {
while ($tdcount <= $numtd) {
echo "<td> </td>";
$tdcount++;
}
echo "</tr>";
}
echo '
</table> ';
?>