Jump to content
php.lv forumi

multi INSERT UPDATE one form


hipnoz

Recommended Posts

Ka panakt ka test_update un test_insert tiek ievietoti tikai tie dati kur value ir bijis kads skaitlis?

 

Ka lai paarnes updeitotos datus no test_update uz test_insert - bridi kad nospiez submit.

 

 

 

 

<?php

include ("connection/connect_db.php");

 

echo "test_update TABLE data:</br>";

 

////:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

$sql="SELECT * FROM test_update ORDER BY id ASC;";

$result=mysql_query($sql);

// Count table rows

$count=mysql_num_rows($result);

////:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

 

?>

<table width="500" border="0" cellspacing="1" cellpadding="0">

<form name="form1" method="post" action="">

<tr>

<td><strong>Id</strong></td>

<td><strong>Vards</strong></td>

<td><strong>Uzvards</strong></td>

<td><strong>Skaitlis</strong></td>

<td><strong>Atņemt</strong></td>

 

</tr>

<tr>

<?php

while ($row = mysql_fetch_array($result)){ ?>

<tr>

<td><?php echo $row['id']; ?></td>

<td><?php echo $row['vards']; ?></td>

<td><?php echo $row['uzvards']; ?></td>

<td><?php echo $row['skaitlis']; ?></td>

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

<tr>

<? } ?>

<tr>

<td colspan="4" align="center">

<input type="submit" name="Submit" value="Submit">

</td>

</tr>

 

</form>

</table>

 

 

<?php

 

if (isset ($_POST['Submit']))

{

 

 

foreach($_POST['foo'] as $key=>$v){

$sql1="UPDATE test_update SET skaitlis=(skaitlis-$v) WHERE id='$key'" or die(mysql_error());

$result1=mysql_query($sql1);

}

echo "update complete";

header ("Location: update_insert.php");

 

}

?>

 

<?php

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...