aeafisme23 Posted April 29, 2008 Share Posted April 29, 2008 I am trying to both successfully add a delete link that will delete with using 1 php page. I can easily make it a second page and work but would like it to work with one. Here is a snippet of the records being echoed out along with the function of deleting the row: RECORDS //echo out the row echo "<tr style='background-color:$bgcolor;'> <td valign=\"top\" width=\"80\" height=\"30\" valign=\"middle\"><a href='".$_SERVER['PHP_SELF']."?id=$id'>$station_id</a></td> <td width=\"230\" valign=\"top\" height=\"30\" valign=\"middle\">$betas_sent</td> <td width=\"230\" valign=\"top\" height=\"30\" valign=\"middle\">$betas_returned</td> <td width=\"340\" valign=\"top\" height=\"30\" valign=\"middle\">$beta_notes</td> <td width=\"80\" valign=\"top\" height=\"30\" valign=\"middle\"><a href='".$_SERVER['PHP_SELF']."?action=delete'>Delete</a></td> <tr>"; $y++; //increment the counter }//end while echo "</table><br>$navigation2 <br><br>If you wish to print this page you must use Landscape Printing for best results"; }else{ //handle no results echo "<tr><td colspan='5' align='center'><b>No data found.</b></td></tr>"; }//endif } DELETE //DELETE RECORD if ($action == "delete") { $sql = "DELETE FROM kv_production WHERE id = '".$codes."'"; $msg = "Record successfully Deleted"; } $result = conn($sql); if (mysql_errno()==0) { confirm($msg); list_users(); }else{ $msg = "There was a problem adding the user to the database. Error is:".mysql_error(); confirm($mag); }//end if My old delete was used in the record displays doing this (and it worked) <td width=\"80\" valign=\"top\" height=\"30\" valign=\"middle\"><a href='delete_record_kv_production.php?id=$id'>Delete</a></td> FOLLOWED BY the page it calls delete_record_kv_production.php (this is the code that made it delete the record but i cant get it to put on one php page only, not having to go to another php page to execute. any ideas? <?php //Get variables from config.php to connect to mysql server require 'config.php'; // connect to the mysql database server. $connect = mysql_connect($dbhost, $dbusername, $dbuserpass) or die("Unable to connect to SQL server..<br />".mysql_error()); $selectDB = mysql_select_db($dbname) or die("Unable to select database.<br />".mysql_error()); //$codes = ((int)($_GET['id'])); $codes = $_GET['id']; $searchcode_query = "SELECT * FROM kv_production WHERE id = '".$codes."'"; $sql_delete_query = "DELETE FROM kv_production WHERE id = '".$codes."'"; $result = mysql_query($searchcode_query) or die("Error executing MySQL SELECT query<br />".mysql_error()); if( mysql_affected_rows() != 1 ) { print "<center>No such Station exists anymore<br><br>Please go back to <a href=\"add_record_kv_production.php\">add a record</a> | <a href=\"view_records_kv_production.php\">view a record</a></center>"; } else { mysql_free_result($result); $result = mysql_query($sql_delete_query) or die("Error executing MySQL DELETE query<br />".mysql_error()); echo "<center>Deleted record id = $codes<br><br>"; echo "Please go back to <a href=\"add_record_kv_production.php\">add a record</a> | <a href=\"view_records_kv_production.php\">view a record</a></center>"; } /** HTML Can go here too **/ ?> Link to comment https://forums.phpfreaks.com/topic/103430-delete-field-1-page-only/ Share on other sites More sharing options...
rhodesa Posted April 29, 2008 Share Posted April 29, 2008 You need to pass the ID as a GET var: <td width=\"80\" valign=\"top\" height=\"30\" valign=\"middle\"><a href='?action=delete&id=$id'>Delete</a></td> And then set that to $codes: //DELETE RECORD $codes = $_GET['id']; if ($action == "delete") Link to comment https://forums.phpfreaks.com/topic/103430-delete-field-1-page-only/#findComment-529669 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.