Please help what is missing here i cannot get the data of row that I check on the checkbox?

<?
include("connect.php");
include("home_order.php");



 echo "<div><table border=0 cellspacing='15' align=center id=table1>
        <tr>

            <th>Title</th>
            <th>Price</th>


        </tr>";


$code = $row['Code'];   
$getcheck=$_GET['check'];
    if ($getcheck){

$result= mysql_query("SELECT * FROM books where Code='$code'");
 while($row = mysql_fetch_array($result)) {

 echo "<td align=center>".$row['Title']."</td>";
 echo "<td align=center>".$row['Price']."</td>";


 }}
 echo"</table>";
 ?>

Do you get any error messages? If yes post them here.

Also display the query and check it in phpmyadmin (or post it here). Change your code to something like:

$query = "SELECT * FROM books where Code='$code'";
// this will display the query so you can check it
die($query);
$result= mysql_query($query);

I dont get error message. I cant get the selected row of the checkbox and display it.do you know what should I do.# Heading Here #

I dont get error message. I cant get the selected row of the checkbox and display it.do you know what should I do.

In other word I would like to display multiple rows using checkbox I hope you get it thanks

Just to be sure: You have a table where each row represent a code and each row has a checkbox. When user selects some checkboxes you would like to diplays information for selected rows based on code. Did I get it right?

It would also help if you post the whole script that displays the table with checkboxes. And use formating in the editor (i.e. select the code and click on the Code button).

yes thats right the i have a table.and it has database sql phpmyadmin. you know..I only want display the rows of checked checkboxes.

<?
    include("connect.php");

    echo"<form method=GET action=order.php>";
    echo"<center><img src=top.png></center>";

echo"<link rel=stylesheet type=text/css href=design.css />";

$result= mysql_query("SELECT * FROM books");

 echo "<div><table border=0 cellspacing='15' align=center id=home_order>
        <tr>
            <th>Code</th>
            <th>Title</th>
            <th>Price</th>
            <th>Stock</th>

        </tr>";

while($row = mysql_fetch_array($result)) {  



 echo "<tr><td align=center>".$row['Code']."</td>";
 echo "<td align=center>".$row['Title']."</td>";
 echo "<td align=center>".$row['Price']."</td>";
 echo "<td align=center>".$row['Stock']."</td>";
 echo"<td align=center>"."<input type=checkbox name=check >"."</td>";


                                     }  


 echo"</table></div>";

echo"<table border=0 cellspacing='15' align=center  >";
 echo"<td align=center>"."<input type=SUBMIT>"."</td>";

 ?>

Here you have your main file and order.php file. Read the comments since most of explanations are there. Main thing is that checkbox name attribute was changed to an array and value was added to each checkbox so you know which codes were selected. I assumed that code is an integer. If it is a string then you must add single quotes otherwise you will get db error.

This is your table with checkboxes:

<?php
// I have wrapped all HTML attributes in double quotes so you do not run into problems

// added html, head and body tags
echo '<html>';

// this line goes to head section
echo '<head><link rel="stylesheet" type="text/css" href="design.css" /></head>';

include("connect.php");

echo '<body>';
echo '<form method="GET" action="order.php">';
echo '<center><img src="top.png"></center>';

$result= mysql_query("SELECT * FROM books");

echo '<div><table border="0" cellspacing="15" align="center" id="home_orde"r>
<tr>
<th>Code</th>
<th>Title</th>
<th>Price</th>
<th>Stock</th>
</tr>';

while($row = mysql_fetch_array($result)) {

    echo "<tr><td align=center>" . $row['code'] . "</td>";
    echo "<td align=center>" . $row['Title'] . "</td>";
    echo "<td align=center>" . $row['Price'] . "</td>";
    echo "<td align=center>" . $row['Stock'] . "</td>";

    // I have changed the name of checkbox to check[] array and added a value
    // that equals the code, so you know which checkbox was selected
    // I have also wrapped HTML attributes in double quotes
    echo '<td align=center><input type="checkbox" name="check[]" value="';
    echo $row['code'] . '" ></td>';
}
echo"</table></div>";
echo"<table border=0 cellspacing='15' align=center >";
echo"<td align=center>"."<input type=SUBMIT>"."</td>";
echo '</body></html>';
?>

