nickbunyun Posted April 24, 2008 Share Posted April 24, 2008 so heres the part.. while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['email'] . "</td>"; echo "<td>" . $row['age'] . "</td>"; echo "<td>" . $row['question'] . "</td>"; echo "<td>" . "X" . "</td>"; echo "</tr>"; specifically echo "<td>" . "X" . "</td>"; i wanna make <a href=" "> X </a> but how do i add it ? i already know the sql to erase the whole row... so heres it DELETE FROM `homeone` WHERE `homeone`.`id` = 6 LIMIT 1 im guessing to pick up the ID i should do this? mysql_querty("DELETE FROM `homeone` WHERE `homeone`.`id` = ". $row['id'] ." LIMIT 1"); anyway.. a lil help please? thanks Link to comment https://forums.phpfreaks.com/topic/102643-making-an-erase-button-on-the-select-file/ Share on other sites More sharing options...
Fadion Posted April 24, 2008 Share Posted April 24, 2008 The link: echo "<a href='index.php?deleteID='" . $row['id'] . ">Click here to delete</a>; The php action: <?php if(isset($_GET['deleteID'])){ $delID = mysql_real_escape_string($_GET['deleteID']); $resultsDelete = mysql_query("DELETE FROM homeone WHERE id=$delID"); } ?> It is called using the GET superglobal. Link to comment https://forums.phpfreaks.com/topic/102643-making-an-erase-button-on-the-select-file/#findComment-525687 Share on other sites More sharing options...
nickbunyun Posted April 24, 2008 Author Share Posted April 24, 2008 i changed it to view.php since thats the file... if i click on the X (which is changed from "click here to delete") it goes to view.php?deleteID= but it does not add anything the ID number.. i checked it, if i add it manually, it does erase it.. so whats wrong with my a href? if(isset($_GET['deleteID'])){ $delID = mysql_real_escape_string($_GET['deleteID']); $resultsDelete = mysql_query("DELETE FROM homeone WHERE id=$delID"); } while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['email'] . "</td>"; echo "<td>" . $row['age'] . "</td>"; echo "<td>" . $row['question'] . "</td>"; echo "<td align='center'> <a href='view.php?deleteID='".$row['id'] .">X</a></td>"; echo "</tr>"; } echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/102643-making-an-erase-button-on-the-select-file/#findComment-525699 Share on other sites More sharing options...
Fadion Posted April 24, 2008 Share Posted April 24, 2008 Assuming uve made the connection to the db, u should have a select query. The whole code should resamble (but using your table and column names): <?php include('dbconnect.php'); if(isset($_GET['deleteID'])){ $delID = mysql_real_escape_string($_GET['deleteID']); $resultsDelete = mysql_query("DELETE FROM homeone WHERE id=$delID"); } $values = mysql_query(SELECT * FROM homeone); //<<< the line I added while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['email'] . "</td>"; echo "<td>" . $row['age'] . "</td>"; echo "<td>" . $row['question'] . "</td>"; echo "<td align='center'> <a href='view.php?deleteID='".$row['id'] .">X</a></td>"; echo "</tr>"; } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/102643-making-an-erase-button-on-the-select-file/#findComment-525707 Share on other sites More sharing options...
nickbunyun Posted April 24, 2008 Author Share Posted April 24, 2008 it falls on line 25 and than i have an error on line 25... heres my whole code <?php include ('menu.php'); $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db(testinsert, $con); $result = mysql_query("SELECT * FROM homeone"); // unused line.. mysql_querty("DELETE FROM `homeone` WHERE `homeone`.`id` = ". $row['id'] ." LIMIT 1"); echo '<table border="1" align="center"> <th> ID </th> <th width="150"> Name </th> <th width="150"> E-Mail Address </th> <th width="50"> Age </th> <th width="300"> Question </th> <th> Tools </th>'; if(isset($_GET['deleteID'])){ $delID = mysql_real_escape_string($_GET['deleteID']); $resultsDelete = mysql_query("DELETE FROM homeone WHERE id=$delID"); } while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['email'] . "</td>"; echo "<td>" . $row['age'] . "</td>"; echo "<td>" . $row['question'] . "</td>"; echo "<td align='center'> <a href='view.php?deleteID='".$row['id'] .">X</a> </td>"; echo "</tr>"; } echo "</table>"; mysql_close($con) ?> this is the error im gettin Parse error: syntax error, unexpected T_STRING in D:\xampp\htdocs\tuts\insert2\view.php on line 25 Link to comment https://forums.phpfreaks.com/topic/102643-making-an-erase-button-on-the-select-file/#findComment-525712 Share on other sites More sharing options...
nickbunyun Posted April 24, 2008 Author Share Posted April 24, 2008 found the problem.. it was this.. echo ('<td align="center"><a href="view.php?deleteID='.$row['id'].'">X</a></td>'); Link to comment https://forums.phpfreaks.com/topic/102643-making-an-erase-button-on-the-select-file/#findComment-525759 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.