ursula.ug Posted November 28, 2011 Share Posted November 28, 2011 I need a bit of help. I am displaying records from a db, and want the user to be able to delete a record. I'm almost there (I think) but it doesn't pass the variable ($hours_id) to the delete query. Any ideas? Should be easy...but I'm just at my end. <?php include '../php/config_conn.php'; $querysum = "SELECT SUM(total_time) FROM `coop_hours` where user = '".$_SESSION['user_name']."'"; $resultsum = mysql_query($querysum); $arr = mysql_fetch_row($resultsum); $resulthours = $arr[0]; $querytime = "SELECT * FROM `coop_hours` WHERE user = '".$_SESSION['user_name']."' ORDER BY 'date_completed'"; $result = mysql_query($querytime); $num = mysql_num_rows($result); mysql_close(); echo "<table width='800' cellpadding='0'><tr> <td><strong>Coop Job</strong></td> <td align=center><strong>Date Completed</strong></td> <td align=center><strong>Total Time</strong></td> <td><strong>Comments</strong></td><td>Delete Entry</td></tr>"; $i=0; while ($i < $num) { $hours_id = mysql_result($result, $i, "hours_id"); $user = mysql_result($result, $i, "user"); $coop_job = mysql_result($result, $i, "coop_job"); $date_completed = mysql_result($result, $i, "date_completed"); $start_time = mysql_result($result, $i, "start_time"); $end_time = mysql_result($result, $i, "end_time"); $total_time = mysql_result($result, $i, "total_time"); $comments = mysql_result($result, $i, "comments"); echo "<tr><td>$coop_job</td> <td align=center>$date_completed</td> <td align=center>$total_time</td> <td>$comments</td> <td align=center> <a href='php/del.php'><img src='images/del.png'></a></td> </tr>"; $i++; } echo "<tr><td colspan=5><hr></td></tr>"; echo "<tr><td></td><td align=right>Total hours:</td><td align=center>$resulthours</td><td></td></tr>"; echo "<table>"; ?> And here is del.php: <?php include '../../php/config_conn.php'; $del_query = ("DELETE FROM coop_hours WHERE hours_id = '".$hours_id."' LIMIT 1"); $result = mysql_query($del_query); header("Location: http://.../myaccount-testing.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/251998-delete-row-from-db/ Share on other sites More sharing options...
MasterACE14 Posted November 29, 2011 Share Posted November 29, 2011 [ code ] [ /code ] tags please. <?php include '../php/config_conn.php'; $querysum = "SELECT SUM(total_time) FROM `coop_hours` where user = '".$_SESSION['user_name']."'"; $resultsum = mysql_query($querysum); $arr = mysql_fetch_row($resultsum); $resulthours = $arr[0]; $querytime = "SELECT * FROM `coop_hours` WHERE user = '".$_SESSION['user_name']."' ORDER BY 'date_completed'"; $result = mysql_query($querytime); $num = mysql_num_rows($result); mysql_close(); echo "<table width='800' cellpadding='0'><tr> <td><strong>Coop Job</strong></td> <td align=center><strong>Date Completed</strong></td> <td align=center><strong>Total Time</strong></td> <td><strong>Comments</strong></td><td>Delete Entry</td></tr>"; $i=0; while ($i < $num) { $hours_id = mysql_result($result, $i, "hours_id"); $user = mysql_result($result, $i, "user"); $coop_job = mysql_result($result, $i, "coop_job"); $date_completed = mysql_result($result, $i, "date_completed"); $start_time = mysql_result($result, $i, "start_time"); $end_time = mysql_result($result, $i, "end_time"); $total_time = mysql_result($result, $i, "total_time"); $comments = mysql_result($result, $i, "comments"); echo "<tr><td>$coop_job</td> <td align=center>$date_completed</td> <td align=center>$total_time</td> <td>$comments</td> <td align=center> <a href='php/del.php'><img src='images/del.png'></a></td> </tr>"; $i++; } echo "<tr><td colspan=5><hr></td></tr>"; echo "<tr><td></td><td align=right>Total hours:</td><td align=center>$resulthours</td><td></td></tr>"; echo "<table>"; ?> And here is del.php: <?php include '../../php/config_conn.php'; $del_query = ("DELETE FROM coop_hours WHERE hours_id = '".$hours_id."' LIMIT 1"); $result = mysql_query($del_query); header("Location: http://.../myaccount-testing.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/251998-delete-row-from-db/#findComment-1292028 Share on other sites More sharing options...
MasterACE14 Posted November 29, 2011 Share Posted November 29, 2011 You're not sending $hours_id to the other file. Quote Link to comment https://forums.phpfreaks.com/topic/251998-delete-row-from-db/#findComment-1292030 Share on other sites More sharing options...
ursula.ug Posted November 29, 2011 Author Share Posted November 29, 2011 I'm trying. I can add this to the form <input type="hidden" name="hours_id" value=""> and this to the del.php file: $hours_id = $_POST["hours_id"]; But it still doesn't work Quote Link to comment https://forums.phpfreaks.com/topic/251998-delete-row-from-db/#findComment-1292055 Share on other sites More sharing options...
MasterACE14 Posted November 29, 2011 Share Posted November 29, 2011 because the 'value' attribute needs a value. Quote Link to comment https://forums.phpfreaks.com/topic/251998-delete-row-from-db/#findComment-1292059 Share on other sites More sharing options...
ursula.ug Posted November 29, 2011 Author Share Posted November 29, 2011 so I tried: <input type="hidden" name="hours_id" value="<?php echo $_POST['hours_id']; ?>"> but I know it's in the wrong place and won't work. The hours_id is an auto increment created when the info from the form is inserted into the database I have to pull that out of the db, and then pass it. Quote Link to comment https://forums.phpfreaks.com/topic/251998-delete-row-from-db/#findComment-1292064 Share on other sites More sharing options...
ursula.ug Posted November 29, 2011 Author Share Posted November 29, 2011 Figured it out. Not as pretty as I want it to be, but it works... Quote Link to comment https://forums.phpfreaks.com/topic/251998-delete-row-from-db/#findComment-1292413 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.