Ok, I consider the air cleared of the personal mess. What say you we get back to trying to help you?
So far what you have posted in terms of code produces output inconsistent with your code. That is why were asking for the exact code you are having problems with. This query:
Code: Select all
update e9 set afm='789' and surname='321' where afm='321' and surname='321'
should look like
Code: Select all
update e9 set afm='789', surname='321' where afm='321' and surname='321'
But the code you posted before shows that it will create a query that does not look anything like that query. So I am guessing there is an issue with the UPDATE syntax as opposed to the insert syntax. Here is the insert code you posted:
Code: Select all
<?php
if ( $_POST[submit] == 1) {
for($a = 0; $a <= 9; $a++) {
$afm = "afm" . $a;
$sql = "INSERT INTO database VALUES('" . $afm . "')";
$data = mysql_query($sql, $con);
}
}
?>
For clarity I would say try this...
Code: Select all
<?php
if ( $_POST[submit] == 1)
{
for($a = 0; $a <= 9; $a++)
{
$afm = 'afm' . $a;
$sql = "INSERT INTO database VALUES('$afm')";
$data = mysql_query($sql, $con) or die('Error in ' . $sql . ': ' . mysql_error());
}
}
?>
Your update code is:
Code: Select all
<?php
If ( $_POST[submit] == 2) {
for($a = 0; $a <= 9; $a++) {
$afm = "afm" . $a;
$oldafm = "oldafm" . $a;
$sql = "update e9 set afm='" . mysql_real_escape_string($_POST[$afm]) . "' where afm='" . mysql_real_escape_string($_POST[$oldafm]) . "'";
$data = mysql_query($sql, $con);
}
}
?>
I had asked you to run this:
Code: Select all
<?php
if (isset($_POST['submit']) && $_POST['submit'] == 2) {
for ($a = 0; $a <= 9; $a++) {
$afm = 'afm' . $a;
$oldafm = 'oldafm' . $a;
$sql = "update e9 set afm='" . mysql_real_escape_string($_POST[$afm]) . "' where afm='" . mysql_real_escape_string($_POST[$oldafm]) . "'";
// Echo out your SQL query to see what the database is seeing
echo '<p>For a at position ' . $a . ' we have afm set to ' . $afm . ' and oldfm set to ' . $oldfm . '. Now for the SQL:<br />' . $sql . '</p>';
//$data = mysql_query($sql, $con);
}
}
?>
Can you do that and post back please?
This is the form code you posted:
Code: Select all
<?php
If ($_POST[submit] >=1) {
for($a = 0; $a <= 9; $a++) {
echo "<input type='hidden' name='oldafm" . $a ."' value='" . $_POST[$afm] . "'>";
}
}
?>
That might cause problems if the $afm var experienced problems. Is there not way to combine this logic into a single conditional check?
This is the table output code you posted:
Code: Select all
<?php
echo "<td align='center' width='188' style='border-style: solid; border-width: 1px' bgcolor='#339966'><input type='text' name='afm" . $a . "' value='" . $_POST[$afm] . "'></td>";
?>
I notice that you are using the same $_POST[$afm] snippet throughout this script. Why not assign that to a var and use the var? It might be a little easier to follow, expecially since you are not checking
isset() on that POST var anywhere.