mikebyrne Posted January 28, 2008 Share Posted January 28, 2008 I want an order processed when a checkbox is "checked" and the user clicks on the proceed button The code I have so far is: <form> <!-- logo start --> <div id="container"> <div class="padTop28"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- logo finish --> <!-- menu start --> <div id="container"> <div id="menu1"> <div id="menu_on"><!-- --></div> <div id="menu_text_on"><a href="../admin_files/new.php" class="black_on">Order</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../sales/sales.php" class="black">Sales</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../item/list.php" class="black">Edit item</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../shipping/current.php" class="black">Postage fee</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add User</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add Product</a></div> <div id="menu_space1"><!-- --></div> </div> <div class="clr"><!-- --></div> <div class="clr"> <!-- --> </div> <div class="padTop5"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div id="dotted"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div class="padTop5"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div id="menu2"> <div id="menu_hide"> <!-- --> </div> <div id="menu_text_on"><a href="../admin_files/new.php" class="black_on">New orders</a></div> <div id="menu_space2"> <!-- --> </div> <div id="menu_text_off"><a href="../admin_files/Unprocessed.php" class="black">Unprocessed orders</a></div> <div id="menu_space2"> <!-- --> </div> <div id="menu_text_off"><a href="../admin_files/completed.php" class="black">Completed orders</a></div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <div class="padTop38"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- menu finish --> <!-- top start --> <div id="container"> <div id="line"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <div id="containerBg1"> <div class="padTop15"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- top finish --> <!-- data title start --> <div id="containerBg2"> <div class="padTop2"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div class="titleBox"> <table width="850" border="0" cellspacing="0" cellpadding="0"> <tr align="left"> <td width="64"> </td> <td width="33"> </td> <td width="86"><a href="#">order no.</a></td> <td width="63"><a href="#">date</a></td> <td width="240"><a href="#">customer name</a></td> <td width="172"><a href="#">e-mail</a></td> <td width="64" align="right"><a href="#">amount</a></td> <td width="23"> </td> <td width="138"><a href="#">shipping method</a></td> </tr> </table> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data title finish --> <!-- 1px space start --> <div id="containerBg1"> <div class="padTop1"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- 1px space finish --> <!-- data top start --> <div id="containerBg3"> <div class="padTop1"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data top finish --> <!-- data content start --> <div id="containerBg4"> <!-- data start --> <div class="padTop11"> <!-- --> </div> <div class="clr"> <table width="850" border="0" cellspacing="0" cellpadding="0"> <?php // let's get some data include('adminconnect.php'); $sql = mysql_query("SELECT OrderNo, Orderdate, Custname, Amount, Shippingmet FROM admin WHERE Orderdate = DATE_FORMAT(now(),'%y/%m/%d')"); while( $row = mysql_fetch_array($sql) ) { // loop through and display ?> <tr align="left"> <td width="33"> </td> <td><input type = "checkbox" name="checkbox" value="checked"></td> <td width="33"> </td> <td width="82"><a href="javascript:openWindow('popup_detail.html', 'NewWindow', 615, 600)" class="black"><?php echo $row['OrderNo'];?></a></td> <td width="61" align="center"><?php echo $row['Orderdate'];?></td> <td width="230" align="Left"><?php echo $row['Custname'];?></td> <td width="170" align="center"><?php echo $row['Trackno'];?></td> <td width="56" align="right"><?php echo $row['Amount'];?></td> <td width="21"> </td> <td width="136" align="center"><?php echo $row['Shippingmet'];?></td> </tr> <? } ?> </table> <!-- data finish --> <!-- --> </div> <div id="btn"> <div id="btnL"><img src="../Admin_files/btn_delete.gif" alt="delete" width="73" height="23" /></div> <div id="btnSpace"> <!-- --> </div> <div id="btnR"><a href="processed.php"><img src="../Admin_files/btn_process.gif" alt="process" width="73" height="23" border="0" /></a></div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <div class="padTop16"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- btn finish --> </div> <div class="clr"> <!-- --> </div> <!-- data content finish --> <!-- data btm start --> <div id="containerBg3"> <div class="padTop1"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data btm finish --> <!-- btm start --> <div id="containerBg1"> <div class="padTop15"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <div id="container"> <div id="line"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <div class="padTop16"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- btm finish --> </form> And processed.php <?php include('adminconnect.php'); $tbl1 = 'admn'; $process=$_POST['checkbox']; if($process =="checked") { $sql2="INSERT INTO $tbl1(Ordercompleted)VALUES(1)"; } else { echo "Not checked"; } ?> Quote Link to comment Share on other sites More sharing options...
adam291086 Posted January 28, 2008 Share Posted January 28, 2008 you dont have any form action set. action="process.php" Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted January 28, 2008 Author Share Posted January 28, 2008 How would I word that? Also, does have my process button set to use a link affect things? Quote Link to comment Share on other sites More sharing options...
adam291086 Posted January 28, 2008 Share Posted January 28, 2008 well when you want to send a form you need to say how to submit it and where to submit it. At the moment you have <form> change it to <form action ="the processing page name" method="post"> I am not sure about the link for the process. I think it may have to be a submit button. I have never tired anything different. Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted January 28, 2008 Author Share Posted January 28, 2008 I've added <form action = "processed.php" method="post"> and <input type="submit" value="Process"> But code doesnt seem to work as it doesnt post a 1 to the orderscompleted field Quote Link to comment Share on other sites More sharing options...
adam291086 Posted January 28, 2008 Share Posted January 28, 2008 have you tried echoing $process in the processed.php page Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted January 28, 2008 Author Share Posted January 28, 2008 My page just seems to stay on the new.php page as opposed to going to processed.php the code for processed.php is now: <?php include('adminconnect.php'); $tbl1 = 'admn'; $process=$_POST['checkbox']; echo "Test" echo $process if($process =="checked") { $sql2="INSERT INTO $tbl1(Ordercompleted)VALUES(1)"; } else { echo "Not checked"; } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2008 Share Posted January 28, 2008 Amongst all that code I don't see where you actually define your form. Can you narrow your code down to the relevent parts and show us your form? Quote Link to comment Share on other sites More sharing options...
GameYin Posted January 28, 2008 Share Posted January 28, 2008 I would like to know what is in the adminconnect.php. Anyway I don't know if this maters but... $process=$_POST['checkbox']; should be $process = $_POST['checkbox']; Also if($process =="checked") I don't know what you are trying to say, your doing a comparison between these 2 to determine if the variable process is the same as ..."checked" but you have $process as $_POST['checkbox']; Try ending this statement also with a semicolon if($process =="checked")[color=red];[/color] This code seems very...weird for me. There is also room here for SQL injection. Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2008 Share Posted January 28, 2008 I would like to know what is in the adminconnect.php. Anyway I don't know if this maters but... $process=$_POST['checkbox']; should be $process = $_POST['checkbox']; The first piece of code is fine. $_POST["username_post"]); Also if($process =="checked") I don't know what you are trying to say, your doing a comparison between these 2 to determine if the variable process is the same as ..."checked" but you have $process as $_POST['checkbox']; This is a simple comparison to see if $process equals the string 'checked', perfectly valid, no need to change it. Try ending this statement also with a semicolon if($process =="checked")[color=red];[/color] This code seems very...weird for me. There is also room here for SQL injection. Ending this line with a semicolon would cause a syntax error. Quote Link to comment Share on other sites More sharing options...
GameYin Posted January 28, 2008 Share Posted January 28, 2008 Why would that be? Looks valid to me. Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted January 28, 2008 Author Share Posted January 28, 2008 The adminconnect file is <? $host="Localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="admin"; // Database name //Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); ?> What I want to achive with this code is when the checkbox is checked and the proceed button is pressed a 1 will appear in the relevent "Orderscompleted" field Quote Link to comment Share on other sites More sharing options...
GameYin Posted January 28, 2008 Share Posted January 28, 2008 If this adminconnect file isn't connecting it's because your database name is incorrect. Also this just annoys me, I don't know if it's incorrect, but lower the L in localhost. Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2008 Share Posted January 28, 2008 As I said, I don't see where your form is defined. Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted January 28, 2008 Author Share Posted January 28, 2008 I'll cut down my form <form> <form action = "processed.php" method="post"> <!-- --> </div> <div class="titleBox"> <table width="850" border="0" cellspacing="0" cellpadding="0"> <tr align="left"> <td width="64"> </td> <td width="33"> </td> <td width="86"><a href="#">order no.</a></td> <td width="63"><a href="#">date</a></td> <td width="240"><a href="#">customer name</a></td> <td width="172"><a href="#">e-mail</a></td> <td width="64" align="right"><a href="#">amount</a></td> <td width="23"> </td> <td width="138"><a href="#">shipping method</a></td> </tr> </table> </div> <div class="clr"> <!-- --> <table width="850" border="0" cellspacing="0" cellpadding="0"> <?php // let's get some data include('adminconnect.php'); $sql = mysql_query("SELECT OrderNo, Orderdate, Custname, Amount, Shippingmet FROM admin WHERE Orderdate = DATE_FORMAT(now(),'%y/%m/%d')"); while( $row = mysql_fetch_array($sql) ) { // loop through and display ?> <tr align="left"> <td width="33"> </td> <td><input type = "checkbox" name="checkbox" value="checked"></td> <td width="33"> </td> <td width="82"><a href="javascript:openWindow('popup_detail.html', 'NewWindow', 615, 600)" class="black"><?php echo $row['OrderNo'];?></a></td> <td width="61" align="center"><?php echo $row['Orderdate'];?></td> <td width="230" align="Left"><?php echo $row['Custname'];?></td> <td width="170" align="center"><?php echo $row['Trackno'];?></td> <td width="56" align="right"><?php echo $row['Amount'];?></td> <td width="21"> </td> <td width="136" align="center"><?php echo $row['Shippingmet'];?></td> </tr> <? } ?> </table> <!-- data finish --> <!-- --> </div> <div id="btn"> <div id="btnL"><img src="../Admin_files/btn_delete.gif" alt="delete" width="73" height="23" /></div> <div id="btnSpace"> <!-- --> <input type="submit" value="Process"> </form> Quote Link to comment Share on other sites More sharing options...
GameYin Posted January 28, 2008 Share Posted January 28, 2008 Well I don't see input fields. That's your problem. Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted January 28, 2008 Author Share Posted January 28, 2008 The records i need are generated by the php code along with the checkbox. There isnt a need for input fields in this case Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 28, 2008 Share Posted January 28, 2008 In your loop, you use the following code for a checkbox: <td><input type = "checkbox" name="checkbox" value="checked"></td> But, your checkboxs can't call have the same name. Use a unique id like so: <td><input type = "checkbox" name="<?php echo $row['OrderNo'];?>" value="checked"></td> Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2008 Share Posted January 28, 2008 The records i need are generated by the php code along with the checkbox. There isnt a need for input fields in this case In order for the checkbox values to be submitted to the next page you need a form. Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted January 28, 2008 Author Share Posted January 28, 2008 That would make more sense because i could have more than one record that needs to be checked!! Should I changed my SQL to something like : update admin set Ordercompleted = "1" where OrderNo = $row['OrderNo']; Not too sure how to word the SQL? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 28, 2008 Share Posted January 28, 2008 actually, I would use the following code for a checkbox: <td><input type = "checkbox" name="order_<?php echo $row['OrderNo'];?>" value="checked"></td> And then in processed.php: <?php include('adminconnect.php'); $tbl1 = 'admn'; foreach($_POST as $key=>$val){ if(substr($key,0,6) != 'order_') continue; //Skip other data $orderno = substr($key,6); if(!is_numeric($orderno)) continue; //Skip non-numeric order numbers $sql = "UPDATE $tbl1 SET Ordercompleted = 1 WHERE OrderNo= '{$orderno}'"; } ?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 28, 2008 Share Posted January 28, 2008 Coding is easier if you use an array: In the form <td><input type = "checkbox" name="order[<?php echo $row['OrderNo'];?>]" value="checked"></td> In processed.php <?php include('adminconnect.php'); $tbl1 = 'admn'; foreach($_POST['order'] as $orderno => $dmy){ $sql = "UPDATE $tbl1 SET Ordercompleted = 1 WHERE OrderNo= '{$orderno}'"; } ?> The foreach works since only the checked boxes are returned to the PHP script. Ken Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted January 28, 2008 Author Share Posted January 28, 2008 Just tried that but it doesnt update the field Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 28, 2008 Share Posted January 28, 2008 Add a line of code to the top of processed.php and copy/paste the output here <?php print_r($_POST); // <-- Add this line include('adminconnect.php'); $tbl1 = 'admn'; Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted January 28, 2008 Author Share Posted January 28, 2008 As i mentioned before it doesnt goto the processed.php page just remains at the new.php but the browser changes to: http://localhost/Admin_files/new.php?order%5B7112%5D=checked Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.