[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Passing URL parameter problem

Posted on 2006-05-09
16
Medium Priority
?
468 Views
Last Modified: 2010-04-25
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);
?>
0
Comment
Question by:dereksheahan
  • 8
  • 6
  • 2
16 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16641146
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?  
0
 

Author Comment

by:dereksheahan
ID: 16641239
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);
?>
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16641561
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...
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 900 total points
ID: 16641750
Well, he fell asleep :)

Derek, let's lose the DW query format.  From your initial post, change the query to:

$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";

Does that get it to function properly?
0
 

Author Comment

by:dereksheahan
ID: 16642601
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);
?>
 
0
 
LVL 16

Expert Comment

by:dr_dedo
ID: 16643111
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!!
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16643294
Change it back to the DW style and go with Dr_dedo's suggestion and post back...
0
 

Author Comment

by:dereksheahan
ID: 16643572
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
0
 
LVL 16

Accepted Solution

by:
dr_dedo earned 600 total points
ID: 16643667
guess you should echo $colname_rsPostalApp or $_GET['Type_variable']

your query seems fine to me, no bizzar stuff in it, try to type it directly into mysql or into mysql query brower
0
 

Author Comment

by:dereksheahan
ID: 16643750
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 :)
0
 

Author Comment

by:dereksheahan
ID: 16643781
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??
0
 

Author Comment

by:dereksheahan
ID: 16643817
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!
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16643842
You're welcome.

How close are you to being done with this?  I'd love to see the live version...
0
 

Author Comment

by:dereksheahan
ID: 16643890
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? http://www.experts-exchange.com/Web/WebDevSoftware/DreamWeaver/Q_21841380.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  :)
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16643907
Vallenwood is helping you there, so I am taking a backseat out of courtesy to him.  
0
 

Author Comment

by:dereksheahan
ID: 16643918
No probs at all!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question