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
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?

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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>";

     

Link to comment
Share on other sites

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 
?>

 

 

 

Link to comment
Share on other sites

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.