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

Why isn't this script passing any variables??

Options
  • 09-04-2006 6:44pm
    #1
    Closed Accounts Posts: 8,866 ✭✭✭


    [PHP]<?php

    include 'functions.php';
    include 'header.php';

    ?>

    <form name=frm1 action="p_edit_all_do.php" method=post>
    <input type=hidden name=num_rows value="<?=$num_rows?>">
    <table width=95% cellspacing=0 cellpadding=1 border=0 class=newtbl>

    <tr>
    <th width=100% colspan=10>Contact Names & Details</td>
    </tr>
    <tr>
    <td> </td>
    </tr>

    <?


    $sql="SELECT * FROM tbl_customer WHERE customer_deleted!='1' AND (customer_name LIKE '{$v}%')";
    $result = mysql_query($sql) or die("Query failed : " . mysql_error());
    $num_rows = mysql_num_rows($result);

    for($counter=0;$counter<$num_rows;$counter++) {
    $row = mysql_fetch_array($result, MYSQL_ASSOC);


    print("<tr>");
    print("<input type=hidden name=line_".$counter."_id value=\"$row[customer_id]\">");
    print("<td><input type=input name=line_".$counter."_customer_name style='width:272' value=\"$row[customer_name]\"></td>");
    print("<td><input type=hidden name=line_".$counter."_customer_name value=\"$row[customer_name]\"></td>");
    print("<td><input type=input name=line_".$counter."_customer_address1 value=\"$row[customer_address1]\"></td>");
    print("<td><input type=hidden name=line_".$counter."_customer_address1 value=\"$row[customer_address1]\"></td>");
    print("<td><input type=input name=line_".$counter."_customer_address2 value=\"$row[customer_address2]\"></td>");
    print("<td><input type=hidden name=line_".$counter."_customer_address2 value=\"$row[customer_address2]\"></td>");
    print("<td><input type=input name=line_".$counter."_customer_phone value=\"$row[customer_phone]\"></td>");
    print("<td><input type=hidden name=line_".$counter."_customer_phone value=\"$row[customer_phone]\"></td>");
    print("</tr>");


    }

    ?>

    <tr>
    <td> </td>
    </tr>
    <tr>
    <td> </td>
    </tr>
    <tr>
    <td width=70% align=right><?=arrow("Save ","frm1.submit()")?></td>
    </tr>
    </table>
    </form>

    <?=arrow("Back ","window.location='p_edit_all_select.php'")?>

    </BODY>
    </HTML>

    [/PHP]

    I'm getting nothing on p_edit_all_do.php...not even the hidden input num_rows...:confused:


Comments

  • Registered Users Posts: 249 ✭✭frost


    you haven't closed your <form> tag


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


    God...I'm an idiot! And your a legend, cheers! :D


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


    Wait, it still doesn't work...:confused:


  • Registered Users Posts: 249 ✭✭frost


    can you post the generated html from the first and second pages? ie, browse to the page and view source. i'll try it here and see if i can figure it out


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


    That'd be a bit of a pain, i'd have to edit out a lot of stuff for security reasons. Is there a specific part I could edit and post?

    If its the select results your curious about it all works fine there, for example a source result looks like this:

    [HTML]<tr><input type=hidden name=line_1_id value="456"><td><input type=input name=line_1_customer_name style='width:272' value="Customer bob"></td><td><input type=hidden name=line_1_customer_name value="customer bob"></td><td><input type=input name=line_1_customer_address1 value="beach street"></td><td><input type=hidden name=line_1_customer_address1 value="beach street"></td><td><input type=input name=line_1_customer_address2 value="beach road"></td><td><input type=hidden name=line_1_customer_address2 value="beach road"></td><td><input type=input name=line_1_customer_phone value="01-2345678"></td><td><input type=hidden name=line_1_customer_phone value="01-2345678"></td></tr>[/HTML]


  • Advertisement
  • Registered Users Posts: 249 ✭✭frost


    security reasons? you aren't revealing anything important in the HTML you are passing to the browser, are you?

    anyway, i played with it here and it works ok for me served from apache to firefox browser.
    i did notice a few things:
    you have a <th> instead of a <td> tag towards the top
    your input type=input should probably be type = text
    the hidden inputs have the same name as the non-hidden ones, which mean you won't be able to retrieve the value of one of them.

    but all that said, i am able to retrieve the values in the $_POST array.


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


    Fair point, sorry, I wasn't really thinking tbh!

    Ok now the customer details pass, but $num_rows just wont pass at all... and it does have a value, if i debug it in the first script it gives the correct value... :confused:

    EDIT: the reason I need it to pass is because the next script does this:

    NB: i replaced $counter with $i in both scripts so i havent got two different counters.

    [PHP]<?php

    include 'functions.php';
    include 'header.php';


    for($i=0; $i<$_REQUEST; $i++) {

    $id = $_REQUEST["line_".$i."_id"];
    $SQL = "UPDATE tbl_customer SET customer_name =
    {$_REQUEST}, customer_address1 =
    {$_REQUEST}, customer_address2 =
    {$_REQUEST}, customer_phone =
    {$_REQUEST} WHERE customer_id = $id";

    debug($SQL);
    $result = mysql_query($SQL) or die("Query failed : " . mysql_error());

    }
    ?>[/PHP]


  • Closed Accounts Posts: 2,046 ✭✭✭democrates


    $num_rows is being output to the page before it gets a value from the query result.

    You can slap that hidden form field after the list of rows (but before the terminating form tag...)

    As mentioned by frost, view source will reveal if all hidden form fields contain expected values.


  • Registered Users Posts: 249 ✭✭frost


    democrates wrote:
    $num_rows is being output to the page before it gets a value from the query result.

    Yes. Nice catch, Democrates.


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


    Got it sorted, cheers lads!


  • Advertisement
  • Registered Users Posts: 4,003 ✭✭✭rsynnott




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


    Nice one for pointing that out, I was unaware of such security issues! :eek:

    However that won't be a problem here, but I'll be sure to take that under advisement in the future, thanks!


Advertisement