This is order.php:

<?php
// if there were any checkboxes selected, they will be returned as an array
// of selected codes, if no checkboxes were selected, the array will not be set
// this is why you first check whether the $_GET['check'] array is set an not empty
if(isset($_GET['check']) and !empty($_GET['check'])) {

    // you can use print_r function to display the contents of array for debugging
    // print_r($_GET['check']);

    // from values in $_GET['check'] array create a string of codes, separated
    //  with commas that willserve as an IN condition for sql query
    // see implode manual on php.net
    $code_list = implode(',', $_GET['check']);

    // construct your query
    $query = "SELECT * FROM books where code IN ($code_list)";

    // you can display your query for debugging
    // die($query);

    $result= mysql_query($query);

    // begin table and table header
    echo "<div><table border=0 cellspacing='15' align=center id=table1><tr>

    <th>Title</th>
    <th>Price</th>
    </tr>";

    // display rows
    while($row = mysql_fetch_array($result)) {

        echo "<td align=center>".$row['Title']."</td>";
        echo "<td align=center>".$row['Price']."</td>";
    }

    // end table
    echo '</table>';

// if $_GET['check'] array is not set or is empty display error message (or do
// whatever you think is appropriate)
} else {

    echo 'Sorry, no checkboxes were selected.';
}
?>

Thank you for your very generous response but its still not displaying the row that has been check
there is a warning...

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\xampp\onlinebookstore\order.php on line 23
this would be line 23: while($row = mysql_fetch_array($result)) {
what do you think is wrong?

The following line is returning false instead of a resource (ponter to rows):

$result= mysql_query($query);

This means that there is an error in the query in order.php. You have to display the query and post it here. Uncoment the line that says:

// die($query);

refresh the page and post the output (your query);

Notice: Undefined variable: code in C:\xampp\htdocs\xampp\onlinebookstore\order.php on line 13
SELECT * FROM books where Code IN ()
this is the line 13:$query = "SELECT * FROM books where Code IN ($code_list)";

i think I need to declare first $code_list?
$code_list=$row['Code'];
am I rightI think I'm not haha

$code_list is a string of codes and should get constructed from the $_GET['check'] array by implode function. So we have to check what the array is. Uncomment the following line in order.php:

// print_r($_GET['check']);

and post the output (firstselect a fewcheckboxes).

Array ( [0] =>
Notice: Undefined index: code in C:\xampp\htdocs\xampp\onlinebookstore\home_order.php on line 28
) SELECT * FROM books where Code IN (
Notice: Undefined index: code in C:\xampp\htdocs\xampp\onlinebookstore\home_order.php on line 28
)
that waht it says. and line 28 is just: }

So the error seems to come from previous script. Can you post both scripts (the one with the table and the order.php) and tell me what is the name of the first script.

the first script is the same as what you post earlier:

home_order.php is the file name

<?php
// I have wrapped all HTML attributes in double quotes so you do not run into problems
// added html, head and body tags
echo '<html>';
// this line goes to head section
echo '<head><link rel="stylesheet" type="text/css" href="design.css" /></head>';
include("connect.php");
echo '<body>';
echo '<form method="GET" action="order.php">';
echo '<center><img src="top.png"></center>';
$result= mysql_query("SELECT * FROM books");
echo '<div><table border="0" cellspacing="15" align="center" id="home_orde"r>
<tr>
<th>Code</th>
<th>Title</th>
<th>Price</th>
<th>Stock</th>
</tr>';
while($row = mysql_fetch_array($result)) {
    echo "<tr><td align=center>" . $row['Code'] . "</td>";
    echo "<td align=center>" . $row['Title'] . "</td>";
    echo "<td align=center>" . $row['Price'] . "</td>";
    echo "<td align=center>" . $row['Stock'] . "</td>";
    // I have changed the name of checkbox to check[] array and added a value
    // that equals the code, so you know which checkbox was selected
    // I have also wrapped HTML attributes in double quotes
    echo '<td align=center><input type="checkbox" name="check[]" value="';
    echo $row['code'] . '" ></td>';
}
echo"</table></div>";
echo"<table border=0 cellspacing='15' align=center >";
echo"<td align=center>"."<input type=SUBMIT>"."</td>";
echo '</body></html>';
?>

