By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

how to POST checkbox values to php program from database?

P: 1
I HAVE TO POST DATA FROM 1 PHP FILE TO ANOTHER VIA POST METHOD USING CHECKBOX.BUT WHEN I CHECK THE BOXES THEN IN OTHER PHP FILE, THERE RETRIEVES ONLY LAST CHECKBOX VALUE RATHER THAN ALL...


TIS IS FIRST PHP FILE

COMPARE.PHP

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con=mysql_connect("localhost","root","pass");
  3. if(!$con) echo "not connected";
  4. mysql_select_db("laptop",$con);
  5. $r=mysql_query("SELECT * FROM gallary ");
  6. echo '<form action="compare1.php" method="POST">';
  7. while($row=mysql_fetch_array($r))
  8. {    
  9.  
  10.  
  11.     echo " BRAND:       ".$row['brand'];
  12.     echo"</br>";
  13.     echo "MODEL:         ".$row['model'];
  14.     echo"</br>";
  15.     echo "HARDDISC:    ".$row['hdd'];
  16.     echo"</br>";
  17.     echo "RAM :       ".$row['ram'];
  18.     echo"</br>";
  19.     echo "SCREEN SIZE:     ".$row['screen'];
  20.     echo"</br>";
  21.     echo "LAPTOP PRICE:   ".$row['price'];
  22.     echo"</br>";
  23.     echo "PROCESSOR:    ".$row['proccesor'];
  24.     echo"</br>";
  25.     echo " <img src= '".$row['image']." ' height=320 width=200>";
  26.     echo"</br>";
  27.     echo"<b>compare<b>";
  28.  
  29.     //$p_id=$row['product_id'];
  30.     echo'<input type="checkbox"  name="checkbox[]" value='.$row[product_id].'>';///////here i selected checkbox array
  31.     echo"</br>";
  32.  
  33.  
  34.     echo"</br>";
  35.  
  36. }
  37. echo '<input type="submit" name="submit" value="submit" >';
  38. echo'</form>';
  39. ?>


and linked php program is

compare1.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con=mysql_connect("localhost","root","pass");
  3. if(!$con)
  4. echo" not coonected";
  5. else "connected";
  6. mysql_select_db("laptop",$con);
  7. echo.$_post['checkbox'];
  8. $product_id=$_POST['checkbox'];
  9. if(isset($_POST['submit']))
  10. {
  11. for ($i=0;$i<=count($_POST['checkbox']);$i++)
  12.  {
  13. $product_id=$_POST['checkbox'];
  14. echo $product_id;
  15. $result1=mysql_query("SELECT * FROM gallary WHERE product_id=$product_id");
  16. while($row1=mysql_fetch_array($result1))
  17. {
  18. echo " BRAND:       ".$row1['brand'];
  19. echo"</br>";
  20. echo "MODEL:         ".$row1['model'];
  21. echo"</br>";
  22. echo "HARDDISC:    ".$row1['hdd'];
  23. echo"</br>";
  24. echo "RAM :       ".$row1['ram'];
  25. echo"</br>";
  26. echo "SCREEN SIZE:     ".$row1['screen'];
  27. echo"</br>";
  28. echo "LAPTOP PRICE:   ".$row1['price'];
  29. echo"</br>";
  30. echo "PROCESSOR:    ".$row1['proccesor'];
  31. echo"</br>";
  32. echo " <img src= ' ".$row1['image']." ' height=320 width=200>";
  33.  
  34. }
  35. }
  36.  
  37. }
  38. ?>


it is giving an error
thanx....
Mar 24 '12 #1
Share this Question
Share on Google+
2 Replies


helimeef
P: 77
Put some code tags around this so that it's easier to debug. What exactly is the problem?
Mar 25 '12 #2

PsychoCoder
Expert Mod 100+
P: 465
You say "It gives an error", well show us exactly what the error message you're getting.
Mar 26 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.