Jump to content

Why is this happening?? echo issue, please take a look.


Bl4ckMaj1k

Recommended Posts

EDIT:

 

Solved. I was calling duplicate variables from an include. Changing the name in this code to something (could be anything really) different fixed the issue. Thanks!!

 

I am currently working on some PHP which grabs variables from the link so I can keep track of which user has been clicked on. Everything seemed to be working just fine until I got to a particular part of the code. Let me know if this makes any sense AT ALL!!! As usual my code can be found below. Thanks!!

<?php

session_start();

// Put stored session variables into local php variable
    $staff_id = $_SESSION['sid'];
    $staff_username = $_SESSION['username'];
    $staff_fname = $_SESSION['staff_first_name'];
    $cust_edit_access = $_SESSION['cust_edit_access'];

include_once "scripts/connect_to_mysql.php";

    $customer_id = $_GET['cid'];
    $customer_id  = mysql_real_escape_string($customer_id );
    $customer_id = eregi_replace("`", "", $customer_id);

    $customer_project_id = $_GET['pid'];
    $customer_project_id = mysql_real_escape_string($customer_project_id );
    $customer_project_id = eregi_replace("`", "", $customer_project_id );

include "left_nav_customers.php";
include "left_nav_tools.php";
include "pgbdy_header_left.php";
include "project_display.php";

$sql = mysql_query("SELECT * FROM company_info WHERE proj_id='$customer_project_id'");

while ($row = mysql_fetch_array($sql)) {
$company_name = $row["company_name"];  
$customer_address = $row["address"]; 
$customer_city = $row["city"]; 
$customer_state = $row["state"]; 
$customer_zip = $row["zip"]; 
$customer_email = $row["email"]; 
$customer_phone = $row["phone"]; 
$customer_fax = $row["fax"]; 
$cust_pre_meth_contact = $row["pref_meth_contact"];
$cust_entry_date = $row["entry_date"];
}

$temp_project_id = '';
$start_date = date("F j, Y, g:i:s a");
$start_month = date('n');

