Ivan SGSG
Ivan SGSG

Reputation: 1

Update cell where ID

I have this form:

<?php
  $id = $_GET['id'];
?>
<form method="POST" action="send.php?<?php echo $id; ?>"
<p><input type="text" class="result" size="80%" required placeholder="number">
</p>
<p>
<input type="hidden" name="id">

<div style="width:200px;">
<span class="a-button a-button-primary a-padding-none  a-button-span12">
  <span class="a-button-inner">
    <input id="continue-top" class="a-button-text " tabindex="0" type="submit" value="Continue" >
  </span>
</span>
  </div>
</p>
</form>

I want to update column result where

$id = $_GET['id'];

How I can update 'result' where id= an example 26 here?:

mysql_query("UPDATE `cc` SET `result`=
                         ('".$_POST['result']."')",$db)  ;
header( 'Refresh: 1; url=admin.php' );

Upvotes: 0

Views: 56

Answers (3)

Mohit maru
Mohit maru

Reputation: 827

Put value in input type hidden. Which id record you want to update for example

Replace this code.

<form method="POST" action="send.php?<?php echo $id; ?>"
<p><input type="text" class="result" size="80%" required    placeholder="number">
</p>
<p>
<input type="hidden" name="id" value='26'>

<div style="width:200px;">
<span class="a-button a-button-primary a-padding-none  a-button-span12">
<span class="a-button-inner">
<input id="continue-top" class="a-button-text " tabindex="0" type="submit" value="Continue" >
</span>
</span>
</div>
</p> 
</form>

Upvotes: 0

FilipET
FilipET

Reputation: 68

<?php 
$id = $_GET['id']; 
?>
<form method="POST" action="send.php">
    <p><input type="text" class="result" name="result" size="80%" required placeholder="number"></p>
    <p>
        <div style="width:200px;">
            <span class="a-button a-button-primary a-padding-none  a-button-span12">
                <span class="a-button-inner">
                    <input id="continue-top" class="a-button-text " tabindex="0" type="submit" value="Continue" >
                </span>
            </span>
        </div>
    </p>
    <input type="hidden" name="id" value="<?php echo $id; ?>" />
</form>

And on send.php get this ID and RESULT with $_POST['id'] and $_POST['result'] and protect with mysql_real_escape_string.

Like that:

$id = mysql_real_escape_string($_POST['id']);
$result = mysql_real_escape_string($_POST['result']);

To update db table cc do this with:

mysql_query("UPDATE `cc` SET `result` = ' " . $result . " ' WHERE `id` = ' " . $id . " '", $db);

Upvotes: 1

TheBosti
TheBosti

Reputation: 1425

$sql = "UPDATE cc SET result='Doe' WHERE id=26";

But here should be someting like this, if you want $_GET[id] to work:

<form method="POST" action="send.php?id=<?php echo $id;?>"

Do not forget to sanitize data avoiding mysql injection:

$id = mysql_real_escape_string($_GET['id']); 

Upvotes: 0

Related Questions