Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-31-2011, 06:04 PM   PM User | #1
turpentyne
Regular Coder

 
Join Date: Aug 2010
Posts: 309
Thanks: 10
Thanked 1 Time in 1 Post
turpentyne is an unknown quantity at this point
2nd var won't pass to php query

gah! Just when I thought I had this script done, I run into another issue.

I can't seem to pass a variable from the second dropdown, so that it puts it in the database. The query works just fine. The dropdown populates just fine. But somehow the id of the second dropdown isn't going to the query. I have the plant_id passed from a previous page and added as a hidden field. I just need that subcat id..


PHP Code:



<?php 

if (isset($_POST['submit'])){

require (
'db.php');

    
$pi mysql_real_escape_string($_POST['plant_id']);
    
$term mysql_real_escape_string($_POST['subcat']);
 
// this term variable is what I want into term id
$query "INSERT INTO termin_connect_to_plants(plant_id, term_id) VALUES ('$pi', '$term')";
echo 
$query
// deleting echo query when done with script
    
$result mysql_query ($query);

    if (
mysql_affected_rows() == 1) {
    echo 
'your plant has been updated';
    }
}
?>

<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<script type="text/javascript">

function reload(form,var2)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
var val2='var2';

self.location='edit_user15.php?cat=' + val + '&id=' + val2 ;
}

</script>
</head>

<body>


<? 
require ('db.php');

if ((isset(
$_GET['id'])) && (is_numeric($_GET['id']))) {

    
$id $_GET['id'];

}

@
$cat=$_GET['cat']; 
if(
strlen($cat) > and !is_numeric($cat)){  
echo 
"Data Error";
exit;
}


//@$cat=$HTTP_GET_VARS['cat']; // Use this line or above line if register_global is off


$quer2=mysql_query("SELECT DISTINCT part,id FROM plant_parts order by part"); 


if(isset(
$cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT part,id FROM terminology where List1Ref=$cat order by part"); 
}else{
$quer=mysql_query("SELECT DISTINCT part FROM terminology order by part"); }
 
// the above works. It's populating dropdowns



echo "<br><br><form method=post name=f1 action=''>";

echo 
"<select name='cat' onchange=\"reload(this.form,1) \"><option value=''>Select one</option>";
while(
$row mysql_fetch_array($quer2)) { 
if(
$row[id]==@$cat){echo "<option selected value='$row[id]'>$row[part]</option>"."<BR>";}
else{echo  
"<option value='$row[id]'>$row[part]</option>";}
}
echo 
"</select>";


//////////        Starting of second drop downlist /////////
echo "<select name='subcat' onchange=\"reload(this.form) \"><option value=''>Select one</option>";
while(
$row mysql_fetch_array($quer)) { 

echo  
"<option value='$row[id]'>$row[id] $row[part]</option>";

}
echo 
"</select>";

//  above id row variable is what I need to pass. I put it in the visible part of the option value to show that it is indeed pulling the data. and it is. I just can't pass it
//////////////////  This will end the second drop down list ///////////

echo "<input type='hidden' name='plant_id' value=".$id.">  

<input type=submit name=submit value=submit>"
;
echo 
"</form>";

?>


</body>

</html>
turpentyne is offline   Reply With Quote
Old 11-02-2011, 11:54 AM   PM User | #2
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
Quote:
if($row[id]
Shouldn't' be:
Code:
if($row[$id]
or
Code:
if($row["id"]
?
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:20 AM.


Advertisement
Log in to turn off these ads.