Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

deleting records

Enthusiast ,
Jul 18, 2006 Jul 18, 2006
This must be an easy one - I'm just creating pages to add / delete records etc from a table.

I'd post a link, but at the moment it's only testing on my local machine - but the search works well, with a results page, with 'delete' in the right hand side column, within the repeat region.

The code for the link looks like :

<a href="confirmdelete.php?ContactID=<?php echo $row_recordset1['ContactID']; ?>">Delete</a>

But it's not working - I presume when I mouse over the different 'Delete' links, I should see the ContactID change as I pass over the different records - but I just draw a blank for each.

I've followed the DW help, but presume I've got the syntax wrong somewhere.

Any ideas?

Cheers,
Iain

TOPICS
Server side applications
346
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jul 19, 2006 Jul 19, 2006
Not sure if I explained that very well - I have a search page, that brings up the records correctly, and has a 'delete' link in the right hand column.

The link is to : <a href="confirmdelete.php?Contact=5">Delete</a>

confirmdelete.php displays the selected record, and a button to confirm the deletion, after which the user is taken to contactdeleted.php, with a message confirming the deletion, and offering a choice of deleting another record, or returning to anm admin menu.

Trouble is, that af...
Translate
LEGEND ,
Jul 18, 2006 Jul 18, 2006
Iain71 wrote:
> But it's not working - I presume when I mouse over the different 'Delete'
> links, I should see the ContactID change as I pass over the different records -
> but I just draw a blank for each.

Nothing wrong with your PHP. It's the recordset results that presumably
don't have any values.

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 18, 2006 Jul 18, 2006
What values should they have? They're appearing in the results page after all, with the values they have in the database.

The results page table looks like :

<table border="1">
<tr>
<td width="157">ContactID</td>
<td width="129">Name</td>
<td width="151">Address1</td>
<td width="151">Address2</td>
<td width="151">Address3</td>
<td width="152">PostCode</td>
<td width="41"> </td>
</tr>
<?php do { ?>
<tr>
<td> <?php echo $row_Recordset1['ContactID']; ?></td>
<td><?php echo $row_Recordset1['Contact']; ?></td>
<td><?php echo $row_Recordset1['Address1']; ?></td>
<td><?php echo $row_Recordset1['Address2']; ?></td>
<td><?php echo $row_Recordset1['Address3']; ?></td>
<td><?php echo $row_Recordset1['PostCode']; ?></td>
<td><a href="confirmdelete.php?Contact= <?php echo $row_recordset1['ContactID']; ?>">Delete</a></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>

so the first ContactID in bold appears correctly, but the second isn't adding itself onto the end of the 'delete' URL when moused over.

Iain
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 18, 2006 Jul 18, 2006
d'oh! Just spotted it - the second recordset needed an uppercase R.

Iain
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 18, 2006 Jul 18, 2006
although my confirm deleted page is jumping straight to the confirm deleted page, without me having to press the button to confirm. that page looks like :

<?php require_once('Connections/ConnDatabaseTest.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

if ((isset($_GET['Contact'])) && ($_GET['Contact'] != "")) {
$deleteSQL = sprintf("DELETE FROM Contacts WHERE ContactID=%s",
GetSQLValueString($_GET['Contact'], "int"));

mysql_select_db($database_ConnDatabaseTest, $ConnDatabaseTest);
$Result1 = mysql_query($deleteSQL, $ConnDatabaseTest) or die(mysql_error());

$deleteGoTo = "contactdeleted.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));
}

$colname_Recordset1 = "1";
if (isset($_GET['Contact'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['Contact'] : addslashes($_GET['Contact']);
}
mysql_select_db($database_ConnDatabaseTest, $ConnDatabaseTest);
$query_Recordset1 = sprintf("SELECT * FROM Contacts WHERE ContactID = %s", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $ConnDatabaseTest) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<form action="" method="get">
<input name="hiddenField" type="hidden" value="<?php echo $row_Recordset1['ContactID']; ?>">
<?php echo $row_Recordset1['ContactID']; ?>
<?php echo $row_Recordset1['Contact']; ?>
<input type="submit" name="Submit" value="Confirm delete">
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 19, 2006 Jul 19, 2006
LATEST
Not sure if I explained that very well - I have a search page, that brings up the records correctly, and has a 'delete' link in the right hand column.

The link is to : <a href="confirmdelete.php?Contact=5">Delete</a>

confirmdelete.php displays the selected record, and a button to confirm the deletion, after which the user is taken to contactdeleted.php, with a message confirming the deletion, and offering a choice of deleting another record, or returning to anm admin menu.

Trouble is, that after clicking the first delete, it's jumping straight to the contactdeleted.php page, bypassing the confirmation step.

It does at least work, insomuch as the record does get deleted - but it would be better probably to have the confirmation step.

Here's a link.

Any ideas?

Cheers,
Iain
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines