Jump to content

variables lost when moving to new php page


mikebyrne

Recommended Posts

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";
}
?>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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";
}
?>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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}'";
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.