Link to home
Start Free TrialLog in
Avatar of dereksheahan
dereksheahan

asked on

Passing URL parameter problem

Hi all,
I have a page that is getting values from two url parameters from the previous page. The two parameters are Type_variable and model_variable. The model_variable works fine but for some reason the Type_variable always shows its result on the page as a value of 1. I'm thinking this might be something to do with the fact that the Type_variable has been used on other pages in the site as well. The Type_variable was also used on the previous page to get information for that page. I know the correct Type_variable is being passed because I can see it in the title bar. The result displayed on the page however is always a value of 1. Can anyone help?
Here's the code to the page:
Thanks,
Derek

<?php require_once('../Connections/GSM_mobile.php'); ?>
<?php
$colname_rsPostalApp = "-1";
if (isset($_GET['Type_variable'])) {
  $colname_rsPostalApp = (get_magic_quotes_gpc()) ? $_GET['Type_variable'] : addslashes($_GET['Type_variable']);
}
$colname2_rsPostalApp = "-1";
if (isset($_GET['model_variable'])) {
  $colname2_rsPostalApp = (get_magic_quotes_gpc()) ? $_GET['model_variable'] : addslashes($_GET['model_variable']);
}
mysql_select_db($database_GSM_mobile, $GSM_mobile);
$query_rsPostalApp = sprintf("SELECT mod_model_id, mod_model_name, mod_type_id, type_table.type_type_id, type_table.type_type_name FROM model_table, type_table WHERE mod_type_id = %s AND  mod_model_id = %s", $colname_rsPostalApp,$colname2_rsPostalApp);
$rsPostalApp = mysql_query($query_rsPostalApp, $GSM_mobile) or die(mysql_error());
$row_rsPostalApp = mysql_fetch_assoc($rsPostalApp);
$totalRows_rsPostalApp = mysql_num_rows($rsPostalApp);
?><!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>
<SCRIPT>
// connect this function as shown below to a form button
function showData (form) {
  window.currentForm = form;
  form.oldAction = form.action;
  form.oldTarget = form.target;
  form.oldMethod = form.method;
  form.action = 'formPrintData.html';
  form.target = 'formData' + new Date().getTime();
  form.method = 'get';
  open ('', form.target);
  form.submit();
}
</SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
-->
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="postalprint.php">
  <p>Please fill out the following form:</p>
  <p>
    <label>
    <div align="center">Name
      <input name="txt_username" type="text" id="txt_username" />
    </div>
    </label>
  </p>
  <p align="center">
    <label>Return Address
    <input name="txt_rtn_add" type="text" id="txt_rtn_add" value="" />
    </label>
  </p>
  <p align="center">
    <label>Postcode
    <input name="txt_postcode" type="text" id="txt_postcode" />
    </label>
  </p>
  <p align="center">
    <label>Contact Number
    <input name="txt_contact_nr" type="text" id="txt_contact_nr" />
    </label>
  </p>
  <p align="center">
    <label>Email Address
    <input name="txt_email_add" type="text" id="txt_email_add" />
    </label>
