Buenas estoy haciendo un backend para mi site, ya sé que podría hacerlo con un CMS, pero es la manera más fácil de aprender.
Al grano, en la seccion de modificar registros, me recoge bien todo, no me da error, pero no me actualiza.
Puse un -> echo "<hr>$sql<hr>"; para ver que pasa, y me doy cuenta que las variables me llegan vacias.
El código es:
codigo donde selecciono el registro a modificar:
Código PHP:
<?php
//incloim les dades del svr
include('config.php');
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from mysql </strong> </td>
</tr>
<tr>
<td align="center"><strong>Username</strong></td>
<td align="center"><strong>Password</strong></td>
<td align="center"><strong>Actualitzar</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? echo $rows['username']; ?></td>
<td><? echo $rows['password']; ?></td>
<!-- link to update.php and send value of id-->
<td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">Actualitzar</a></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
<?php
mysql_close();
?>
--------------
pagina donde puedo modificar los datos:
Código PHP:
<?php
//incloim les dades del svr
include('config.php');
// get value of id that sent from address bar
$id=$_GET['id'];
// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td> </td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"><strong>User</strong></td>
<td align="center"><strong>Pass</strong></td>
</tr>
<tr>
<td> </td>
<td align="center"><input name="usuario" type="text" id="usuario" value="<? echo $rows['username']; ?>"></td>
<td align="center"><input name="codigo" type="text" id="codigo" value="<? echo $rows['password']; ?>" size="15"></td>
</tr>
<tr>
<td> </td>
<td><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>"></td>
<td align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<?
// close connection
mysql_close();
?>
-----------------
pagina que me updata los cambios:
Código PHP:
<?php
//incloim les dades del svr
include('config.php');
// update data in mysql database
$sql="UPDATE $tbl_name SET usuario='$username', codigo='$password' WHERE id='$id'";
$result=mysql_query($sql);
echo "<hr>$sql<hr>";
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='list_records.php'>View result</a>";
}
else {
echo "ERROR";
}
?>
He buscado por Google, he probado mil cosas pero no encuentro la solución. Ofuscado ya os pido ayuda, a ver si alguien lo ve.
Gracias, Christian