Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

select box not passing variable(php)

Options
  • 22-03-2006 6:25pm
    #1
    Closed Accounts Posts: 8,866 ✭✭✭


    removed


Comments

  • Closed Accounts Posts: 70 ✭✭vito


    maybe you could show us your pickselected() function and also what is in array $v and how is it set?

    Whats being output to the browser? Does your select element get populated with options?

    very difficult to see whats going on with the code you have posted.

    sorry cant help more...

    Vito


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    $v is set like this:
    foreach($_REQUEST as $key=>$val) {
    $v[$key]=$val;

    the output is fine, the select box is populated correctly.I'll highlight the parts that are relevant to my question.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    As far as i know the bold parts are the relevant bits. The bold line if(isset($v)){ isn't being executed, so obviously $customer_id2 isn't being set. That make more sense?


  • Closed Accounts Posts: 70 ✭✭vito


    where did you set $customer_id2?

    should this be $v?

    <input type=hidden name=customer_id2 value="<?=$v?>">

    I think this is the problem.


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    i beleive that the pickselected() function has the <option value='your value'>your value</option> inside.
    show us the html of the form.


  • Advertisement
  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    That is the html of the form, thats the whole page...

    Here's the pickselected() funtion:
    function pickselected($textIn,$selected){

    if($selected==="") {
    return $textIn;
    }
    else
    {

    $t=$textIn;
    $t = str_replace("value=\"{$selected}\"","value=\"{$selected}\" selected",$t);
    $t = str_replace("value='{$selected}'","value=\"{$selected}\" selected",$t);
    if($selected!="")
    $t = str_replace("value={$selected}","value=\"{$selected}\" selected",$t);
    return $t;
    }
    }


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    Try this in your code:
    <?php 
    $x_CustomerID = $_POST['customer_id2'];
    if (!(!is_null($x_CustomerID)) || ($x_CustomerID == "")) { $x_CustomerID = "setdefaultvalue_here";} // Set default value ?>
    <?php
    $x_CustomerIDList = "<select name=\"Customer_ID2\">";
    $x_CustomerIDList .= "<option value=''>Please Select</option>";
    $SQL = "SELECT * FROM `tbl_customer` WHERE `customer_deleted` <> 1 AND `customer_id` <>'".$v['customer_id']."' ORDER BY `customer_name`";
    $_result = mysql_query($SQL) or die("Query failed : " . mysql_error());
    //mysql_query($SQL) or die("Query failed : " . mysql_error());
    
    if ($_result) {
    	$rowcntwrk = 0;
    	while ($datawrk = mysql_fetch_array($_result)) {
    		$x_CustomerIDList .= "<option value=\"" . htmlspecialchars($datawrk[0]) . "\"";
    		if ($datawrk["customer_id"] == @$x_CustomerID) {
    			$x_CustomerIDList .= "' selected";
    		}
    		$x_CustomerIDList .= ">" . $datawrk["customer_id"] . "</option>";
    		$rowcntwrk++;
    	}
    }
    @mysql_free_result($_result);
    $x_CustomerIDList .= "</select>";
    echo $x_CustomerIDList;
    ?>
    

    also you have 2 fields in your form named customer_id2
    <input type=hidden name=customer_id2 value="<?=$customer_id2?>">


  • Closed Accounts Posts: 70 ✭✭vito


    That is the html of the form, thats the whole page...

    Here's the pickselected() funtion:

    function pickselected($textIn, $selected = null){
    return (!$selected || $selected == '') ? str_replace("value=\"{$selected}\"", "value=\"{$selected}\" selected", $textIn) : $textIn;
    }

    Not sure that this will fix it but certain that what you had previously was actually replacing value=\"{$selected}\" 3 times. Try it and if it doesn't work post the source of the html page that your function is parsing. I think it might contain some errors based on your pickselected script.


Advertisement