Page 2 of 2

Posted: Thu Mar 15, 2007 12:02 pm
by UrButtFullOfArr0ws
I lost my temper... im awfully sorry about that and i know he's just trying to help but that's not the right way to ask for some information even if it's for helping myself. :oops: :?
If he thought the information i ommited was relevant he might of had mentioned a reason and i would be glad to give back an answer. But when i said that i didn't think it could have anything to do with my problem he just thought that i don't want or/and need help.
And yes i want his help, actually i'm grateful for any help i could get with it as i've been fighting on this one for like 3 days. He wants to think it's a syntax problem? Good! But i already answered that i checked the syntax like 1000 times and to no avail. Still, his best answer was "Ok, pointless. Good Luck."
Correct me if i'm wrong but that looks like rudeness to me. Quote again... I wrote "I didn't copy-paste all of it"... he wrote "of course you didn't".
What's that supposed to mean?

Posted: Thu Mar 15, 2007 1:57 pm
by RobertGonzalez
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.

Posted: Thu Mar 15, 2007 3:12 pm
by UrButtFullOfArr0ws
Sure :D
OK im gonna try that and get back...

Btw i made a typo... "INSERT INTO database VALUES('" . $afm . "')"" : supposed to be $_POST[$afm] again instead of $afm xD
It's not like that in the actual code :)

Posted: Thu Mar 15, 2007 3:50 pm
by UrButtFullOfArr0ws
Ok replacing the "and" in the update query with " , " seemed to solve that... :(
At first i put "and" becouse i did the query in console and it worked just fine...Yet i'm feeling stupid 8O becouse i checked for syntax mistakes.
But i got another question: Why was only afm, the first column, affected by this and none of the other columns?
Thx a lot btw :D :D

Posted: Thu Mar 15, 2007 4:35 pm
by RobertGonzalez
The only thing I can think of is that somehow the syntax was correct to a degree and the server accepted it up to a point, then terminated it.

Posted: Thu Mar 15, 2007 4:39 pm
by UrButtFullOfArr0ws
I see. That's probably why the console worked while PHP didn't work correctly. Thx :wink: