• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 485
  • Last Modified:

Dreamweaver url variable passing problem

Hi all,
Having a problem displaying the results of passing a url variable from one page to another. I can get the result to display in a single text page but when I try to put the results in a drop down menu it doesn't seem to work. This is what I've done so far.

The drop-menu is called "modeldrop".I've added a recordset on the results page and filtered it by passing the url variable (called type_variable). Then whenl I try to  display the results of this query in a dynamic drop-menu it comes out blank. I know the variable is passed as it says it in the title of the page (e.g. http://localhost/GSM/index.php?Type_variable=1). Anyone have any ideas where I'm going wrong??
Thanks,
Derek

Here's the code:
<?php require_once('../Connections/gsm.php'); ?>
<?phpfunction GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  $insertSQL = sprintf("INSERT INTO details_table (det_user_id, det_username, det_email_add, det_model_id, det_if_other_text, det_network_id, det_imei_nr, det_checked) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['det_user_id'], "int"),
                       GetSQLValueString($_POST['det_username'], "text"),
                       GetSQLValueString($_POST['det_email_add'], "text"),
                       GetSQLValueString($_POST['det_model_id'], "int"),
                       GetSQLValueString($_POST['det_if_other_text'], "text"),
                       GetSQLValueString($_POST['monsters'], "int"),
                       GetSQLValueString($_POST['det_imei_nr'], "int"),
                       GetSQLValueString($_POST['det_checked'], "int"));

  mysql_select_db($database_gsm, $gsm);
  $Result1 = mysql_query($insertSQL, $gsm) or die(mysql_error());

  $insertGoTo = "thankyou.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  $insertSQL = sprintf("INSERT INTO details_table (det_user_id, det_username, det_email_add, det_model_id, det_if_other_text, det_network_id, det_imei_nr, det_checked) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['monsters'], "int"),
                       GetSQLValueString($_POST['det_username'], "text"),
                       GetSQLValueString($_POST['det_email_add'], "text"),
                       GetSQLValueString($_POST['det_model_id'], "int"),
                       GetSQLValueString($_POST['det_if_other_text'], "text"),
                       GetSQLValueString($_POST['monsters'], "int"),
                       GetSQLValueString($_POST['det_imei_nr'], "int"),
                       GetSQLValueString($_POST['det_checked'], "int"));

  mysql_select_db($database_gsm, $gsm);
  $Result1 = mysql_query($insertSQL, $gsm) or die(mysql_error());
}

mysql_select_db($database_gsm, $gsm);
$query_rsNetworknew = "SELECT network_table.net_network_id, network_table.net_network_name FROM network_table";
$rsNetworknew = mysql_query($query_rsNetworknew, $gsm) or die(mysql_error());
$row_rsNetworknew = mysql_fetch_assoc($rsNetworknew);
$totalRows_rsNetworknew = mysql_num_rows($rsNetworknew);

$colname_rsModel = "-1";
if (isset($_GET['Type_variable'])) {
  $colname_rsModel = (get_magic_quotes_gpc()) ? $_GET['Type_variable'] : addslashes($_GET['Type_variable']);
}
mysql_select_db($database_gsm, $gsm);
$query_rsModel = sprintf("SELECT mod_model_id, mod_model_name, mod_type_id, type_table.type_type_id FROM model_table, type_table WHERE type_type_id = %s", $colname_rsModel);
$rsModel = mysql_query($query_rsModel, $gsm) or die(mysql_error());
$row_rsModel = mysql_fetch_assoc($rsModel);
$totalRows_rsModel = mysql_num_rows($rsModel);
?><form name="form1" method="post" action="">
</form>

<form method="POST" name="form2" action="<?php echo $editFormAction; ?>">
  <table width="352" height="235" align="center">
    <tr valign="baseline">
      <td width="119" align="right" nowrap>Det_username:</td>
      <td width="192"><input type="text" name="det_username" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Det_email_add:</td>
      <td><input type="text" name="det_email_add" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Det_model_id:</td>
      <td><p>&nbsp;</p>
        <p>
          <label>model_id
          <select name="modeldrop" id="modeldrop">
            <?php
do {  
?><option value="<?php echo $row_rsModel['type_type_id']?>"<?php if (!(strcmp($row_rsModel['type_type_id'], $row_rsModel['mod_model_name']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsModel['mod_model_name']?></option>
            <?php
} while ($row_rsModel = mysql_fetch_assoc($rsModel));
  $rows = mysql_num_rows($rsModel);
  if($rows > 0) {
      mysql_data_seek($rsModel, 0);
        $row_rsModel = mysql_fetch_assoc($rsModel);
  }
?>
          </select>
          </label>
</p></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><p>Choose a network: </p>      </td>
      <td><label>
      <select name="monsters" id="monsters">
        <?php
do {  
?>
        <option value="<?php echo $row_rsNetworknew['net_network_id']?>"><?php echo $row_rsNetworknew['net_network_name']?></option>
        <?php
} while ($row_rsNetworknew = mysql_fetch_assoc($rsNetworknew));
  $rows = mysql_num_rows($rsNetworknew);
  if($rows > 0) {
      mysql_data_seek($rsNetworknew, 0);
        $row_rsNetworknew = mysql_fetch_assoc($rsNetworknew);
  }
?>
      </select>
      </label></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Det_if_other_text:</td>
      <td><input type="text" name="det_if_other_text" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Det_imei_nr:</td>
      <td><input type="text" name="det_imei_nr" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input name="submit" type="submit" value="Insert record"></td>
    </tr>
  </table>
  <input type="hidden" name="det_user_id" value="">
  <input type="hidden" name="det_checked" value="">
  <input type="hidden" name="MM_insert" value="form2">
</form>
<p>&nbsp;</p>
<?php
mysql_free_result($rsNetworknew);

mysql_free_result($rsModel);
?>
0
dereksheahan
Asked:
dereksheahan
1 Solution
 
VallenwoodCommented:
It's always hard to debug a script I'm not running myself, since there's so much trial and error. But one thing stood out right away. Your SQL query says:

SELECT mod_model_id, mod_model_name, mod_type_id, type_table.type_type_id FROM model_table, type_table WHERE type_type_id = %s

But it should probably say:

SELECT mod_model_id, mod_model_name, mod_type_id, type_table.type_type_id FROM model_table, type_table WHERE type_type_id = '%s'

Because MySQL expects it to be in single-quotes. (You'll notice up above, where the Dreamweaver-generated insert query has "VALUES(%s,%s,%s..." the values themselves are enlosed in single quotes by the "GetSQLValueString" function call which prepares them for entry.)
0
 
dereksheahanAuthor Commented:
Hi Vallenwood,
Thanks got it sorted myself. The problem was I didn't have the url parameter named in the correct locations.
Cheers,
Derek
0
 
GranModCommented:
Closed, 400 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now