</p>
  <p align="center">
    <label>Phone Make
    <input name="txt_phone_make" type="text" id="txt_phone_make" value="<?php echo $row_rsPostalApp['type_type_name']; ?>" />
    </label>
  </p>
  <p align="center">
    <label>Phone Model
    <input name="txt_phone_mobile" type="text" id="txt_phone_mobile" value="<?php echo $row_rsPostalApp['mod_model_name']; ?>" />
    </label>
  </p>
  <p align="center">
    <label>IMEI Number (enter *#06# on your handset)
    <input name="txt_IMEI_nr" type="text" id="txt_IMEI_nr" />
    </label>
  </p>
  <p align="center">
      <INPUT TYPE="button" VALUE="show data"
       ONCLICK="showData(this.form);"
>


  </p>
  <p>&nbsp;</p>
</form>
</body>
</html>
<?php
mysql_free_result($rsPostalApp);
?>
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Derek,

Can you post the page code from the page preceeding this one and also the query string (the part of the URL after the ?).

As far as I can see, this code is correct.  However, where is the echo call to Type_variable?  
Avatar of dereksheahan
dereksheahan

ASKER

Sure,
If what it says in the URL when I pass to the above page (http://localhost/GSM/Postal/postalform.php?Type_variable=12&model_variable=360).
Here's what the URL is and the preceeding page:
(http://localhost/GSM/Postal/jasontester.php?Type_variable=12)
and here's the code to the preceeding page. Hope it helps.
 <?php require_once('../Connections/GSM_mobile.php'); ?>
<?php require_once('../Connections/GSM_mobile.php'); ?>
<?php
$colname_rsPostalResults = "-1";
if (isset($_GET['Type_variable'])) {
  $colname_rsPostalResults = (get_magic_quotes_gpc()) ? $_GET['Type_variable'] : addslashes($_GET['Type_variable']);
}
mysql_select_db($database_GSM_mobile, $GSM_mobile);
$query_rsPostalResults = sprintf("SELECT mod_model_id, mod_model_name, mod_type_id FROM model_table WHERE mod_type_id = %s", $colname_rsPostalResults);
$rsPostalResults = mysql_query($query_rsPostalResults, $GSM_mobile) or die(mysql_error());
$row_rsPostalResults = mysql_fetch_assoc($rsPostalResults);
$totalRows_rsPostalResults = mysql_num_rows($rsPostalResults);

$colname_rsgetimage = "-1";
if (isset($_GET['Type_variable'])) {
  $colname_rsgetimage = (get_magic_quotes_gpc()) ? $_GET['Type_variable'] : addslashes($_GET['Type_variable']);
}
mysql_select_db($database_GSM_mobile, $GSM_mobile);
$query_rsgetimage = sprintf("SELECT type_type_id, type_type_name, image_src FROM type_table WHERE type_type_id = %s", $colname_rsgetimage);
$rsgetimage = mysql_query($query_rsgetimage, $GSM_mobile) or die(mysql_error());
$row_rsgetimage = mysql_fetch_assoc($rsgetimage);
$totalRows_rsgetimage = mysql_num_rows($rsgetimage);
?><!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=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {font-family: Arial, Helvetica, sans-serif}
.style2 {color: #993333}
#Layer1 {
     left:11px;
     top:188px;
     width:417px;
     height:auto;
     z-index:1;
}
#Layer1 {
     border: thin dotted #333333;
}
Pos {
     overflow: visible;
}
#Layer2 {
     width:683px;
     clear: both;
     float: none;
}
.style4 {color: #0000CC}
#Layer3 {
      position:absolute;
      left:10px;
      top:38px;
      width:377px;
      height:89px;
      z-index:1;
}
#Layer1 {
      position: relative;
}
#Layer2 {
      position: relative;
      left: 13px;
      top: 251px;
}
#Layer4 {
      position:absolute;
      left:16px;
      top:146px;
      width:323px;
      height:37px;
      z-index:2;
}
-->
</style>
</head>

<body>

<div id="Layer3"><img src="http://localhost/GSM/Images/<?php echo $row_rsgetimage['image_src']; ?>" />Postal Unlock : </div>
<div id="Layer1">
  <p><span class="style1 style4">
    <?php do { ?>
        <a href="postalform.php?Type_variable=<?php echo $row_rsPostalResults['mod_type_id']; ?>&amp;model_variable=<?php echo $row_rsPostalResults['mod_model_id']; ?>"><?php echo $row_rsPostalResults['mod_model_name']; ?></a>
    <?php } while ($row_rsPostalResults = mysql_fetch_assoc($rsPostalResults)); ?>
  </span></p>
</div>
<div id="Layer2">
  <p><a href="postalmain.php">Search again </a></p>
  <p>If your phone model is not listed then please <a href="../support.php">contact us</a> to make sure we can unlock your phone before sending.</p>
  <p>Alternatively you can download  our <a href="../Files/postal unlocking form.doc">postal contact form</a> and fill it in later. </p>
</div>
<div id="Layer4">The following is a list of models that we support. Click on your model to continue:</div>
<div>
  <form id="form1" name="form1" method="post" action="">
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p class="style1 style2">&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
  </form>
</div>
</body>
</html>
<?php
mysql_free_result($rsPostalResults);

mysql_free_result($rsgetimage);
?>
Well, crap.  This looks okay too.

A long time ago, someone once told me that the way DW writes queries is odd.  I wonder if using sprintf and %s isn't screwing you up somehow...

I'm going to take some time to play with my son, then I'll play with this code.  In the meantime, post a 20 point pointer question in the PHP area and ask some real PHP pros to look at this.  Something is not quite right, but I can't put my finger on it...
SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Its telling me I have an error in my SQL syntax when I change it to this. (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1) I think I've put it in the right place?

<?php require_once('../Connections/GSM_mobile.php'); ?>
<?php
$colname_rsPostalApp = "-1";
if (isset($_GET['Type_variable'])) {
  $colname_rsPostalApp = (get_magic_quotes_gpc()) ? $_GET['Type_variable'] : addslashes($_GET['Type_variable']);
}
$colname2_rsPostalApp = "-1";
if (isset($_GET['model_variable'])) {
  $colname2_rsPostalApp = (get_magic_quotes_gpc()) ? $_GET['model_variable'] : addslashes($_GET['model_variable']);
}
mysql_select_db($database_GSM_mobile, $GSM_mobile);

