dereksheahan
asked on
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('../Connectio ns/gsm.php '); ?>
<?phpfunction GetSQLValueString($theValu e, $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_STR ING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUE RY_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_i d'], "int"),
GetSQLValueString($_POST[' det_userna me'], "text"),
GetSQLValueString($_POST[' det_email_ add'], "text"),
GetSQLValueString($_POST[' det_model_ id'], "int"),
GetSQLValueString($_POST[' det_if_oth er_text'], "text"),
GetSQLValueString($_POST[' monsters'] , "int"),
GetSQLValueString($_POST[' det_imei_n r'], "int"),
GetSQLValueString($_POST[' det_checke d'], "int"));
mysql_select_db($database_ gsm, $gsm);
$Result1 = mysql_query($insertSQL, $gsm) or die(mysql_error());
$insertGoTo = "thankyou.php";
if (isset($_SERVER['QUERY_STR ING'])) {
$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_userna me'], "text"),
GetSQLValueString($_POST[' det_email_ add'], "text"),
GetSQLValueString($_POST[' det_model_ id'], "int"),
GetSQLValueString($_POST[' det_if_oth er_text'], "text"),
GetSQLValueString($_POST[' monsters'] , "int"),
GetSQLValueString($_POST[' det_imei_n r'], "int"),
GetSQLValueString($_POST[' det_checke d'], "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_rsNetwo rknew, $gsm) or die(mysql_error());
$row_rsNetworknew = mysql_fetch_assoc($rsNetwo rknew);
$totalRows_rsNetworknew = mysql_num_rows($rsNetworkn ew);
$colname_rsModel = "-1";
if (isset($_GET['Type_variabl e'])) {
$colname_rsModel = (get_magic_quotes_gpc()) ? $_GET['Type_variable'] : addslashes($_GET['Type_var iable']);
}
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_ad d:</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> </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['ty pe_type_id '], $row_rsModel['mod_model_na me']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsModel['mod_model_na me']?></op tion>
<?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_net work_id']? >"><?php echo $row_rsNetworknew['net_net work_name' ]?></optio n>
<?php
} while ($row_rsNetworknew = mysql_fetch_assoc($rsNetwo rknew));
$rows = mysql_num_rows($rsNetworkn ew);
if($rows > 0) {
mysql_data_seek($rsNetwork new, 0);
$row_rsNetworknew = mysql_fetch_assoc($rsNetwo rknew);
}
?>
</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"> </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> </p>
<?php
mysql_free_result($rsNetwo rknew);
mysql_free_result($rsModel );
?>
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('../Connectio
<?phpfunction GetSQLValueString($theValu
{
$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_STR
$editFormAction .= "?" . htmlentities($_SERVER['QUE
}
if ((isset($_POST["MM_insert"
$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['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
mysql_select_db($database_
$Result1 = mysql_query($insertSQL, $gsm) or die(mysql_error());
$insertGoTo = "thankyou.php";
if (isset($_SERVER['QUERY_STR
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
if ((isset($_POST["MM_insert"
$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['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
mysql_select_db($database_
$Result1 = mysql_query($insertSQL, $gsm) or die(mysql_error());
}
mysql_select_db($database_
$query_rsNetworknew = "SELECT network_table.net_network_
$rsNetworknew = mysql_query($query_rsNetwo
$row_rsNetworknew = mysql_fetch_assoc($rsNetwo
$totalRows_rsNetworknew = mysql_num_rows($rsNetworkn
$colname_rsModel = "-1";
if (isset($_GET['Type_variabl
$colname_rsModel = (get_magic_quotes_gpc()) ? $_GET['Type_variable'] : addslashes($_GET['Type_var
}
mysql_select_db($database_
$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
$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_ad
<td><input type="text" name="det_email_add" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Det_model_id
<td><p> </p>
<p>
<label>model_id
<select name="modeldrop" id="modeldrop">
<?php
do {
?><option value="<?php echo $row_rsModel['type_type_id
<?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_net
<?php
} while ($row_rsNetworknew = mysql_fetch_assoc($rsNetwo
$rows = mysql_num_rows($rsNetworkn
if($rows > 0) {
mysql_data_seek($rsNetwork
$row_rsNetworknew = mysql_fetch_assoc($rsNetwo
}
?>
</select>
</label></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Det_if_other
<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><input type="text" name="det_imei_nr" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </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> </p>
<?php
mysql_free_result($rsNetwo
mysql_free_result($rsModel
?>
ASKER
Hi Vallenwood,
Thanks got it sorted myself. The problem was I didn't have the url parameter named in the correct locations.
Cheers,
Derek
Thanks got it sorted myself. The problem was I didn't have the url parameter named in the correct locations.
Cheers,
Derek
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.)