close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Don´t save the correct value.

Thread began 12/04/2014 8:24 am by Juan | Last modified 12/04/2014 12:28 pm by Jason Byrnes | 545 views | 1 replies |

Juan

Don´t save the correct value.

Hi all seems to work fine when you run the page. But when value is saved on database from clild field it saves the id_value instead of the value displayed on page...



<?php require_once('../Connections/bichos.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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"] == "insert")) {
$insertSQL = sprintf("INSERT INTO eventos_complementos (id_evento, id_complemento, precio) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['Child'], "text"),
GetSQLValueString($_POST['Child'], "text"),
GetSQLValueString($_POST['Child'], "text"));

mysql_select_db($database_bichos, $bichos);
$Result1 = mysql_query($insertSQL, $bichos) or die(mysql_error());
}

mysql_select_db($database_bichos, $bichos);
$query_Parent = "SELECT * FROM platillos_especiales";
$Parent = mysql_query($query_Parent, $bichos) or die(mysql_error());
$row_Parent = mysql_fetch_assoc($Parent);
$totalRows_Parent = mysql_num_rows($Parent);

mysql_select_db($database_bichos, $bichos);
$query_Child = "SELECT * FROM platillos_especiales";
$Child = mysql_query($query_Child, $bichos) or die(mysql_error());
$row_Child = mysql_fetch_assoc($Child);
$totalRows_Child = mysql_num_rows($Child);

function WA_DD_Replace($startStr) {
$startStr = str_replace("'", "|WA|", $startStr);
$startStr = str_replace("\\", "\\\\", $startStr);
$startStr = preg_replace("/[\r\n]{1,}/", " ", $startStr);
return $startStr;
}
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<?php
if ($row_Child) {
echo "<SC" . "RIPT>\n";
echo "var WAJA = new Array();\n";

$oldmainid = 0;
$newmainid = $row_Child["id_platillo"];
if ($oldmainid == $newmainid) {
$oldmainid = "";
}
$n = 0;
while ($row_Child) {
if ($oldmainid != $newmainid) {
echo "WAJA[".$n."] = new Array();\n";
echo "WAJA[".$n."][0] = '".WA_DD_Replace($newmainid)."';\n";
$m = 1;
}

echo "WAJA[".$n."][".$m."] = new Array();\n";
echo "WAJA[".$n."][".$m."][0] = "."'".WA_DD_Replace($row_Child["id_platillo"])."'".";\n";
echo "WAJA[".$n."][".$m."][1] = "."'".WA_DD_Replace($row_Child["precio"])."'".";\n";

$m++;
if ($oldmainid == 0) {
$oldmainid = $newmainid;
}
$oldmainid = $newmainid;
$row_Child = mysql_fetch_assoc($Child);
if ($row_Child) {
$newmainid = $row_Child["id_platillo"];
}
if ($oldmainid != $newmainid) {
$n++;
}
}

echo "var Child_WAJA = WAJA;\n";
echo "WAJA = null;\n";
echo "</SC" . "RIPT>\n";
}
?>
<script type="text/javascript">
function WA_ClientSideReplace(theval,findvar,repvar) {
var retval = "";
while (theval.indexOf(findvar) >= 0) {
retval += theval.substring(0,theval.indexOf(findvar));
retval += repvar;
theval = theval.substring(theval.indexOf(findvar) + String(findvar).length);
}
retval += theval;
if (retval == "" && theval.indexOf(findvar) < 0) {
retval = theval;
}
return retval;
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function WA_UnloadList(thelist,leavevals,bottomnum) {
while (thelist.options.length > leavevals+bottomnum) {
if (thelist.options[leavevals]) {
thelist.options[leavevals] = null;
}
}
return leavevals;
}

function WA_FilterAndPopulateSubList(thearray,sourceselect,targetselect,leaveval,bottomleave,usesource,delimiter) {
if (bottomleave > 0) {
leaveArray = new Array(bottomleave);
if (targetselect.options.length >= bottomleave) {
for (var m=0; m<bottomleave; m++) {
leavetext = targetselect.options[(targetselect.options.length - bottomleave + m)].text;
leavevalue = targetselect.options[(targetselect.options.length - bottomleave + m)].value;
leaveArray[m] = new Array(leavevalue,leavetext);
}
}
else {
for (var m=0; m<bottomleave; m++) {
leavetext = "";
leavevalue = "";
leaveArray[m] = new Array(leavevalue,leavetext);
}
}
}
startid = WA_UnloadList(targetselect,leaveval,0);
mainids = new Array();
if (usesource) maintext = new Array();
for (var j=0; j<sourceselect.options.length; j++) {
if (sourceselect.options[j].selected) {
mainids[mainids.length] = sourceselect.options[j].value;
if (usesource) maintext[maintext.length] = sourceselect.options[j].text + delimiter;
}
}
for (var i=0; i<thearray.length; i++) {
goodid = false;
for (var h=0; h<mainids.length; h++) {
if (thearray[i][0] == mainids[h]) {
goodid = true;
break;
}
}
if (goodid) {
theBox = targetselect;
theLength = parseInt(theBox.options.length);
theServices = thearray[i].length + startid;
var l=1;
for (var k=startid; k<theServices; k++) {
if (l == thearray[i].length) break;
theBox.options[k] = new Option();
theBox.options[k].value = thearray[i][l][0];
if (usesource) theBox.options[k].text = maintext[h] + WA_ClientSideReplace(thearray[i][l][1],"|WA|","'");
else theBox.options[k].text = WA_ClientSideReplace(thearray[i][l][1],"|WA|","'");
l++;
}
startid = k;
}
}
if (bottomleave > 0) {
for (var n=0; n<leaveArray.length; n++) {
targetselect.options[startid+n] = new Option();
targetselect.options[startid+n].value = leaveArray[n][0];
targetselect.options[startid+n].text = leaveArray[n][1];
}
}
for (var l=0; l < targetselect.options.length; l++) {
targetselect.options[l].selected = false;
}
if (targetselect.options.length > 0) {
targetselect.options[0].selected = true;
}
}
</script>
</head>

<body>

<form method="POST" action="<?php echo $editFormAction; ?>" name="insert" id="insert">

<select name="Parent" size="10" id="Parent" onChange="WA_FilterAndPopulateSubList(Child_WAJA,MM_findObj('Parent'),MM_findObj('Child'),0,0,false,': ')">
<?php
do {
?>
<option value="<?php echo $row_Parent['id_platillo']?>"><?php echo $row_Parent['nombre_platillo']?></option>
<?php
} while ($row_Parent = mysql_fetch_assoc($Parent));
$rows = mysql_num_rows($Parent);
if($rows > 0) {
mysql_data_seek($Parent, 0);
$row_Parent = mysql_fetch_assoc($Parent);
}
?>
</select>


<select name="Child" id="Child"></select>


<input name="Add" type="submit" id="Add" value="Add to list">
<input type="hidden" name="MM_insert" value="insert">


</form>


</body>
</html>
<?php
mysql_free_result($Parent);

mysql_free_result($Child);
?>

Sign in to reply to this post

Jason ByrnesWebAssist

I don't follow what you mean, please provide some additional details.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...