|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Can't delete a row
hi
The code displays data and lets me select a row with a checkbox to delete it. My problem is that it won't display the first row and won't delete a selected row. [highlight=php] <?php $connection = mysql_connect("localhost", "root", ""); mysql_select_db("whitg22"); function editnames() { $result = mysql_query("SELECT * FROM hits"); if (mysql_fetch_array($result) != 0) { echo "<table border=0>"; echo "<tr bgcolor=#cccccc> <td align=center>Title</td> <td align=center>Artist</td> <td align=center>Year</td> <td align=center>Genreid</td> <td align=center>Chart Position</td> <td align=center>Type</td> <td align=center>Price</td> <td align=center>Quantity</td> <td align=center>Choose a Hit</td> </tr>"; while ($row = mysql_fetch_array($result)) { $title = $row['title']; $artist = $row['artist']; $year = $row['year']; $genreid = $row['genreid']; $chartposition = $row['chartposition']; $type = $row['type']; $price = $row['price']; $quantity = $row['quantity']; echo "<form method='post' action='edit.php'> <tr> <td align='center'><input type='text' name='title' value='" . $title . "' size='30' maxlength='30'></td> <td align='center'><input type='text' name='artist' value='" . $artist . "'></td> <td align='center'><input type='text' name='year' value='" . $year . "' size='4' maxlength='4'></td> <td align='center'><input type='text' name='genreid' value='" . $genreid . "' size='5' maxlength='5'></td> <td align='center'><input type='text' name='chartpostion' value='" . $chartposition . "' size='10' maxlength='10'></td> <td align='center'><input type='text' name='type' value='" . $type . "' size='5' maxlength='5'></td> <td align='center'><input type='text' name='price' value='" . $price . "' size='4' maxlength='4'></td> <td align='center'><input type='text' name='quantity' value='" . $quantity . "' size='5' maxlength='5'></td> <td align='center'><input type='checkbox' name='id' value='" . $title . "'></td></tr>"; } echo "<tr><td><input type='submit' name='submit' value='Delete'></td></tr></table></form>"; } else { echo "No records found!"; } } editnames(); if(isset($submit)) { mysql_query("DELETE FROM hits WHERE title = $id"); echo $id; } ?> [highlight=php] |
|
#2
|
|||
|
|||
|
RE: Can't delete a row
i finally made it to delete a row, but still it displays all dta rows apart from the first one, it's as if it does not see it.
|
|
#3
|
|||
|
|||
|
RE: Can't delete a row
You need to change your 'while' loop to a 'do ... while' loop. The problem is that you fetch the first row in that 'if' statement, then that row gets discarded in the 'while' statement. That while loop displayes the data, but the first row is gone.
|
|
#4
|
|||
|
|||
|
RE: Can't delete a row
Thanks vertigo, it works now
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Can't delete a row |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|