Page 1 of 1

Editing Tables [Resolved]

Posted: Mon Aug 26, 2013 3:35 am
by Epiales
Not sure who's the expert on mysql and php, but I'm working on an admin section where I can edit the usernames and such instead of having to edit from database. Below I have something I just threw together really quick. It's showing the username and such but when I update, it's not making the change in the database. Does anyone know anything about this?

Code: Select all

if(isset($_POST['Update'])){
$UpdateQuery = "UPDATE user SET username='$_POST[Username]', WHERE username='$_POST[hidden]'";
mysql_query($UpdateQuery, $con);
};

$sql = "SELECT * FROM user";
$myData = mysql_query($sql,$con);
?>
<tr>
<table border=1>
<th>Username</th>
</tr>

<?php
while($record = mysql_fetch_array($myData)) {
echo "<form action = 'mydata3.php' method=post>";
echo "<tr>";
echo "<td>" . "<input type = text name =  Username value =" . $record['username'] . " </td>";
echo "<td>" . "<input type = hidden name =  hidden  value =" . $record['username'] . " </td>";
echo "<td>" . "<input type = submit name = update value=Update" . " </td>";
echo "</form>";
}
echo "</table>";
mysql_close($con);
; 
The mydata3.php is the same document, so it's only one php file.

Re: Editing Tables

Posted: Mon Aug 26, 2013 4:21 am
by Epiales
Finally lol. I knew I wasn't too far off.

I changed to this:

Code: Select all

$UpdateQuery = "UPDATE user SET username='$_POST[Username]' WHERE id='$_POST[hidden]'";
And then this:

Code: Select all

echo "<td>" . $record['id'] . " </td>";
echo "<td>" . "<input type=text name =Username value =" . $record['username'] . " </td>";
echo "<td>" . "<input type=hidden name =hidden value =" . $record['id'] . " </td>";
echo "<td>" . "<input type=submit name=update value=Update" . " </td>";
Hope ya don't mind me making these posts. I updated it with the correct code in case someone else just happens to use it. Thanks for having such a great place for getting help.