0

I need to run this sql query, which give me a list of Id and Dates I want to click each result and take with me the Id value to the next form I wrote this query above but i see in the debager that the hidden ID get his value but not pass to the next form I think i have a problem with the submit() . where should I put him ?

function ShowAllCarts($user_email) {

    $connB = new ProductDAO();
    $connB->Connect();
    $pro_query = "SELECT * FROM Cart WHERE `Email`='$user_email';";
    $db_result = $connB->ExecSQL($pro_query);

    $html_result = '<div data-role="content"> <ul data-role="listview" data-theme="b"> ';
    $html_result .= '<form action="PreviouscartProduct.php" method="POST"/>';

    while($row_array = $db_result->fetch_array(MYSQLI_ASSOC))
    {
        $Id= $row_array['Id'];
        $Date= $row_array['Date'];

        //$html_result //
        $html_result .="<li><a href='PreviouscartProduct.php'>Cart number: $Id from Date: $Date><input type='hidden' name='Id' value'<?=$Id?>'</input></a></li>'";
        $html_result .= '<a onclick="this.form.submit();" </a>;
    }

        $html_result .= '</form>';  
        $html_result .= ' </ul> </div>';

    $connB->Disconnect();
    return $html_result;
}

//display all carts
$func_result = ShowAllCarts($Email);
1
  • 2
    Please, use punctuation in your text, it is hard to read. Commented Sep 3, 2012 at 21:41

2 Answers 2

1

You need to use a checkbox element:

$html_result .="<li>"
              ."<checkbox name='cartItem[$Id]' value='$Date'>"
              . "Cart number: $Id from Date: $Date"
              . "</li>'"
              ;

Then, in PreviouscartProduct.php, you'd itera over cartItem:

$cartItems = $_POST[ 'cartItem' ];
foreach( $cartItems as $id => $date ) {
 ... do something ...
}

In case you'd like to take exactly one item, why not use this:

$html_result .="<li>"
              . "<a href='PreviouscartProduct.php?cartID=$Id&date=$Date'>"
              . "Cart number: $Id from Date: $Date"
              . "</a>"
              . "</li>'"
              ;
Sign up to request clarification or add additional context in comments.

1 Comment

thank you for your answer when i tried the checkbox like you write here it doesn't take the result line as a link or as a box to be checked , just a simple line with charctares
0

There's a bunch of HTML syntax errors in this, check the output in a validator

For a start, your opening a tag doesn't close after this.form.submit();, it should read

$html_result .= '<a onclick="this.form.submit();">Anchor Text Here</a>';

Edit : the anchor element needs to reference the form. Give the form element a name attribute and use something like

onclick="document.nameattributehere.submit();return false"

on the link.

End edit.

Also, in the line above, you're already using the PHP parser when you get to the value attribute of your input, so there is no need for the

<?= and ?>

Finally, in the same tag, you don't need a closing input tag

</input>

Just close the opening tag with

/>

That's just glancing, run the validator for other errors and I'm sure the problem will be clearer.

3 Comments

Also, the the nesting of the <ul> and <form> tags are incorrect
thank you for your answare i treied it , the post of the Id still doesn't happen
I would go with SteAp's answer of just using the links with a querystring. Just tidy up your HTML, it's hard to help when it's such a mess.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.