I am trying to create a form that updates mySQL-database.
I've created three php-pages.
updatepizza.php
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="billie"; // Mysql password
$db_name="cygna_fyraarstider"; // Database name
$tbl_name="pizza_menu"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<br><br><br>
<center>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="500" border="1" bordercolor="#000000" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>Pizza</strong> </td>
</tr>
<tr>
<td align="center"><strong>Titel</strong></td>
<td align="center"><strong>Ingredienser</strong></td>
<td align="center"><strong>Pris</strong></td>
<td align="center"><strong>Uppdatera</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? echo $rows['titel']; ?></td>
<td><? echo $rows['ingrediens']; ?></td>
<td><? echo $rows['pris']; ?></td>
<td align="center"><a href="updatepizza-process.php?id=<? echo $rows['id']; ?>">Uppdatera</a></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
</center>
<?php
mysql_close();
?>
updatepizza-process.php
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="billie"; // Mysql password
$db_name="cygna_fyraarstider"; // Database name
$tbl_name="pizza_menu"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<br><br><br>
<center>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="500" border="1" bordercolor="#000000" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>Pizza</strong> </td>
</tr>
<tr>
<td align="center"><strong>Titel</strong></td>
<td align="center"><strong>Ingredienser</strong></td>
<td align="center"><strong>Pris</strong></td>
<td align="center"><strong>Uppdatera</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? echo $rows['titel']; ?></td>
<td><? echo $rows['ingrediens']; ?></td>
<td><? echo $rows['pris']; ?></td>
<td align="center"><a href="updatepizza-process.php?id=<? echo $rows['id']; ?>">Uppdatera</a></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
</center>
<?php
mysql_close();
?>
update-success.php
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="billie"; // Mysql password
$db_name="cygna_fyraarstider"; // Database name
$tbl_name="pizza_menu"; // Table name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="UPDATE pizza_menu SET titel='$titel', ingrediens='$ingrediens', pris='$pris' WHERE id='$id'";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='updatepizza.php'>Gå tillbaka</a>";
}
else {
echo "ERROR";
}
?>
It shows "Successful" when I've updated a row but it doesn't change anything in the database. What is the problem? I've been trying to figure it out for days now.