...

View Full Version : Multiple if variable =x update, updating all fields



Jenny Dithe
11-17-2010, 03:22 PM
Hi,

I have a checkbox form which is sent to my insert page, which looks like:


if ($_REQUEST['product1'] !=''){
$sql="UPDATE products SET product1 ='requested'
WHERE client='{$_SESSION['client']}'";

mysql_query($sql,$con) or die(mysql_error());}

if ($_REQUEST['product2'] !=''){
$sql="UPDATE products SET product2 ='requested'
WHERE client='{$_SESSION['client']}'";

mysql_query($sql,$con) or die(mysql_error());}

if ($_REQUEST['product3'] !=''){
$sql="UPDATE products SET product3 ='requested'
WHERE client='{$_SESSION['client']}'";

mysql_query($sql,$con) or die(mysql_error());}


But if only product2 is selected, all three still update as requested. I have no idea what is going wrong.

SB65
11-17-2010, 06:41 PM
Hard to tell from that code what the issue might be.

A starting point might be to point your form at this code:


<?php
// ------------------------------------
print '$_POST array';
// ------------------------------------
print "<BR/>";
// ------------------------------------
foreach ( $_POST as $key => $value ) {
print $key . " " . "=" . " " . $value;
print "<BR/>";
}
// ------------------------------------
print "<BR/>";
// ------------------------------------
print "<BR/>";
// ------------------------------------
print '$_GET array';
// ------------------------------------
print "<BR/>";
// ------------------------------------
foreach ( $_GET as $key => $value ) {
print $key . " " . "=" . " " . $value;
print "<BR/>";
}
// ------------------------------------
print "<BR/>";
// ------------------------------------
print "<BR/>";
// ------------------------------------
print '$_REQUEST array';
// ------------------------------------
print "<BR/>";
// ------------------------------------
foreach ( $_REQUEST as $key => $value ) {
print $key . " " . "=" . " " . $value;
print "<BR/>";
}
// ------------------------------------
?>

which will print out all the data sent by the form. From this you should be able to establish what the values of all your variables are, and hence identify the problem.

Jenny Dithe
11-18-2010, 07:51 AM
Thank you, managed to solve it, that got me on the right track.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum