Jump to content

Recommended Posts

hi-

i have been using dreamweaver to create an administration section for my website (as it's really handy). Basically you log in and can, add, remove, edit records which is fine.

for deleting records:

[list]
[*]i have one page that lists all the record's titles next to a radio button.
[*]you click a radio button and then submit the form
[*]now it should go to a page that displays the record in question, at which point the user can read the record and continue to delete should he/she desire
[/list]

Instead it just deletes the record anyway without getting the information and displaying it on a second page. How do i get it to wait until the user clicks submit before executing the delete?

thats the form on the first page:
[code] <div id="admin">
  <?php do { ?>
    <form action="delnews2.php" method="get" name="delnews">
        <p>
          <input name="ev_id" type="radio" value="<?php echo $row_delnews1['ev_id']; ?>" />
          <?php echo $row_delnews1['ev_title']; ?> <span class="forthcoming">[<?php echo $row_delnews1['ev_date']; ?>]</span>
        <hr />
        </p><?php } while ($row_delnews1 = mysql_fetch_assoc($delnews1)); ?>
      <input name="" type="submit" value="select" />
        </form>
    </div>
<!-- InstanceEndEditable --></div>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($delnews1);
?>[/code]

and this is the second page's rescordset and form:

[code]<?php require_once('../Connections/contacts.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['ev_id'])) && ($_GET['ev_id'] != "")) {
  $deleteSQL = sprintf("DELETE FROM events WHERE ev_id=%s",
                      GetSQLValueString($_GET['ev_id'], "int"));

  mysql_select_db($database_contacts, $contacts);
  $Result1 = mysql_query($deleteSQL, $contacts) or die(mysql_error());

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

$colname_delnews2 = "-1";
if (isset($_GET['ev_id'])) {
  $colname_delnews2 = (get_magic_quotes_gpc()) ? $_GET['ev_id'] : addslashes($_GET['ev_id']);
}
mysql_select_db($database_contacts, $contacts);
$query_delnews2 = sprintf("SELECT * FROM events WHERE ev_id = %s", $colname_delnews2);
$delnews2 = mysql_query($query_delnews2, $contacts) or die(mysql_error());
$row_delnews2 = mysql_fetch_assoc($delnews2);
$totalRows_delnews2 = mysql_num_rows($delnews2);
?>[/code]

[code] <div id="admin">
<form action="" method="post" name="delnews">
        <p>
          <input name="ev_id" type="hidden" value="<?php echo $row_delnews2['ev_id']; ?>" />
          <?php echo $row_delnews2['ev_title']; ?> <span class="forthcoming">[<?php echo $row_delnews2['ev_date']; ?>]</span>
  <p> <?php echo $row_delnews2['ev_desc']; ?></p>
       
        </p>
      <input name="" type="submit" value="select" />
    </form>
  </div>
<!-- InstanceEndEditable --></div>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($delnews2);
?>[/code]
you have used $_GET['ev_id'] on both pages and in the php part it first looks for $_GET['ev_id'] being set, then deletes it if it is( it is set when it comes to this page from the first page) it then goes onto say if its set get all the data, unfortunatley it has now been deleted on page. try on the second form:-
[code]
<input name="ev_id1" type="hidden" value="<?php echo $row_delnews2['ev_id']; ?>" />

[/code]

then in the second pages recordset put the following

[code]
if ((isset($_GET['ev_id1'])) && ($_GET['ev_id1'] != ""))
[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.