A
A
Alexander2016-07-16 14:40:16
PHP
Alexander, 2016-07-16 14:40:16

Pass variable using POST method...?

There is a form:

<form action="php/post_delete.php" method="post">
  <input type = "text" name="' .$result['id']. '" hidden />
  <input type="submit" value="Удалить"><br>
</form>';

If on the form page echo $result['id']; then it displays everything correctly, it remains only to send it to php/post_delete.php by POST and, as it were, the job is done. But somewhere I mow, and I can not understand where. The host:
<?php 
//тут подключение к БД
?>
<?php
$id = $_POST[$result['id']];
$query = database::query("DELETE FROM 'punk' WHERE id =" $id  "");
?>

The error is always the same. "Unknown variable $id"
I tried:
$id = $_POST['id'];
$id = $_POST[name];
$id = $result['id'];

And nothing comes out. Poke your nose, please, what am I stupid here.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
#
# artur #, 2016-02-04
@NemoNab

Show the contents of mail.php because it should be sent through it. Ajax simply dynamically returns an "Ok" or "An error occurred!" result, and before that, jQuery.validation checks that the form fields are filled in correctly.
Understand your PHP script, read - php.net/manual/ru/function.mail.php Understand
the location of the mail.php file, your paths are different in your examples

N
NemoNab, 2016-02-04
@NemoNab

Yes, with ways it is visible and the truth a trouble.
Here is the mailer code:

<?php

$method = $_SERVER['REQUEST_METHOD'];

//Script Foreach
$c = true;
if ( $method === 'POST' ) {

  $project_name = trim($_POST["project_name"]);
  $admin_email  = trim($_POST["admin_email"]);
  $form_subject = trim($_POST["form_subject"]);

  foreach ( $_POST as $key => $value ) {
    if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
      $message .= "
      " . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . "
        <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
        <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
      </tr>
      ";
    }
  }
} else if ( $method === 'GET' ) {

  $project_name = trim($_GET["project_name"]);
  $admin_email  = trim($_GET["admin_email"]);
  $form_subject = trim($_GET["form_subject"]);

  foreach ( $_GET as $key => $value ) {
    if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
      $message .= "
      " . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . "
        <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
        <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
      </tr>
      ";
    }
  }
}

$message = "<table style='width: 100%;'>$message</table>";

mail($admin_email, $form_subject, $message, "From: $project_name <$admin_email>" . "\r\n" . "Reply-To: $admin_email" . "\r\n" . "X-Mailer: PHP/" . phpversion() . "\r\n" . "Content-type: text/html; charset=\"utf-8\"");

A
Alexander, 2016-07-16
@PUNK_199

Problem solved.

<form action="php/post_delete.php" method="post">
  <input type = "text" name = "id" value ="' .$result['id']. '" hidden />
  <input type="submit" value="Удалить"><br>
</form>';

...and
<?php
$id = $_POST['id'];
$query = database::query("DELETE FROM punk WHERE id = '$id'");
?>

A
Alexander, 2016-07-16
@NeiroNx

<input type = "text" name="id" value="' .$result['id']. '" hidden />

try it like that.

M
Maxim Timofeev, 2016-07-16
@webinar

Well, not $id = $_POST['id'] but $id = $_POST['result']['id'] probably

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question