Jump to content

Button giving a value into a db row.


Lee-Bartlett

Recommended Posts

Here is my page, i would like my bottom button, the approve button to pass a value of yes to my db, but im not quite sure how to do this. the code for this is...

 

<?php
echo "<td><form action='' method='post'> <input type='hidden' name='id' value='yes'><input type='submit' value='approve' name='approvebutton' ></form></td>";
?>

 

i was thinking of doing somthing like this tho...

 


<?php

echo "<td><form action='' method='post'> <input type='hidden' name='id' value='" . $row['id'] . "'><input type='submit' value='update' name='updatebutton' ></form></td>";


?>

Link to comment
https://forums.phpfreaks.com/topic/132728-button-giving-a-value-into-a-db-row/
Share on other sites

i guess i don't completely understand what you want...why does the value have to be 'yes'? the following:

<?php
echo "<td><form action='' method='post'><input type='submit' value='approve' name='approvebutton' ></form></td>";
?>

will submit a value of 'approve'...why can't you just use that?

I am guessing you want an admin to verify something.

If so appearance doesn't matter so much.

echo '<a href="update.php?id=$row['id']&value=yes">Approve</a>';

 

Then update.php

runs the

 $query="UPDATE  table SET value= '{$_GET['value']}' WHERE id = '{$_GET['id']}'" ;

You ought to escape the data for security but that is my concept of how to do it.

 

Never knew it was so hard to get a submit button to put a yes into a collum, here it my most recent attempt but it just renamed the button and not put yet into the database.

 

echo "<td><form action='' method='post'> <input type='hidden' name='approve' value='" . $row['approve'] . "'><input type='submit' value='yes' name='app' ></form></td>";

     

Your problem lies at the hidden field where you are trying to print the value of $row['id'] inside the value field.

 

Heres a working example:

 

Test.php (page1)
=============

<html>
<title>Test</title>
<head></head>
<body>

  <?php
  $status = "approved";
?>

<form id="test" name="test" method="post" action="collect.php">
  <label>
  <!-- We hide the value we want to send and then post it -->
  <input type="hidden" name="status" value="<?php echo $status;?>" />
  <input type="submit" name="button" id="button" value="Submit" />
  </label>
</form>

</body>
</html>

collect.php(page2)
==============
<?php
include('dbconn.php'); //include db connect file


$status = $_POST['status'];

//$state now contains the status value, in our case it contains approved
  //update db
  
$updateDB = "update table set status = '$status' where id = 100;";
$success = mysql_query($updateDB);

//use an if to check if your database is updated. from here on, you can redirect the user to another page, by using php's header() function 
?>

 

 

 

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.