...which should normally not be too hard, but for some reason I just can't get it to work. I'm probably missing something or made a typo, I dunno, but whatever it is I can't find it.
include('connect-db.php');
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$query = "SELECT * FROM articles ORDER BY orderid";
$result = mysql_query($query) or die(mysql_error());
$count = mysql_num_rows($result);
?>
<div class="content-holder">
<form action="" method="post">
<table border='1' cellpadding='10' id='ViewTable'>
<tr>
<th>Volgorde</th>
<th>Titel</th>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
$orderid = $row['orderid'];
$title = $row['title'];
?>
<tr>
<td><input type="textbox" class="TextAreaTitle" name="order" value="<?=$orderid?>"></td>
<td><?=$title?></td>
</tr>
<?php
}
?>
</table>
<input type="submit" name="submit" class="submitlink" Value="Verzenden">
</form>
</div>
<?php
if(isset($_POST['submit']))
{
mysql_query("UPDATE articles SET orderid=$orderid WHERE title=$title");
echo "Updated!";
}
?>
I just pasted the entire code here to be sure. On the webpage, what you basically see if a table, with the colomns orderid and title, with all of their respective rows. the orderid's can be changed as they are a textbox. What I'm trying to achieve is that is one (or multiple) orderid's get changed, and you click on the button, then I want the orderid's to change accordingly in my database.
Thanks in advance for your help. Any questions please ask.
EDIT: I completely forgot to mention this, but what happens now when I click on the button, it returns the echo saying "Updated!" but the database doesn't actually update.
mysql_connect("$host" , "$username" , "$password")
。不要使用mysql_
函数,应该使用PDO。 - ShuklaSannidhya