feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I figured out why the SQL string was not working -- it's because I was starting the for loop with 0 instead of 1, which would get first_name0, last_name0, etc... instead of the values of first_name1, last_name1, etc...
Which caused the SQL error of:
Code: Select all
Error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '0' at line 1
This was after commenting out all the connection code and just echoing the sql string being generated.
Now, I have a new issue and I can't see any reason why it's doing this but the $_REQUEST for my hidden fields is returning with NULL
Code: Select all
$my_sql_string2 = "UPDATE guest_login SET";
for ($j=1; $j<=$i-1; $j++)
{
$my_sql_string2 .= " FIRST_NAME= '{$_REQUEST['first_name'.$j]}', LAST_NAME= '{$_REQUEST['last_name'.$j]}', EMAIL_ADDRESS= '{$_REQUEST['email_address'.$j]}', WHAT_U_LIKED= '{$_REQUEST['what_u_liked'.$j]}'";
}
$my_sql_string3 = " WHERE ";
for ($k=1; $k<=$i-1; $k++)
{
$my_sql_string4 .= "FIRST_NAME='{$_REQUEST['hidden_first_name'.$j]}' AND LAST_NAME= '{$_REQUEST['hidden_last_name'.$j]}' AND EMAIL_ADDRESS='{$_REQUEST['hidden_email_address'.$j]}' AND WHAT_U_LIKED='{$_REQUEST['hidden_what_u_liked'.$j]}'";
}
$my_sql_string2 .= $my_sql_string3;
$my_sql_string2 .= $my_sql_string4;
echo $my_sql_string2 . "This is your sql query";
The result returns NULL values for the hidden fields requested:
Code: Select all
UPDATE guest_login SET FIRST_NAME= 'bob2', LAST_NAME= 'newhart', EMAIL_ADDRESS= 'bob@newhart.com', WHAT_U_LIKED= 'yes' FIRST_NAME= 'bob3', LAST_NAME= 'newhart', EMAIL_ADDRESS= 'bob2@newhart.com', WHAT_U_LIKED= 'yes2' FIRST_NAME= 'bob4', LAST_NAME= 'newhart', EMAIL_ADDRESS= 'bob3@newhart.com', WHAT_U_LIKED= 'yes' WHERE FIRST_NAME='' AND LAST_NAME= '' AND EMAIL_ADDRESS='' AND WHAT_U_LIKED=''FIRST_NAME='' AND LAST_NAME= '' AND EMAIL_ADDRESS='' AND WHAT_U_LIKED=''FIRST_NAME='' AND LAST_NAME= '' AND EMAIL_ADDRESS='' AND WHAT_U_LIKED=''
When clearly the View Source on the previous page is:
Code: Select all
<form action='welcome3.php' method='post'><input type='textfield' name='pre_intials1' value='Mr.'><input type='textfield' name='first_name1' value='bob'><input type='textfield' name='last_name1' value='newhart'><input type='textfield' name='email_address1' value='bob@newhart.com'><input type='textfield' name='what_u_liked1' value='yes'><input type='hidden' name='hidden_pre_intials1' value='Mr.'><input type='hidden' name='hidden_first_name1' value='bob'><input type='hidden' name='hidden_last_name1' value='newhart'><input type='hidden' name='hidden_email_address1' value='bob@newhart.com'><input type='hidden' name='hidden_what_u_liked1' value='yes'><input type='textfield' name='pre_intials2' value='Mr.'><input type='textfield' name='first_name2' value='bob2'><input type='textfield' name='last_name2' value='newhart'><input type='textfield' name='email_address2' value='bob2@newhart.com'><input type='textfield' name='what_u_liked2' value='yes2'><input type='hidden' name='hidden_pre_intials2' value='Mr.'><input type='hidden' name='hidden_first_name2' value='bob2'><input type='hidden' name='hidden_last_name2' value='newhart'><input type='hidden' name='hidden_email_address2' value='bob2@newhart.com'><input type='hidden' name='hidden_what_u_liked2' value='yes2'><input type='textfield' name='pre_intials3' value='Mr.'><input type='textfield' name='first_name3' value='bob3'><input type='textfield' name='last_name3' value='newhart'><input type='textfield' name='email_address3' value='bob3@newhart.com'><input type='textfield' name='what_u_liked3' value='yes'><input type='hidden' name='hidden_pre_intials3' value='Mr.'><input type='hidden' name='hidden_first_name3' value='bob3'><input type='hidden' name='hidden_last_name3' value='newhart'><input type='hidden' name='hidden_email_address3' value='bob3@newhart.com'><input type='hidden' name='hidden_what_u_liked3' value='yes'><input type='hidden' name='my_i' value='4'><input type='submit' name='update_button' value='Update Record'></form>
Clearly there are values in the hidden fields but the $_REQUEST is not capturing them, why?
I just noticed another problem with the SQL query while checking out the preview, there is no commas between the first SET of fields and the generated sets afterwards. Plus there are no ANDs between the first set of wheres and the generated where values afterwards.
I guess I'm going to have to create for loops within each other, but first I have to figure out why the hidden fields are returning NULL values.
Thanks in advance.
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]