Help!!

Discussion in 'PHP' started by Greenmethod, May 12, 2009.

  1. #1
    I can't figure out why this is giving me an error. I've gone through it over and ever again, but I can't find it.

    <!-- If Deleting Inventory --><?php
    }elseif($delete == 'inventory'){?>
    	<!-- If a category has been selected --><?php
    	if($_POST['cat_no'] && !$_POST['stop_delete']){
    		$cat_no = $_POST['cat_no'];
    		$sn_req_query = mysql_query("") or die(mysql_error());
    		$sn_req_assoc = mysql_fetch_assoc($sn_req_query);
    		$sn_req = $sn_req_assoc['ser_no_req'];?>
    
    		<!-- If a SN is required --><?php
    		if('y' == $sn_req){?>
    
    			<!-- If you have checked which sn's to delete, and/or verified the deletion --><?php
    			if($_POST['kp_ckd'] || $_POST['dl_ckd'] || $_POST['del_verified']){
    				$sns_query = mysql_query("");
    				while($sns_assoc = mysql_fetch_array($sns_query)){
    					$sns_in_db[] = $sns_assoc['ser_no'];
    				};?>
    
    				<!-- If deletion has been verified --><?php
    				if($_POST['del_verified']){
    					foreach($sns_in_db as $ser_no){
    						if($_POST[$ser_no]){
    							echo 'deleted ' . $ser_no . '<br>';
    							$delete_inv = mysql_query("");
    						};
    					};?>
    					<script language="JavaScript">
    						setTimeout("top.location.href = 'admin.php'",3000);
    					</script>
    
    				<!-- Form to Verify Deletion --><?php
    				}else{?>
    					<form action="delete.php" method="post">
    						<table><?php
    							foreach($sns_in_db as $ser_no){?>
    								<!-- If you are keeping the checked sn's --><?php
    								if($_POST['kp_ckd']){
    									if(!$_POST[$ser_no]){?>
    										<tr>
    											<td><?php echo $ser_no ?></td>
    											<input type="hidden" name="<?php echo $ser_no ?>" value="<?php echo $ser_no?>">
    										</tr><?php
    									};?>
    
    								<!-- If you are deleting the checked sn's --><?php
    								}elseif($_POST['dl_ckd']){
    									if($_POST[$ser_no]){?>
    										<tr>
    											<td><?php echo $ser_no ?></td>
    											<input type="hidden" name="<?php echo $ser_no ?>" value="<?php echo $ser_no?>">
    										</tr><?php
    									};
    								};
    							};?>
    							<tr>
    								<td><input type="submit" name="del_verified" value="Delete"></td>
    								<td><input type="submit" name="stop_delete" value="Don't Delete"></td>
    							</tr>
    						</table>
    						<input type="hidden" name="delete" value="inventory">
    						<input type="hidden" name="cat_no" value="<?php echo $cat_no ?>">
    					</form><?php
    				};?>
    
    			<!-- Form to choose sn's --><?php
    			}else{
    				$sns_query = mysql_query("") or die(mysql_error());?>
    				<form method="post">
    					<table width="300"><?php
    						while($sns_result = mysql_fetch_assoc($sns_query)){?>
    							<tr>
    								<td align="right"><input type="checkbox" name="<?php echo $sns_result['ser_no'];?>"></td>
    								<td><?php echo $sns_result['ser_no']; ?></td>
    								<td><?php echo $sns_result['dt_we_ord'];?></td>
    								<td><?php echo $sns_result['comp_ord_from'];?></td>
    							</tr><?php
    						};?>
    						<tr>
    							<td colspan="2" align="center"><input type="submit" name="kp_ckd" value="Keep Checked"></td>
    							<td colspan="2" align="center"><input type="submit" name="dl_ckd" value="Delete Checked"></td>
    						</tr>
    					</table>
    					<input type="hidden" name="delete" value="inventory">
    					<input type="hidden" name="cat_no" value="<?php echo $cat_no; ?>">
    				</form>
    			};
    
    		<!-- If SN is not required --><?php
    		}elseif('n' == $sn_req){?>
    
    			<!-- If deletion has been verified --><?php
    			if($_POST['del_verified']){
    				$num_to_del = $_POST['num_to_del'];
    				for($i=$num_to_del;$i>0;$i--){
    					mysql_query("") or die(mysql_error());
    				};
    				echo $num_to_del . '<center> Records Deleted.  Redirecting...</center>';?>
    				<script language="JavaScript">
    					setTimeout("top.location.href = 'admin.php'",3000);
    				</script><?php
    				exit;?>
    
    			<!-- Verifing number to delete --><?php
    			}elseif($_POST['num_to_del']){
    				$in_stock = $_POST['in_db'] - $_POST['num_to_del'];?>
    				<form action="delete.php" method="post">
    					<input type="hidden" name="delete" value="inventory">
    					<input type="hidden" name="cat_no" value="<?php echo $cat_no; ?>">
    					<input type="hidden" name="num_to_del" value="<?php echo $_POST['num_to_del'] ?>">
    					<table>
    						<tr>
    							<td colspan="2">Do you have <?php echo $in_stock . ' ' . stripslashes($_POST['desc']); ?> ('s) in stock?</td>
    						</tr>
    						<tr>
    							<td align="center"><input type="submit" name="del_verified" value="Yes"></td>
    							<td align="center"><input type="submit" name="stop_delete" value="No"></td>
    						</tr>
    					</table>
    				</form><?php
    				exit;?>
    
    			<!-- Form show how many are in inventory and asks how many to delete. --><?php
    			}else{
    				$desc = stripslashes($_POST['desc']);
    				$in_stock_query = mysql_query("");?>
    				<form action="delete.php" method="post">
    					<input type="hidden" value="inventory" name="delete">
    					<input type="hidden" name="in_db" value="<?php echo mysql_num_rows($in_stock_query); ?>">
    					<input type="hidden" name="desc" value="<?php echo $desc ?>">
    					<input type="hidden" name="cat_no" value="<?php echo $cat_no ?>">
    					<table>
    						<tr>
    							<td><?php echo $desc ?></td>
    						</tr>
    						<tr>
    							<td>Database shows:</td>
    							<td><?php echo mysql_num_rows($in_stock_query); ?></td>
    						</tr>
    						<tr>
    							<td>Delete:</td>
    							<td><input name="num_to_del" type="text" size="5" maxlength="3"></td>
    						</tr>
    						<tr align="center">
    							<td colspan="2"><input type="submit" value="Delete"></td>
    						</tr>
    					</table>
    				</form><?php
    				exit;
    			};
    		};?>
    
    	<!-- List of Inventory --><?php
    	}else{
    		include('categories.php');
    	};
    PHP:

     
    Greenmethod, May 12, 2009 IP
  2. Greenmethod

    Greenmethod Peon

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Parse error: parse error, unexpected T_ELSEIF in delete.php on line 139 is the error i'm getting
     
    Greenmethod, May 12, 2009 IP
  3. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well for starters this is at the very top of your script.

    <?php
    }elseif($delete == 'inventory'){

    which is a very obvious problem, because you can't have a closing brace } without first having an open one. And elseif() can't be used if there was no if() before it.

    So assuming it wasn't a matter of impartial cut and paste, it should be:

    
    if($delete == 'inventory'){
    
    PHP:
    Also assuming you haven't done the same mistake elsewhere in the file.
     
    kblessinggr, May 12, 2009 IP
  4. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Also instead of having to close and reopen <?php every time put comments in the file, use PHP commenting instead.

    example
    
    // this is a comment
    
    /* This
    is also a comment */
    
    PHP:
     
    kblessinggr, May 12, 2009 IP
  5. Greenmethod

    Greenmethod Peon

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <?php
    session_start();
    include('sys/loginbox.php');
    $delete = $_POST['delete'];
    links();?>
    <br />
    <!-- If Deleting a Quote --><?php
    if($delete == 'quote'){?>
    	<!-- If you have already entered a quote number --><?php
    	if($_POST['quote_num']){
    		$quote_num = $_POST['quote_num'];?>
    		<!-- If you hit yes on the form to delete the quote --><?php
    		if ('Yes' == $_POST['delete_quote']){
    			mysql_query("") or die(mysql_error());
    			echo '<center>' . $_POST['rows_deleted'] . ' rows deleted.  Redirecting...</center>';?>
    			<script language="JavaScript">
    				setTimeout("top.location.href = 'admin.php'",3000);
    			</script>
    
    		<!-- If you hit no on the form, not to delete the quote --><?php
    		}elseif('No' == $_POST['delete_quote']){
    			echo 'No records have been deleted.  Redirecting...';?>
    			<script language="JavaScript">
    				setTimeout("top.location.href = 'admin.php'",3000);
    			</script>
    
    		<!-- Form to choose Yes or No to delete X number of records --><?php
    		}else{
    			$query = mysql_query("'") or die(mysql_error());
    			echo 'Delete ' . mysql_num_rows($query) . ' rows from database?'?>
    			<form action="delete.php" method="POST">
    				<input type="hidden" name="rows_deleted" value="<?php echo mysql_num_rows($query); ?>">
    				<input type="hidden" name="delete" value="quote">
    				<input type="hidden" name="quote_num" value="<?php echo $_POST['quote_num'] ?>">
    				<input type="submit" name="delete_quote" value="Yes" >
    				<input type="submit" name="delete_quote" value="No">
    			</form><?php
    		};?>
    
    	<!-- Form to enter quote number --><?php
    	}else{?>
    		<form action="delete.php" method="post">
    			<input type="hidden" name="delete" value="quote">
    			Quote Number: <input type="text" name="quote_num" maxlength="4" size="6">
    			<br>
    			<input type="submit" value="Verify Deletion">
    		</form><?php
    	};?>
    
    <!-- If Deleting Inventory --><?php
    }elseif($delete == 'inventory'){?>
    	<!-- If a category has been selected --><?php
    	if($_POST['cat_no'] && !$_POST['stop_delete']){
    		$cat_no = $_POST['cat_no'];
    		$sn_req_query = mysql_query("") or die(mysql_error());
    		$sn_req_assoc = mysql_fetch_assoc($sn_req_query);
    		$sn_req = $sn_req_assoc['ser_no_req'];?>
    
    		<!-- If a SN is required --><?php
    		if('y' == $sn_req){?>
    
    			<!-- If you have checked which sn's to delete, and/or verified the deletion --><?php
    			if($_POST['kp_ckd'] || $_POST['dl_ckd'] || $_POST['del_verified']){
    				$sns_query = mysql_query("");
    				while($sns_assoc = mysql_fetch_array($sns_query)){
    					$sns_in_db[] = $sns_assoc['ser_no'];
    				};?>
    
    				<!-- If deletion has been verified --><?php
    				if($_POST['del_verified']){
    					foreach($sns_in_db as $ser_no){
    						if($_POST[$ser_no]){
    							echo 'deleted ' . $ser_no . '<br>';
    							$delete_inv = mysql_query("");
    						};
    					};?>
    					<script language="JavaScript">
    						setTimeout("top.location.href = 'admin.php'",3000);
    					</script>
    
    				<!-- Form to Verify Deletion --><?php
    				}else{?>
    					<form action="delete.php" method="post">
    						<table><?php
    							foreach($sns_in_db as $ser_no){?>
    								<!-- If you are keeping the checked sn's --><?php
    								if($_POST['kp_ckd']){
    									if(!$_POST[$ser_no]){?>
    										<tr>
    											<td><?php echo $ser_no ?></td>
    											<input type="hidden" name="<?php echo $ser_no ?>" value="<?php echo $ser_no?>">
    										</tr><?php
    									};?>
    
    								<!-- If you are deleting the checked sn's --><?php
    								}elseif($_POST['dl_ckd']){
    									if($_POST[$ser_no]){?>
    										<tr>
    											<td><?php echo $ser_no ?></td>
    											<input type="hidden" name="<?php echo $ser_no ?>" value="<?php echo $ser_no?>">
    										</tr><?php
    									};
    								};
    							};?>
    							<tr>
    								<td><input type="submit" name="del_verified" value="Delete"></td>
    								<td><input type="submit" name="stop_delete" value="Don't Delete"></td>
    							</tr>
    						</table>
    						<input type="hidden" name="delete" value="inventory">
    						<input type="hidden" name="cat_no" value="<?php echo $cat_no ?>">
    					</form><?php
    				};?>
    
    			<!-- Form to choose sn's --><?php
    			}else{
    				$sns_query = mysql_query("") or die(mysql_error());?>
    				<form method="post">
    					<table width="300"><?php
    						while($sns_result = mysql_fetch_assoc($sns_query)){?>
    							<tr>
    								<td align="right"><input type="checkbox" name="<?php echo $sns_result['ser_no'];?>"></td>
    								<td><?php echo $sns_result['ser_no']; ?></td>
    								<td><?php echo $sns_result['dt_we_ord'];?></td>
    								<td><?php echo $sns_result['comp_ord_from'];?></td>
    							</tr><?php
    						};?>
    						<tr>
    							<td colspan="2" align="center"><input type="submit" name="kp_ckd" value="Keep Checked"></td>
    							<td colspan="2" align="center"><input type="submit" name="dl_ckd" value="Delete Checked"></td>
    						</tr>
    					</table>
    					<input type="hidden" name="delete" value="inventory">
    					<input type="hidden" name="cat_no" value="<?php echo $cat_no; ?>">
    				</form>
    			};
    
    		<!-- If SN is not required --><?php
    		}elseif('n' == $sn_req){?>
    
    			<!-- If deletion has been verified --><?php
    			if($_POST['del_verified']){
    				$num_to_del = $_POST['num_to_del'];
    				for($i=$num_to_del;$i>0;$i--){
    					mysql_query("") or die(mysql_error());
    				};
    				echo $num_to_del . '<center> Records Deleted.  Redirecting...</center>';?>
    				<script language="JavaScript">
    					setTimeout("top.location.href = 'admin.php'",3000);
    				</script><?php
    				exit;?>
    
    			<!-- Verifing number to delete --><?php
    			}elseif($_POST['num_to_del']){
    				$in_stock = $_POST['in_db'] - $_POST['num_to_del'];?>
    				<form action="delete.php" method="post">
    					<input type="hidden" name="delete" value="inventory">
    					<input type="hidden" name="cat_no" value="<?php echo $cat_no; ?>">
    					<input type="hidden" name="num_to_del" value="<?php echo $_POST['num_to_del'] ?>">
    					<table>
    						<tr>
    							<td colspan="2">Do you have <?php echo $in_stock . ' ' . stripslashes($_POST['desc']); ?> ('s) in stock?</td>
    						</tr>
    						<tr>
    							<td align="center"><input type="submit" name="del_verified" value="Yes"></td>
    							<td align="center"><input type="submit" name="stop_delete" value="No"></td>
    						</tr>
    					</table>
    				</form><?php
    				exit;?>
    
    			<!-- Form show how many are in inventory and asks how many to delete. --><?php
    			}else{
    				$desc = stripslashes($_POST['desc']);
    				$in_stock_query = mysql_query("");?>
    				<form action="delete.php" method="post">
    					<input type="hidden" value="inventory" name="delete">
    					<input type="hidden" name="in_db" value="<?php echo mysql_num_rows($in_stock_query); ?>">
    					<input type="hidden" name="desc" value="<?php echo $desc ?>">
    					<input type="hidden" name="cat_no" value="<?php echo $cat_no ?>">
    					<table>
    						<tr>
    							<td><?php echo $desc ?></td>
    						</tr>
    						<tr>
    							<td>Database shows:</td>
    							<td><?php echo mysql_num_rows($in_stock_query); ?></td>
    						</tr>
    						<tr>
    							<td>Delete:</td>
    							<td><input name="num_to_del" type="text" size="5" maxlength="3"></td>
    						</tr>
    						<tr align="center">
    							<td colspan="2"><input type="submit" value="Delete"></td>
    						</tr>
    					</table>
    				</form><?php
    				exit;
    			};
    		};?>
    
    	<!-- List of Inventory --><?php
    	}else{
    		include('categories.php');
    	};?>
    
    <!-- Delete Customer --><?php
    }elseif($delete == 'customer'){?>
    	<!-- If Customer Number Entered --><?php
    	if($_POST['del_cust']){
    		$cust_sql = mysql_query("");?>
    		<!-- Customer Found --><?php
    		if(1 == mysql_num_rows($cust_sql)){
    			$cust_info = mysql_fetch_assoc($cust_sql);?>
    			<!-- Form for verification of deletion -->
    			<br />
    			<form method="post">
    				<table width=300 frame='vsides'>
    					<tr>
    						<th colspan="2" align="center"><?php echo $cust_info['shop']; ?></th>
    					</tr>
    					<tr>
    						<td colspan="2" align="center"><?php echo $cust_info['address']; ?> </td>
    					</tr>
    					<tr>
    						<td colspan="2" align="center"><?php
    							echo $cust_info['city'] . ', ' . $cust_info['state'] . ' ';
    							if(strlen($cust_info['zip']) != 5){
    								echo zip($cust_info['zip']);
    							}else{
    								echo $cust_info['zip'];
    							};?>
    						</td>
    					</tr>
    					<tr>
    						<td colspan="2" align='center'><?php phone_number($cust_info['shop_num']); ?></td>
    					</tr>
    					<tr>
    						<td align='center'><input type='submit' name="del_verified" value='Delete'></td>
    						<td align="center"><input type="submit" name="stop_delete" value="Don't Delete"></td>
    					</tr>
    				</table>
    				<input type="hidden" name="cust_no" value="<?php echo $cust_info['cust_no']; ?>">
    				<input type="hidden" name="delete" value="customer">
    			</form><?php
    			exit;?>
    
    		<!-- Customer Not Found --><?php
    		}else{
    			echo 'Customer Number Not Found.  Redirecting...';?>
    			<script language="JavaScript">
    				setTimeout("top.location.href = 'admin.php'",3000);
    			</script><?php
    		};?>
    	
    	<!-- Form to search for Customer Number --><?php
    	}else{?>
    		<form action="delete.php" method="post">
    			<table>
    				<tr>
    					<td>Customer Number:</td>
    					<td><input type="text" name="cust_no"></td>
    				</tr>
    				<tr>
    					<td colspan="2" align="center"><input type="submit" name="del_cust" value="Delete"></td>
    				</tr>
    			</table>
    		<input type="hidden" name="delete" value="customer">
    		</form><?php
    	};?>
    
    <!-- Delete Purchase Order --><?php
    }elseif($delete == 'po'){?>
    	<!-- Delete PO Number From DB --><?php
    	if($_POST['write_db']){
    		$po_num = $_POST['po_num'];
    		$po_delete = mysql_query("");
    		echo 'Purchase Order has been deleted from database.  Redirecting...';?>
    		<script language="JavaScript">
    			setTimeout("top.location.href = 'admin.php'",3000);
    		</script>
    		
    	<!-- Search for PO Number --><?php
    	}elseif($_POST['po_num']){
    		$po_num = $_POST['po_num'];
    		$po_query = mysql_query("") or die(mysql_error());
    		$info_assoc = mysql_fetch_assoc($po_query);?>
    		<!-- PO Number Found --><?php 
    		if(0 != mysql_num_rows($po_query)){?>
    			<table width="400">
    				<tr>
    					<td align="center"><font size="+2"><?php echo $info_assoc['comp_ord_from']; ?></font></td>
    				</tr>
    				<tr>
    					<td align="center"><font size="+2"><?php echo $info_assoc['dt_we_ord']; ?></font></td>
    				</tr>
    				<tr>
    					<td align="center"><font size="+2"><?php echo $info_assoc['invoice_num']; ?></font></td>
    				</tr>
    			</table>
    			<br />
    			<table width="400">
    				<tr>
    					<td align="center"><b><u>Number Ordered</u></b></td>
    					<td align="center"><b><u>Description</u></b></td>
    				</tr><?php
    				$po_query = mysql_query("") or die(mysql_error());
    				while($po_assoc = mysql_fetch_assoc($po_query)){
    					$cat_no = $po_assoc['cat_no'];
    					$item_query = mysql_query("") or die(mysql_error());
    					$item_assoc = mysql_fetch_assoc($item_query);?>
    					<tr>
    						<td align="center"><?php echo mysql_num_rows($item_query); ?></td>
    						<td align="center"><?php echo $item_assoc['desc']; ?></td>
    					</tr><?php
    				};?>
    			</table>
    			<br />
    			<form method="post">
    				<input type="hidden" name="delete" value="po" />
    				<input type="hidden" name="po_num" value="<?php echo $po_num ?>" />
    				<input type="submit" name="write_db" value="Delete" />
    			</form>
    			<form action="admin.php">
    				<input type="submit" value="Don't Delete" />
    			</form>
    
    		<!-- PO Number Not Found --><?php
    		}else{
    			echo 'PO Not Found.  Redirecting...';?>
    			<script language="JavaScript">
    				setTimeout("top.location.href = 'admin.php'",3000);
    			</script>
    		};
    
    	<!-- Enter PO Number Form --><?php
    	}else{?>
    		<form method="post">
    			Purchase Order Number: <input type="text" size="5" name="po_num" maxlength="4" />
    			<input type="hidden" name="delete" value="po" />
    			<input type="submit" value="Delete PO" />
    		</form><?php
    	};?>
    
    <!-- Choose what to delete --><?php
    }else{?>
    	<form action='delete.php' name='jump' method='POST'>
    		<select name='delete' onChange='document.jump.submit();'>
    			<option selected value=''></option>
    			<option value='quote'>Quote</option>
    			<option value='inventory'>Inventory</option>
    			<option value='customer'>Customer</option>
    			<option value='po'>Purcase Order</option>
    		</select>
    	</form><?php
    };?>
    PHP:
     
    Greenmethod, May 12, 2009 IP
  6. Greenmethod

    Greenmethod Peon

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    That is the entire code from the page... there are if's before the one that i'm having the problem with. I don't think that the problem is because of the html comments, do you?
     
    Greenmethod, May 12, 2009 IP
  7. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Assumimg there is a ?> and <?php surrounding every html comment it wouldn't be the causing factor.

    Normally when it says unexpected T_ELSEIF , it means it did not expect to see an elseif() at that point, which normally means you forgot to close the previous if(). So look for a elseif() without a } in front of it.
     
    kblessinggr, May 12, 2009 IP
  8. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ok this seems to be your problem. This is the segment of code leading up to line 139 where the error occurs.

    
               <?php
                }else{
                    $sns_query = mysql_query("") or die(mysql_error());?>
                    <form method="post">
                        <table width="300"><?php
                            while($sns_result = mysql_fetch_assoc($sns_query)){?>
                                <tr>
                                    <td align="right"><input type="checkbox" name="<?php echo $sns_result['ser_no'];?>"></td>
                                    <td><?php echo $sns_result['ser_no']; ?></td>
                                    <td><?php echo $sns_result['dt_we_ord'];?></td>
                                    <td><?php echo $sns_result['comp_ord_from'];?></td>
                                </tr><?php
                            };?>
                            <tr>
                                <td colspan="2" align="center"><input type="submit" name="kp_ckd" value="Keep Checked"></td>
                                <td colspan="2" align="center"><input type="submit" name="dl_ckd" value="Delete Checked"></td>
                            </tr>
                        </table>
                        <input type="hidden" name="delete" value="inventory">
                        <input type="hidden" name="cat_no" value="<?php echo $cat_no; ?>">
                    </form>
                };
    
            <!-- If SN is not required --><?php
            }elseif('n' == $sn_req){?>
    
    PHP:
    Note how the previous item is an else()... you can't place an else before an elseif, you must follow the if -> elseif -> else order.

    You may also have some parsing issues in there, cuz I notice you have a }; immediately after a </form> without going back into php via <?php (and you don't need a ; after a brace)
     
    kblessinggr, May 12, 2009 IP
  9. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I also noticed that even if you do move the else down, you can't have two else { ... } for the same conditional block.

    All in all I think you need to completely rewrite that code.
     
    kblessinggr, May 12, 2009 IP
  10. Greenmethod

    Greenmethod Peon

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Thank you very much for your help. I still consider myself to be learning php, and any help is greatly appreciated. I have gone through that code taken out all of the html comments, and by doing that found my error. Here is the new code...

    <?php
    session_start();
    include('sys/loginbox.php');
    $delete = $_POST['delete'];
    links();?>
    <center>
    <br /><?php
    
    if($delete == 'quote'){//If Deleting a Quote
    	if($_POST['quote_num']){//If you have already entered a quote number
    		$quote_num = $_POST['quote_num'];
    		if ('Yes' == $_POST['delete_quote']){//If you hit yes on the form to delete the quote
    			mysql_query("") or die(mysql_error());
    			echo '<center>' . $_POST['rows_deleted'] . ' rows deleted.  Redirecting...</center>';?>
    			<script language="JavaScript">
    				setTimeout("top.location.href = 'admin.php'",3000);
    			</script><?php
    		}elseif('No' == $_POST['delete_quote']){//If you hit no on the form, not to delete the quote
    			echo 'No records have been deleted.  Redirecting...';?>
    			<script language="JavaScript">
    				setTimeout("top.location.href = 'admin.php'",3000);
    			</script><?php
    		}else{//Form to choose Yes or No to delete X number of records
    			$query = mysql_query("") or die(mysql_error());
    			echo 'Delete ' . mysql_num_rows($query) . ' rows from database?'?>
    			<form action="delete.php" method="POST">
    				<input type="hidden" name="rows_deleted" value="<?php echo mysql_num_rows($query); ?>">
    				<input type="hidden" name="delete" value="quote">
    				<input type="hidden" name="quote_num" value="<?php echo $_POST['quote_num'] ?>">
    				<input type="submit" name="delete_quote" value="Yes" >
    				<input type="submit" name="delete_quote" value="No">
    			</form><?php
    		};
    	}else{//Form to enter quote number?>
    		<form action="delete.php" method="post">
    			<input type="hidden" name="delete" value="quote">
    			Quote Number: <input type="text" name="quote_num" maxlength="4" size="6">
    			<br>
    			<input type="submit" value="Verify Deletion">
    		</form><?php
    	};
    }elseif($delete == 'inventory'){//If Deleting Inventory
    	if($_POST['cat_no'] && !$_POST['stop_delete']){//If a category has been selected
    		$cat_no = $_POST['cat_no'];
    		$sn_req_query = mysql_query("") or die(mysql_error());
    		$sn_req_assoc = mysql_fetch_assoc($sn_req_query);
    		$sn_req = $sn_req_assoc['ser_no_req'];
    		if('y' == $sn_req){//If a SN is required
    			if($_POST['kp_ckd'] || $_POST['dl_ckd'] || $_POST['del_verified']){ //If you have checked which sn's to delete, and/or verified the deletion
    				$sns_query = mysql_query("");
    				while($sns_assoc = mysql_fetch_array($sns_query)){
    					$sns_in_db[] = $sns_assoc['ser_no'];
    				};
    				if($_POST['del_verified']){//If deletion has been verified
    					foreach($sns_in_db as $ser_no){
    						if($_POST[$ser_no]){
    							echo 'deleted ' . $ser_no . '<br>';
    							$delete_inv = mysql_query("");
    						};
    					};?>
    					<script language="JavaScript">
    						setTimeout("top.location.href = 'admin.php'",3000);
    					</script><?php
    				}else{//Form to Verify Deletion?>
    					<form action="delete.php" method="post">
    						<table><?php
    							foreach($sns_in_db as $ser_no){
    								if($_POST['kp_ckd']){//If you are keeping the checked sn's
    									if(!$_POST[$ser_no]){?>
    										<tr>
    											<td><?php echo $ser_no ?></td>
    											<input type="hidden" name="<?php echo $ser_no ?>" value="<?php echo $ser_no?>">
    										</tr><?php
    									};
    								}elseif($_POST['dl_ckd']){//If you are deleting the checked sn's
    									if($_POST[$ser_no]){?>
    										<tr>
    											<td><?php echo $ser_no ?></td>
    											<input type="hidden" name="<?php echo $ser_no ?>" value="<?php echo $ser_no?>">
    										</tr><?php
    									};
    								};
    							};?>
    							<tr>
    								<td><input type="submit" name="del_verified" value="Delete"></td>
    								<td><input type="submit" name="stop_delete" value="Don't Delete"></td>
    							</tr>
    						</table>
    						<input type="hidden" name="delete" value="inventory">
    						<input type="hidden" name="cat_no" value="<?php echo $cat_no ?>">
    					</form><?php
    				};
    			}else{//Form to choose sn's
    				$sns_query = mysql_query("") or die(mysql_error());?>
    				<form method="post">
    					<table width="300"><?php
    						while($sns_result = mysql_fetch_assoc($sns_query)){?>
    							<tr>
    								<td align="right"><input type="checkbox" name="<?php echo $sns_result['ser_no'];?>"></td>
    								<td><?php echo $sns_result['ser_no']; ?></td>
    								<td><?php echo $sns_result['dt_we_ord'];?></td>
    								<td><?php echo $sns_result['comp_ord_from'];?></td>
    							</tr><?php
    						};?>
    						<tr>
    							<td colspan="2" align="center"><input type="submit" name="kp_ckd" value="Keep Checked"></td>
    							<td colspan="2" align="center"><input type="submit" name="dl_ckd" value="Delete Checked"></td>
    						</tr>
    					</table>
    					<input type="hidden" name="delete" value="inventory">
    					<input type="hidden" name="cat_no" value="<?php echo $cat_no; ?>">
    				</form><?php
    			};
    		}elseif('n' == $sn_req){//If SN is not required
    			if($_POST['del_verified']){//If deletion has been verified
    				$num_to_del = $_POST['num_to_del'];
    				for($i=$num_to_del;$i>0;$i--){
    					mysql_query("") or die(mysql_error());
    				};
    				echo $num_to_del . '<center> Records Deleted.  Redirecting...</center>';?>
    				<script language="JavaScript">
    					setTimeout("top.location.href = 'admin.php'",3000);
    				</script><?php
    			}elseif($_POST['num_to_del']){//Verifing number to delete
    				$in_stock = $_POST['in_db'] - $_POST['num_to_del'];?>
    				<form action="delete.php" method="post">
    					<input type="hidden" name="delete" value="inventory">
    					<input type="hidden" name="cat_no" value="<?php echo $cat_no; ?>">
    					<input type="hidden" name="num_to_del" value="<?php echo $_POST['num_to_del'] ?>">
    					<table>
    						<tr>
    							<td colspan="2">Do you have <?php echo $in_stock . ' ' . stripslashes($_POST['desc']); ?> ('s) in stock?</td>
    						</tr>
    						<tr>
    							<td align="center"><input type="submit" name="del_verified" value="Yes"></td>
    							<td align="center"><input type="submit" name="stop_delete" value="No"></td>
    						</tr>
    					</table>
    				</form><?php
    			}else{//Form show how many are in inventory and asks how many to delete
    				$desc = stripslashes($_POST['desc']);
    				$in_stock_query = mysql_query("");?>
    				<form action="delete.php" method="post">
    					<input type="hidden" value="inventory" name="delete">
    					<input type="hidden" name="in_db" value="<?php echo mysql_num_rows($in_stock_query); ?>">
    					<input type="hidden" name="desc" value="<?php echo $desc ?>">
    					<input type="hidden" name="cat_no" value="<?php echo $cat_no ?>">
    					<table>
    						<tr>
    							<td><?php echo $desc ?></td>
    						</tr>
    						<tr>
    							<td>Database shows:</td>
    							<td><?php echo mysql_num_rows($in_stock_query); ?></td>
    						</tr>
    						<tr>
    							<td>Delete:</td>
    							<td><input name="num_to_del" type="text" size="5" maxlength="3"></td>
    						</tr>
    						<tr align="center">
    							<td colspan="2"><input type="submit" value="Delete"></td>
    						</tr>
    					</table>
    				</form><?php
    			};
    		};?>
    
    	<!-- List of Inventory --><?php
    	}else{
    		include('categories.php');
    	};
    	/*}elseif($_POST['sub_cat_1']){
    		$main_cat = $_POST['main_cat'];
    		$sub_cat_1 = $_POST['sub_cat_1'];
    		$desc_result = mysql_query("");?>
    		<table><?php
    			while ($desc_row = mysql_fetch_array($desc_result)){
    				$desc = stripslashes($desc_row['desc']);
    				$cat_no = $desc_row['cat_no'];?>
    				<form method="post">
    					<input type="hidden" name="delete" value="inventory">
    					<input type="hidden" name="cat_no" value="<?php echo $cat_no ?>">
    					<tr>
    						<td><input class="inv_list" type="submit" name="desc" value="<?php echo $desc ?>"></td>
    					</tr>
    				</form><?php
    			};?>
    		</table>
    
    	<!-- List of Sub Categories --><?php
    	}elseif ($_POST['main_cat']){
    		$main_cat = $_POST['main_cat'];
    		$sub_1 = mysql_query("");?>
    		<form method="post">
    			<input type="hidden" name="delete" value="inventory">
    			<input type="hidden" name="main_cat" value="<?php echo $main_cat ?>">
    			<table><?php
    				while ($sub_1_row = mysql_fetch_array($sub_1)){
    					$sub_cat_1 = stripslashes($sub_1_row['sub_cat_1']);?>
    					<tr>
    						<td><input class="inv_list" type="submit" name="sub_cat_1" value="<?php echo $sub_cat_1 ?>"></td>
    					</tr><?php
    				};?>
    			</table>
    		</form>
    
    	<!-- List of Main Categories --><?php
    	}else{
    		$main_cat_result = mysql_query("");?>
    		<form action="delete.php" method="post">
    		<input type="hidden" name="delete" value="inventory">
    			<table border="0"><?php
    				while($main_cat_row = mysql_fetch_array($main_cat_result)){
    					$main_cat = stripslashes($main_cat_row['main_cat']);?>
    					<tr>
    						<td><input class="inv_list" type="submit" name="main_cat" value="<?php echo $main_cat ?>"></td>
    					</tr><?php
    				};?>
    			</table>
    		</form><?php
    	};*/
    }elseif($delete == 'customer'){//Delete Customer
    	if($_POST['del_cust']){//If Customer Number Entered
    		$cust_sql = mysql_query("");
    		if(1 == mysql_num_rows($cust_sql)){//Customer Found
    			$cust_info = mysql_fetch_assoc($cust_sql);?>
    			<!-- Form for verification of deletion -->
    			<br />
    			<form method="post">
    				<table width=300 frame='vsides'>
    					<tr>
    						<th colspan="2" align="center"><?php echo $cust_info['shop']; ?></th>
    					</tr>
    					<tr>
    						<td colspan="2" align="center"><?php echo $cust_info['address']; ?> </td>
    					</tr>
    					<tr>
    						<td colspan="2" align="center"><?php
    							echo $cust_info['city'] . ', ' . $cust_info['state'] . ' ';
    							if(strlen($cust_info['zip']) != 5){
    								echo zip($cust_info['zip']);
    							}else{
    								echo $cust_info['zip'];
    							};?>
    						</td>
    					</tr>
    					<tr>
    						<td colspan="2" align='center'><?php phone_number($cust_info['shop_num']); ?></td>
    					</tr>
    					<tr>
    						<td align='center'><input type='submit' name="del_verified" value='Delete'></td>
    						<td align="center"><input type="submit" name="stop_delete" value="Don't Delete"></td>
    					</tr>
    				</table>
    				<input type="hidden" name="cust_no" value="<?php echo $cust_info['cust_no']; ?>">
    				<input type="hidden" name="delete" value="customer">
    			</form><?php
    		}else{//Customer Not Found
    			echo 'Customer Number Not Found.  Redirecting...';?>
    			<script language="JavaScript">
    				setTimeout("top.location.href = 'admin.php'",3000);
    			</script><?php
    		};
    	}else{//Form to search for Customer Number?>
    		<form action="delete.php" method="post">
    			<table>
    				<tr>
    					<td>Customer Number:</td>
    					<td><input type="text" name="cust_no"></td>
    				</tr>
    				<tr>
    					<td colspan="2" align="center"><input type="submit" name="del_cust" value="Delete"></td>
    				</tr>
    			</table>
    		<input type="hidden" name="delete" value="customer">
    		</form><?php
    	};
    
    
    }elseif($delete == 'po'){//Delete Purchase Order
    	if($_POST['write_db']){//Delete PO Number From DB
    		$po_num = $_POST['po_num'];
    		$po_delete = mysql_query("'");
    		echo 'Purchase Order has been deleted from database.  Redirecting...';?>
    		<script language="JavaScript">
    			setTimeout("top.location.href = 'admin.php'",3000);
    		</script><?php
    	}elseif($_POST['po_num']){//Search for PO Number
    		$po_num = $_POST['po_num'];
    		$po_query = mysql_query("'") or die(mysql_error());
    		$info_assoc = mysql_fetch_assoc($po_query);
    		if(0 != mysql_num_rows($po_query)){//PO Number Found?>
    			<table width="400">
    				<tr>
    					<td align="center"><font size="+2"><?php echo $info_assoc['comp_ord_from']; ?></font></td>
    				</tr>
    				<tr>
    					<td align="center"><font size="+2"><?php echo $info_assoc['dt_we_ord']; ?></font></td>
    				</tr>
    				<tr>
    					<td align="center"><font size="+2"><?php echo $info_assoc['invoice_num']; ?></font></td>
    				</tr>
    			</table>
    			<br />
    			<table width="400">
    				<tr>
    					<td align="center"><b><u>Number Ordered</u></b></td>
    					<td align="center"><b><u>Description</u></b></td>
    				</tr><?php
    				$po_query = mysql_query("") or die(mysql_error());
    				while($po_assoc = mysql_fetch_assoc($po_query)){
    					$cat_no = $po_assoc['cat_no'];
    					$item_query = mysql_query("") or die(mysql_error());
    					$item_assoc = mysql_fetch_assoc($item_query);?>
    					<tr>
    						<td align="center"><?php echo mysql_num_rows($item_query); ?></td>
    						<td align="center"><?php echo $item_assoc['desc']; ?></td>
    					</tr><?php
    				};?>
    			</table>
    			<br />
    			<form method="post">
    				<input type="hidden" name="delete" value="po" />
    				<input type="hidden" name="po_num" value="<?php echo $po_num ?>" />
    				<input type="submit" name="write_db" value="Delete" />
    			</form>
    			<form action="admin.php">
    				<input type="submit" value="Don't Delete" />
    			</form><?php
    		}else{//PO Number Not Found
    			echo 'PO Not Found.  Redirecting...';?>
    			<script language="JavaScript">
    				setTimeout("top.location.href = 'admin.php'",3000);
    			</script><?php
    		};
    	}else{//Enter PO Number Form?>
    		<form method="post">
    			Purchase Order Number: <input type="text" size="5" name="po_num" maxlength="4" />
    			<input type="hidden" name="delete" value="po" />
    			<input type="submit" value="Delete PO" />
    		</form><?php
    	};
    }else{//Choose what to delete?>
    	<form action='delete.php' name='jump' method='POST'>
    		<select name='delete' onChange='document.jump.submit();'>
    			<option selected value=''></option>
    			<option value='quote'>Quote</option>
    			<option value='inventory'>Inventory</option>
    			<option value='customer'>Customer</option>
    			<option value='po'>Purcase Order</option>
    		</select>
    	</form><?php
    };?>
    </center>
    PHP:
    If anyone has any pointers or opinions about my code, please let me know. Thanks again!
     
    Greenmethod, May 12, 2009 IP
  11. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Probably try breaking down the sections, like include('filename.php') large chunks of code as you need them, kind like how you wouldn't put an entire site into a single index.php, but you might pull the desired content from various php into index.php

    and since you're deciding between four delete methods, try a switch instead of if..then

    example:
    
    switch($delete) 
    {
          case 'quote':
             ...do stuff....
             break;
          case 'inventory':
             ...do stuff....
             break;
          case 'customer':
             ...do stuff....
             break;
          case 'po':
             ...do stuff....
             break;
          default:
            ...do stuff...
    }
    
    PHP:
     
    kblessinggr, May 12, 2009 IP
  12. Greenmethod

    Greenmethod Peon

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I have used switch before... is there a difference in speed or accuracy with either of them?
     
    Greenmethod, May 12, 2009 IP
  13. Greenmethod

    Greenmethod Peon

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    And is anyone else having trouble signing into this site? I have been having a lot of trouble today.
     
    Greenmethod, May 12, 2009 IP
  14. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Not a huge difference in performance, just can be easier on the developer when you got multiple choice options instead of a bunch of if() { } elseif {} elseif { } elseif { } else { }
     
    kblessinggr, May 12, 2009 IP
  15. Greenmethod

    Greenmethod Peon

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    yea, i've changed that page to switch and I see what you're saying.
     
    Greenmethod, May 12, 2009 IP