order.php:

<?php
// if there were any checkboxes selected, they will be returned as an array
// of selected codes, if no checkboxes were selected, the array will not be set
// this is why you first check whether the $_GET['check'] array is set an not empty
if(isset($_GET['check']) and !empty($_GET['check'])) {
    // you can use print_r function to display the contents of array for debugging
     print_r($_GET['check']);
    // from values in $_GET['check'] array create a string of codes, separated
    //  with commas that willserve as an IN condition for sql query
    // see implode manual on php.net
    $code_list = implode(',', $_GET['check']);
    // construct your query

    $query = "SELECT * FROM books where Code IN ($code_list)";
    // you can display your query for debugging
     die($query);

    $result= mysql_query($query);
    // begin table and table header
    echo "<div><table border=0 cellspacing='15' align=center id=table1><tr>
    <th>Title</th>
    <th>Price</th>
    </tr>";
    // display rows
    while($row = mysql_fetch_array($result)) {
        echo "<td align=center>".$row['Title']."</td>";
        echo "<td align=center>".$row['Price']."</td>";
    }
    // end table
    echo '</table>';
// if $_GET['check'] array is not set or is empty display error message (or do
// whatever you think is appropriate)
} else {
    echo 'Sorry, no checkboxes were selected.';
}
?>

The error is probably in home_order.php just before the end of while loop on line that says:

echo '<td align=center><input type="checkbox" name="check[]" value="';
echo $row['code'] . '" ></td>';

It should be:

echo $row['Code'] . '" ></td>';

It is better to use all small caps for field names otherwise the errors like that pop out (it was actually my error since I did not know the table structure).

ok.I change it already but the result is this:Array ( [0] => 1100 [1] => 1102 ) SELECT * FROM books where Code IN (1100,1102)

Comment out the lines you uncommented for debugging (they are there just for debugging):

die($query);

and

print_r($_GET['check']);

yes I did that already but it goes back from the first warning :Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\xampp\onlinebookstore\order.php on line 25
Title Price

i comment out it already but this what it displays :ok.I change it already but the result is this:Array ( [0] => 1100 [1] => 1102 ) SELECT * FROM books where Code IN (1100,1102)

I COMMENT IT OUT ALREADY BUT IT SAYS

Array ( [0] => 1100 [1] => 1102 ) SELECT * FROM books where Code IN (1100,1102)

SORRY THIS WHAT IT SAYS WHEN I COMMENT IT OUT:

\
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\xampp\onlinebookstore\order.php on line 25

Make sure the line print_r($_GET['check']); in order.php is commented like this:

// print_r($_GET['check']);

Go back to the page home_order.php, select some checkboxes and submit.

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\xampp\onlinebookstore\order.php on line 25
this show after I comment it out again

yeah I did that I go back home_order.php and select some boxes but that did not solve it..

Please uncomment the following line again and post the output:

// print_r($_GET['check']);

This array should contain values from checkboxes or an error message from the query.

Also do you use phpmyadmin or other client to accesss the database? Try to test the following query and post what it returns:

SELECT * FROM books where Code IN (1100,1102)

Parse error: syntax error, unexpected '>' in C:\xampp\htdocs\xampp\onlinebookstore\order.php on line 19

when did test the query you said thats the warning tells.

bty.I use phpmyadmin

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.