phpnewbie1979 Posted February 1, 2010 Share Posted February 1, 2010 Hi everyone I am in the process of creating a simple cms for my site and I ran into a problem deleting rows from the database. I created a script that shows all rows in the database and then tried to create a delete button that would delete the row if clicked. I'm obviously doing something wrong and I can't figure it out. Any help would be greatly appreciated. I've been at it for a few days with no solution. The script i'm using is to show all rows and place the delete link is: <?php require_once "connect_to_mysql.php"; $query="SELECT * FROM table_name"; $result=mysql_query($query); $num=mysql_num_rows($result) or die(mysql_error()); mysql_close(); ?> <div> <table border="0" cellspacing="0" cellpadding="0"> <?php $i=0; while ($i < $num) { $c0=mysql_result($result,$i,"fieldone"); $c1=mysql_result($result,$i,"fieldtwo"); $c2=mysql_result($result,$i,"fieldthree"); $c3=mysql_result($result,$i,"fieldfour"); $c4=mysql_result($result,$i,"fieldfive"); $c5=mysql_result($result,$i,"fieldsix"); $c6=mysql_result($result,$i,"fieldseven"); $c7=mysql_result($result,$i,"fieldeight"); $c8=mysql_result($result,$i,"fieldnine"); $c9=mysql_result($result,$i,"fieldten"); ?> <tr><td class="td_border_left" width="50"><?php echo $id; ?></td> <td class="td_border_right" width="300"> <strong><?php echo $c1; ?></strong><br /> <?php echo $c2; ?><br /> <?php echo $c3; ?>, <?php echo $c4; ?><br /><br /> <strong>Program:</strong> <?php echo $c5; ?><br /><br /> <strong>Waiting List:</strong> <?php echo $c6; ?><br /> <strong>Type:</strong <?php echo $c7; ?><br /> <strong>Application Deadline:</strong> <?php echo $c8; ?><br /> <strong>Application Deadline:</strong> <?php echo $c9; ?><br /> </td> <form id="form" name="form" method="post" action="delete.php"> <td class="td_border_right" valign="top"> <input type="hidden" name="fieldname" value="<?=$_Post['$c0']; ?>"/> <input type="submit" value="delete" /> </td> </form> </tr> <?php $i++; } ?> </table> </div> and the delete script I'm using is: <?php $c0 = $_POST['$c0']; include_once "connect_to_mysql.php"; // Add the updated info into the database table $query="DELETE FROM table_name WHERE c0='$c0'"; echo($query); mysql_query($query) or die(mysql_error()); ?> The error I'm getting is DELETE FROM affhousing WHERE id='' Link to comment https://forums.phpfreaks.com/topic/190563-cant-delete-rows-from-database/ Share on other sites More sharing options...
Mchl Posted February 1, 2010 Share Posted February 1, 2010 <?=$_Post['$c0']; ?> should be <?=$_POST[$c0]; ?> or maybe <?=$_POST['c0']; ?> (can't be sure without seeing more of your code) For the other file $c0 = $_POST['$c0']; should be $c0 = $_POST['fieldname']; probably Link to comment https://forums.phpfreaks.com/topic/190563-cant-delete-rows-from-database/#findComment-1005077 Share on other sites More sharing options...
phpnewbie1979 Posted February 1, 2010 Author Share Posted February 1, 2010 Thanks I figured it out. in the first script I put <input type="hidden" name="fieldname" value="<?=$_Post[$'c0']; ?>"/> I should have put: <input type="hidden" name="fieldname" value="<?php echo $c0; ?>"/> and in the delete script i changed $c0 = $_POST['$c0']; to just $_POST['$c0']; Link to comment https://forums.phpfreaks.com/topic/190563-cant-delete-rows-from-database/#findComment-1005142 Share on other sites More sharing options...
Mchl Posted February 1, 2010 Share Posted February 1, 2010 to just $_POST['$c0']; This line does nothing... Link to comment https://forums.phpfreaks.com/topic/190563-cant-delete-rows-from-database/#findComment-1005148 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.