Jump to content

[SOLVED] update records


DeFActo

Recommended Posts

Hello all,

 

i want to update records in table and have that code:

<?
// Connect database.
$host="localhost"; // Host name.
$db_user=""; // MySQL username.
$db_password=""; // MySQL password.
$database=""; // Database name.
mysql_connect($host,$db_user,$db_password);
mysql_select_db($database);
$result=mysql_query("select * from kol where id='1'");
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="update_1.php">
<table border="1" cellpadding="3" cellspacing="0">
<tr>
<td align="center" bgcolor="#FFCC00"><strong>ID</strong></td>
<td align="center" bgcolor="#FFCC00"><strong>Name</strong></td>
</tr>
<?

while($row=mysql_fetch_assoc($result)){
?>
<tr>
<td bgcolor="#FFFFCC<? echo $row['id']; $aa=$row['id'];  ?></td>
<td bgcolor="#FFFFCC"><input name="name_<? echo $row['id']; ?>" type="text" id="name_<? echo $row['id']; ?>" value="<? echo $row['name']; ?>" /></td>
</tr>
<? }  ?>
</table>
<input type="submit" name="Submit" value="Update" />
</form>
</body>
</html>

 

everything would be perfect, but as you can see i want to update just one row. I know that i could do it like that:

 

<input name="id_<? echo $row['id']; ?>" type="text" id="id_<? echo $row['id']; ?>" <!--value="<? echo $row['id']; ?>" />

 

and then in update_1.php:

 

$a=$_POST['id'];

 

but i do not want that $row['id'] would be changeable. Any hints how could i do it?

Thank you in advance.

Link to comment
https://forums.phpfreaks.com/topic/100499-solved-update-records/
Share on other sites

not sure why you posted that but you would replace that line with the one i posted above.

 

then one you submit you would get the id with

 

$a = $_POST['id'];

 

You won't have to put the id with the name anymore

 

<input name="name" type="text" id="name_<? echo $row['id']; ?>" value="<? echo $row['name']; ?>" />

 

 

Ray

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.