doomdude Posted August 12, 2011 Share Posted August 12, 2011 Hi Guys, Would someone be able to explain to me in simple English or examples what I'm doing wrong here? What I'm trying to do: I've got a database that's setup working fine and displaying my data on a page I've made, I've added a button to edit account and delete accounts which are working fine, however I'm simply trying to make a submit button change a 0 to a 1 in the database for the row the button is on. Code: accounts.php: <?php include("includes/config.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="style/style.css" rel="stylesheet" type="text/css" /> </head> <body> <?php include("includes/header.php"); ?> <div id="admincontent"> <?php include("includes/navigation.php"); ?> <?php include("includes/navtwo.php"); ?> <? $result = mysql_query("SELECT * FROM $dbdata WHERE pin='0'") or die(mysql_error()); echo "<table border='1' cellpadding='10'>"; echo "<tr> <th>ID</th> <th>Account Name</th> <th>Name</th> <th>IP Adress</th> <th>Edit</th> <th>3 Day</th> <th>7 Day</th> <th>Delete</th></tr>"; while($row = mysql_fetch_array( $result )) { echo "<tr>"; echo '<td>' . $row['id'] . '</td>'; echo '<td>' . $row['Account_name'] . '</td>'; echo '<td>' . $row['Name'] . '</td>'; echo '<td>' . $row['IP_address'] . '</td>'; echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>'; echo '<td><form action="includes/3day.php" method="post"><input type="hidden" name="id" value="' . $row['id'] . '" /><input type="submit"></form></td>'; echo '<td></td>'; echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>'; echo "</tr>"; } echo "</table>"; ?> </div> </body> 3day.php: <?php error_reporting(E_ALL); ini_set("display_errors", "on"); include("config.php"); $id = mysql_real_escape_string($_POST['id']); if (isset($_POST['submit'])) { $query=("UPDATE $dbdata SET pin='1' WHERE id='$id'"); mysql_query($query); header("Location: /admin/accounts.php"); } else { header("Location: /admin/accounts.php"); } ?> At current when I click the submit button it does nothing. I'm really stuck with this guys so far I've used tutorials and snippits from around the web to get to this point. Quote Link to comment https://forums.phpfreaks.com/topic/244644-php-mysql-update/ Share on other sites More sharing options...
creata.physics Posted August 12, 2011 Share Posted August 12, 2011 change if (isset($_POST['submit'])) to if (isset($_POST['id'])) Quote Link to comment https://forums.phpfreaks.com/topic/244644-php-mysql-update/#findComment-1256592 Share on other sites More sharing options...
Kristoff1875 Posted August 12, 2011 Share Posted August 12, 2011 I'm working on something like this at the moment, and this is exactly what I need. Can I just ask, the way it's laid out, does that bring up pre-populated text fields with what's already there and they can change it and save the changes? Quote Link to comment https://forums.phpfreaks.com/topic/244644-php-mysql-update/#findComment-1256595 Share on other sites More sharing options...
doomdude Posted August 12, 2011 Author Share Posted August 12, 2011 change if (isset($_POST['submit'])) to if (isset($_POST['id'])) OMG I love you! been stuck with this for days! Thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/244644-php-mysql-update/#findComment-1256596 Share on other sites More sharing options...
creata.physics Posted August 12, 2011 Share Posted August 12, 2011 It's my pleasure, please mark this topic as solved please. Quote Link to comment https://forums.phpfreaks.com/topic/244644-php-mysql-update/#findComment-1256598 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.