if ($_POST['create_new_customer_project']) {
$sql2 = mysql_query("INSERT INTO projects (cust_id, staff_id, start_date) 
	VALUES('$customer_id','$staff_id','$start_date')") or die (mysql_error());
	// Get the inserted ID here to use in the activation email
	$new_project_id = mysql_insert_id();
	// Create directory(folder) to hold each user files(pics, MP3s, etc.) 

	$temp_project_id = "$start_month-00$customer_id-0$new_project_id";

	mkdir("customer_files/cust$customer_id/$temp_project_id", 0755);

$sql3 = mysql_query("UPDATE projects SET proj_id='$temp_project_id' WHERE id='$new_project_id'");

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="style.css"/>

<!----------- ALL JAVASCRIPT ------------------------
==================================================-->
<script src="js/jquery-1.5.js" type="text/javascript"></script>

<script language="javascript" type="text/javascript"> 
function toggleSlideBox(x) {
	if ($('#'+x).is(":hidden")) {
		$(".hiddenDiv").slideUp(200);
		$('#'+x).slideDown(300);
	} else {
		$('#'+x).slideUp(300);
	}
}
</script>

<!--===========COMPANY INFO POPUP==============--
==============================================-->

<script type="text/javascript">
<!--
function edit_company_info() {
window.open( "edit_company_info.php?sid=<?php echo "$staff_id"; ?>&cid=<?php echo "$customer_id"; ?>&pid=<?php echo "$customer_project_id"; ?>", "myWindow", 
"status = 1, toolbar = no, scrollbars = no, location = no, resizable = no, height = 580, width = 600, resizable = 0" )
}
//-->
</script>

<!--===========COMPANY INFO POPUP==============--
==============================================-->

<!--===========GENERAL INFO POPUP==============--
==============================================-->

<script type="text/javascript">
<!--
function edit_general_info() {
window.open( "http://www.google.com/", "myWindow", 
"status = 1, toolbar = no, scrollbars = no, location = no, resizable = no, height = 600, width = 600, resizable = 0" )
}
//-->
</script>

<!--===========GENERAL INFO POPUP==============--
==============================================-->

<!--===========BILLING INFO POPUP==============--
==============================================-->

<script type="text/javascript">
<!--
function edit_billing_info() {
window.open( "http://www.google.com/", "myWindow", 
"status = 1, toolbar = no, scrollbars = no, location = no, resizable = no, height = 600, width = 600, resizable = 0" )
}
//-->
</script>

<!--===========BILLING INFO POPUP==============--
==============================================-->

<!--===========FACILITY INFO POPUP==============--
==============================================-->

<script type="text/javascript">
<!--
function edit_facility_info() {
window.open( "http://www.google.com/", "myWindow", 
"status = 1, toolbar = no, scrollbars = no, location = no, resizable = no, height = 600, width = 600, resizable = 0" )
}
//-->
</script>

<!--===========FACILITY INFO POPUP==============--
==============================================-->

<!--===========PRODUCT NEEDS INFO POPUP==============--
==============================================-->

<script type="text/javascript">
<!--
function edit_product_needs_info() {
window.open( "http://www.google.com/", "myWindow", 
"status = 1, toolbar = no, scrollbars = no, location = no, resizable = no, height = 600, width = 600, resizable = 0" )
}
//-->
</script>

<!--===========PRODUCT NEEDS INFO POPUP==============--
==============================================-->

<script type="text/javascript">
<!--
var sURL = unescape(window.location.pathname);

function refresh()
{
    window.location.href = sURL;
}
//-->
</script>


<!----------- ALL JAVASCRIPT ------------------------
==================================================-->

</head>

<body>

<div id="pg_container">

<!--HEADER SECTION-->
<div id="header">
<div id="header_logo"></div>
    <div id="header_right">
    	Welcome <a href="template.php?id=<?php echo "$staff_id"; ?>"><?php echo $staff_fname; ?></a> |  <a href="logout.php">Logout</a>
    </div>
</div>
<!--HEADER SECTION-->

<!--PAGE CONTAINER-->
<div id="pgbdy_container">

  <div id="left_nav">
   	  	<div id="leftnav_header"></div>
      	
        <div id="leftnav_bdy">
       	  <div id="leftnav_content">
          	<div id="leftnav_customers">
            	<p>
                	Select a Customer:<br /><br />
                	<?php echo "$list_customers"; ?>
                </p>
            </div>
            <hr />
            <?php if($cust_edit_access == "1") { ?>
            <div id="leftnav_tools">
            	
                <p>
                	<?php echo "$leftnav_links"; ?>
                </p>
                
            </div>
            <?php } else { ?>
            <div id="leftnav_tools">
            	<p>
                 Edit Customers<br /><br />
                 You do not have access to edit customers.
                </p>
            </div>
            <?php } ?>                    
          </div>
        </div>
      </div>
     
      
  	  <div id="pgbdy">
      	<div id="bdy_header"></div>
      	<div id="bdy_content_area">
       	  <div id="bdy_content">
		<div id="bdy_content_header">
            	<div id="bdy_content_selected_customer">
                	
                    <p><?php echo "$contact_info_display"; ?></p>
                    
                </div>
                
                <div id="bdy_content_current_projects">
          			<form action="customer_profile.php?sid=<?php echo "$staff_id"; ?>&cid=<?php echo "$customer_id"; ?>" method="post" enctype="multipart/form-data">
                	<p>
                    	Customer Projects
                        <input name="create_new_customer_project" type="submit" class="create_new_customer_project_btn" value="" /><br /><br />
                    <?php echo "$list_customer_projects"; ?>
                    </p>
                    </form>
                </div>
            </div>
            <hr />
            <div id="bdy_content_container">
                <div id="company_information_section">
                <a href="#" onclick="return false" onmousedown="javascript:toggleSlideBox('company_infoBox');">Company Information</a>
                    	<div class="hiddenDiv" id="company_infoBox" style="border:#FFF 2px solid; width:553px;">
                        	<p>Please click the button below to edit the customer's company information.<br />
                    		<input name="edit_company_info" onclick="edit_company_info()" type="button" value="Edit Company Information"/><br /><br />
                            //i placed this here just to make sure the issue was on this page.                       
                            <?php echo "$customer_project_id"; ?>
                            <b>Company Name:  </b><?php echo "$company_name"; ?><br />
                            <b>Contact Name:  </b><?php echo "$customer_fname"; ?> <?php echo "$customer_lname"; ?><br />
                            <b>Address:  </b><?php echo "$customer_address"; ?><br />
                            <b>City, State, Zip:  </b><?php echo "$customer_city"; ?>, <?php echo "$customer_state"; ?> <?php echo "$customer_zip"; ?><br />
                            <b>Email:  </b><?php echo "$customer_email"; ?><br />
                            <b>Phone:  </b><?php echo "$customer_phone"; ?><br />
                            <b>Fax:  </b><?php echo "$customer_fax"; ?><br />
                            <b>Preferred Method of Contact:  </b><?php echo "$cust_pre_meth_contact"; ?>
                            
                            </p>
                        </div>
                </div>
                
                <div id="general_information_section">
                <a href="#" onclick="return false" onmousedown="javascript:toggleSlideBox('general_infoBox');">General Information</a>
                    	<div class="hiddenDiv" id="general_infoBox" style="border:#FFF 2px solid; width:553px;">
                        	<p>Please click the button below to edit the customer's general information.<br />
                    		<input name="edit_general_info" onclick="edit_general_info()" type="button" value="Edit General Information"/>
                            </p>
                        </div>
                </div>
                
                <div id="billing_information_section">
                <a href="#" onclick="return false" onmousedown="javascript:toggleSlideBox('billing_infoBox');">Billing Information</a>
                    	<div class="hiddenDiv" id="billing_infoBox" style="border:#FFF 2px solid; width:553px;">
                        	<p>Please click the button below to edit the customer's billing information.<br />
                    		<input name="edit_billing_info" onclick="edit_billing_info()" type="button" value="Edit Billing Information"/>
                            </p>
                        </div>
                </div>
                
                <div id="facility_information_section">
                <a href="#" onclick="return false" onmousedown="javascript:toggleSlideBox('facility_infoBox');">Facility Information</a>
                    	<div class="hiddenDiv" id="facility_infoBox" style="border:#FFF 2px solid; width:553px;">
                        	<p>Please click the button below to edit the customer's facility information.<br />
                    		<input name="edit_facility_info" onclick="edit_facility_info()" type="button" value="Edit Facility Information"/>
                            </p>
                        </div>
                </div>
                
                <div id="product_needs_information_section">
                <a href="#" onclick="return false" onmousedown="javascript:toggleSlideBox('product_needs_infoBox');">Product Needs Information</a>
                    	<div class="hiddenDiv" id="product_needs_infoBox" style="border:#FFF 2px solid; width:553px;">
                        	<p>Please click the button below to edit the customer's product needs information.<br />
                    		<input name="edit_product_needs_info" onclick="edit_product_needs_info()" type="button" value="Edit Product Needs Information"/>
                            </p>
                        </div>
                </div>
            </div>
          </div>
      	</div>
      </div>
      
      <div id="right_nav">
      	<div id="rightnav_header"></div>
      	<div id="rightnav_bdy">
       	  <div id="rightnav_bdy_content">
          	<div id="rightnav_proj_status">
            	<p>
                	All Current Associated Project Statuses
                </p>
            </div>
            <hr />
            <div id="rightnav_alerts">
              <p>
              Any associated alerts sent so far
              </p>
            </div>
          </div>
      	</div>
      </div>

</div>
<!--PAGE CONTAINER-->

<div id="footer"></div>

</div>
</body>
</html>

 

The issue is that each of these ID echo statements (cid being customer id, sid being staff id, and pid being project id) echoes something. CID echoes correctly, SID does as well. For some reason, PID only echoes the last project ID that was entered for that particular user. So for example, if I add a project to a user and im staff it would be like this:

 

Staff ID = my Staff ID = 1

Customer ID = customer I am currently working on = 11 (in this case...just a random number for example sake)

Project ID = the current month number (no zeroes)-00(current customer id being worked on)-0(current project ID from table) = 3-0011-042

 

If our example is saying that the latest addition is 3-0011-042, and I click on project 3-0011-038, for some reason (EVEN THOUGH MY WEB LINK HAS THE CORRECT PID which is 3-0011-038) it only echoes the last PID entered in the table. Its almost like its completely ignoring what I have in my address bar and looks directly at my tables latest entry....this has really screwed with my brainnnn!!! I can't seem to figure it out for the life of me. I don't even know how I could run a $_GET function and not get what I am asking for.....crazy. Please help guys!!!!

 

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.