You are here: Re: Still struggling..... « PHP SQL « IT news, forums, messages
Re: Still struggling.....

Posted by ZeldorBlat on 02/17/06 22:19

UKuser wrote:
> This code is still not working. I have adjusted it so the table
> displays however, what I'm after is that when you update any number of
> fields, and click update, the whole table gets updated.
>
> Also, what is the smallest code to add to avoid SQL/XSS injectiony
> stuff?
>
> Thanks
>
> <HTML>
> <TITLE>test 4</title>
> <form method='post' action='test4.php'>
> <?php
> function check_mysql()
> {
> if (mysql_errno() > 0)
> {
> die("<BR> MySQL error " . mysql_errno() . ": " .mysql_error());
> }
> }
>
> $db = mysql_connect("coconia.net", "nana46_nana46", "hello");
> if (!$db)
> {
> die("Failed to open connection to MySQL server.");
> }
>
> mysql_select_db("nana46_nana46");
> check_mysql();
>
> $requete = "SELECT id,lowerval,upperval,result FROM fig_lookup";
> $resulta = mysql_query($requete) or die (mysql_error());
>
> echo '<table border="2" cellpadding="0" cellspacing="0" width="100%">';
>
> $edit = "<img src='edit.gif' border='0' alt='Edit record'>";
>
> echo "<table border='2'>";
> echo "<td>id</td>";
> echo "<td>Lowerval</td>";
> echo "<td>Upperval</td>";
> echo "<td>Result</td></tr>";
>
> if($_POST["mode"] == "Update")
> {
> for ($i=0; $i<count($_POST[id]); $i++)
> {
> $post1 = $_POST[f2][$i];
> $post2 = $_POST[f3][$i];
> $post3 = $_POST[f4][$i];
> $post0 = $_POST[f1][$i];
> mysql_query ("UPDATE fig_lookup SET
> lowerval='$post1',upperval='$post2',result='$post3' WHERE id=$post0 ");
>
> }
> }
>
> while ($l = mysql_fetch_array($resulta, MYSQL_ASSOC))
> { ?>
> <tr>
> <td><input type="text" name="f1[]" value="<?= $l["id"]?>"></td>
> <td><input type="text" name="f2[]" value="<?= $l["lowerval"]?>"></td>
> <td><input type="text" name="f3[]" value="<?= $l["upperval"]?>"></td>
> <td><input type="text" name="f4[]" value="<?=
> $l["result"]?>"></td></tr>
> <?
> }
> echo "</tr></table>";
> echo "$post1";
> ?>
> <input type='submit' name='mode' value='Update'>
>
> </form>
> </HTML>
>
> http://nana46.coconia.net/test4.php

I think your problem is in this line:

for ($i=0; $i<count($_POST[id]); $i++)

Looking at your form, you have no input element called 'id', so count
is likely always zero and the loop never gets executed. Even if you
did have an input called 'id', you should have quotes around it inside
the [].

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация