Editing Tables [Resolved]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Editing Tables [Resolved]

Post 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.
Last edited by Epiales on Tue Aug 27, 2013 3:23 am, edited 1 time in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Editing Tables

Post 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.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Beginner Help and Support”