Jump to content


Check out our Community Blogs

makamo66

Member Since 12 May 2010
Offline Last Active Jun 22 2010 05:15 PM
-----

Topics I've Started

MySQL Query Using SET and IN Clauses with an Array

04 June 2010 - 04:12 PM

I am trying to do an UPDATE with the SET clause:

UPDATE temp_cart SET quantity IN (7, 6) WHERE product_id IN ( 2, 4 ) AND user_id = '" . $_SESSION['UID'] . "'

I know that SET is used only with an equal sign like this:

UPDATE temp_cart SET quantity = 6 WHERE product_id IN ( 2, 4 ) AND user_id = '" . $_SESSION['UID'] . "'

However, I need a way to set the quantity column to more than one value so I want to use the IN clause. I can't just run the query twice because in reality the query is using variables with imploded values and not simply the integers shown here. The query actually looks like this:

$id_nums = implode(", ", $productId2);
$qty_nums = implode(", ", $qtyBox2);
UPDATE temp_cart SET quantity IN ($qty_nums) WHERE product_id IN ($id_nums) AND user_id = '" . $_SESSION['UID'] . "'

I am using MySQL version 5.0. The error message I get is fairly non-descript. It is merely:

Error occured while inserting values into table: 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 'IN (7, 6) WHERE product_id IN ( 2, 4 ) AND user_id = '20100604164333'' at line 1

SQL Query Using SET and IN Clauses with an Array

04 June 2010 - 04:05 PM

I am trying to do an UPDATE with the SET clause:

UPDATE temp_cart SET quantity IN (7, 6) WHERE product_id IN ( 2, 4 ) AND user_id = '" . $_SESSION['UID'] . "'

I know that SET is used only with an equal sign like this:

UPDATE temp_cart SET quantity = 6 WHERE product_id IN ( 2, 4 ) AND user_id = '" . $_SESSION['UID'] . "'

However, I need a way to set the quantity column to more than one value so I want to use the IN clause. I can't just run the query twice because in reality the query is using variables with imploded values and not simply the integers shown here. The query actually looks like this:

$id_nums = implode(", ", $productId2);
$qty_nums = implode(", ", $qtyBox2);
UPDATE temp_cart SET quantity IN ($qty_nums) WHERE product_id IN ($id_nums) AND user_id = '" . $_SESSION['UID'] . "'

I am using MySQL version 5.0. The error message I get is fairly non-descript. It is merely:

Error occured while inserting values into table: 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 'IN (7, 6) WHERE product_id IN ( 2, 4 ) AND user_id = '20100604164333'' at line 1

Writing a simple statement with an index

21 May 2010 - 04:29 PM

I can write this and get the right results:

if ( $_SESSION['addId'] == 'add[4]' )
$productId = 1;
if ( $_SESSION['addId'] == 'add[5]' )
$productId = 2;
if ( $_SESSION['addId'] == 'add[6]' )
$productId = 3;

But if I try to streamline it by writing it this way, it doesn't work:

if ( $_SESSION['addId'] == 'add[$i]' )
$productId = $i;

I think the two methods should be equivalent so why doesn't the second way work?

Page Redirect after Error Message is Output to the Browser

19 May 2010 - 03:28 PM

I know that you aren't supposed to output anything to the browser before using the header location function but what if you need to show an error message? If there is an error, for example, an invalid email address, then I want to show an error message and go back to the form submission page. After all of the errors have been corrected, I want to redirect to the next page. However since I already sent an error message, I can't send a header. Is there a way to do this without resorting to javascript?

Can't Override the Default Value of the Textbox

18 May 2010 - 01:35 PM

I have an html textbox that was written like this:

echo "<b>Quantity:</b> <input type=\"text\" name=\"qtyBox\" value=\"1\" size=\"1\" />";

When the form is submitted I collect the value of the textbox like this:

$_SESSION['qtyBox'] = $_POST['qtyBox'];
$qtyBox = $_SESSION['qtyBox'];
echo $qtyBox;

The problem is that no matter what I type into the text box, the value is echoed out as 1. If I leave the value blank and type a number into the box, I get a blank too.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download