?
Solved

Dreamweaver url variable passing problem

Posted on 2006-04-22
4
Medium Priority
?
477 Views
Last Modified: 2008-02-01
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
Comment
Question by:dereksheahan
3 Comments
 
LVL 4

Expert Comment

by:Vallenwood
ID: 16516067
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
 

Author Comment

by:dereksheahan
ID: 16533485
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
 

Accepted Solution

by:
GranMod earned 0 total points
ID: 16660817
Closed, 400 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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…
I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

840 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