Jump to content

making an erase button on the SELECT file


nickbunyun

Recommended Posts

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 :)

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.

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>";

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>";
?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.