$query_rsPostalApp = "SELECT mod_model_id, mod_model_name, mod_type_id, type_table.type_type_id, type_table.type_type_name FROM model_table, type_table WHERE mod_type_id = $colname_rsPostalApp AND mod_model_id = $colname2_rs_PostalApp";
$rsPostalApp = mysql_query($query_rsPostalApp, $GSM_mobile) or die(mysql_error());
$row_rsPostalApp = mysql_fetch_assoc($rsPostalApp);
$totalRows_rsPostalApp = mysql_num_rows($rsPostalApp);
?><!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>
<SCRIPT>
// connect this function as shown below to a form button
function showData (form) {
  window.currentForm = form;
  form.oldAction = form.action;
  form.oldTarget = form.target;
  form.oldMethod = form.method;
  form.action = 'formPrintData.html';
  form.target = 'formData' + new Date().getTime();
  form.method = 'get';
  open ('', form.target);
  form.submit();
}
</SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
-->
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="postalprint.php">
  <p>Please fill out the following form:</p>
  <p>
  <label>
    <div align="center">Name
      <input name="txt_username" type="text" id="txt_username" />
    </label>
    <p align="center">
    <label>Return Address
    <input name="txt_rtn_add" type="text" id="txt_rtn_add" value="" />
    </label>
  </p>
  <p align="center">
    <label>Postcode
    <input name="txt_postcode" type="text" id="txt_postcode" />
    </label>
  </p>
  <p align="center">
    <label>Contact Number
    <input name="txt_contact_nr" type="text" id="txt_contact_nr" />
    </label>
  </p>
  <p align="center">
    <label>Email Address
    <input name="txt_email_add" type="text" id="txt_email_add" />
    </label>
</p>
  <p align="center">
    <label>Phone Make
    <input name="txt_phone_make" type="text" id="txt_phone_make" value="<?php echo $row_rsPostalApp['type_type_name']; ?>" />
    </label>
  </p>
  <p align="center">
    <label>Phone Model
    <input name="txt_phone_mobile" type="text" id="txt_phone_mobile" value="<?php echo $row_rsPostalApp['mod_model_name']; ?>" />
    </label>
  </p>
  <p align="center">
    <label>IMEI Number (enter *#06# on your handset)
    <input name="txt_IMEI_nr" type="text" id="txt_IMEI_nr" />
    </label>
  </p>
  <p align="center">
      <INPUT TYPE="button" VALUE="show data"
       ONCLICK="showData(this.form);"
>


  </p>
  <p>&nbsp;</p>
</form>
</body>
</html>
<?php
mysql_free_result($rsPostalApp);
?>
 
try to print your data to the page to debug stuff, e.g. echo Type_variable, and echo your query string to see what your feeding mySQL, believe me, it helps a big time!!
Change it back to the DW style and go with Dr_dedo's suggestion and post back...
So.. I tried the following statements at the end of the page.
<?php
echo $Type_variable;
echo $query_rsPostalApp;
?>

The first one Type_variable doesn't seem to return anything no matter what I try. (I also tried echo Type_variable;)
Am I writing it correctly.
The second statement seems to return a correct result:
Printed on the end of the screen is:
SELECT mod_model_id, mod_model_name, mod_type_id, type_table.type_type_id, type_table.type_type_name FROM model_table, type_table WHERE mod_type_id = 12 AND mod_model_id = 316
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks tried that and it gives the right result every time. Think I might have a better idea what the problem is. The recordset is returning the first value from the database (i.e. with a Type_variable of 1). Therefore it is probably trying all of the Type_variables to the text_box (which is the problem area where I want the Type_variable result to be displayed). Also, not sure if ye got this from the code but I'm trying to print the model_name and not the Type_variable. I'm only using the Type_variable parameter to filter the recordset. Not sure if I'm making perfect sense :)
Yeah, just tested it there again. If I put the mod_type_id instead of the mod_type_name in the text field it displays the correct result. Therefore the problem has something to do with the connectivity between the mod_type_name and the mod_type_id??
Got it sorted!!! I added another parameter to the SQL statement that linked the tables better. Changed the statement to look like this:
SELECT mod_model_id, mod_model_name, mod_type_id, type_table.type_type_id, type_table.type_type_name, type_table.type_type_id
FROM model_table, type_table
WHERE mod_type_id = colname AND  mod_model_id = colname2 AND mod_type_id = type_type_id

Thanks so much for all the help guys!
You're welcome.

How close are you to being done with this?  I'd love to see the live version...
Yeah I'd love to see the live version as well! Think about one more week or so and it should be ready to put something up. Don't worry you'll be the first to know about it :) This is my first project since I finished college course  a few years back so I'm quite rusty, thus all the questions!.
( Don't know if you had a chance to have a look at that dynamic drop-down problem since yesterday? https://www.experts-exchange.com/questions/21841380/Dynamically-Linked-drop-down-problem.html Can't seem to make sense of it at all! If you're too busy not a bother, I'll keep hacking away at it. anyways  :)
Vallenwood is helping you there, so I am taking a backseat out of courtesy to him.  
No probs at all!