html - Saving a specific row using PHP and a search option -


i have following program, searchs text placed in previous php file, , displays results, adding radiobox check item purchased. not able make page save item checked items found new table, don't know how that, because items found placed fetched items, therefore don't know how select 1 save entire row selected. please help!.

<!doctype html> <html> <head>  <meta charset="utf-8"> <title>search option</title>  </head>  <body> <?php echo "<form action='slips.php' method='post'>"; if(isset($_post['name_prod2'])){  $word=$_post['name_prod2'];   $conn = oci_pconnect('dbname', 'password', 'localhost/xe'); if (!$conn) {     $e = oci_error();     trigger_error(htmlentities($e['error'], ent_quotes), e_user_error); }  $stid = oci_parse($conn, "select * product lower(name) '%" . $word . "%'"); oci_execute($stid);  echo "<table width='950' table border='1' align='center'>\n";     echo "<tr>\n";     echo "<th width='50'> <div align='center'>buy</div></th>";     echo "<th width='110'> <div align='center'>product id</div></th>";     echo "<th width='190'> <div align='center'>product name</div></th>";     echo "<th width='250'> <div align='center'>description</div></th>";     echo "<th width='100'> <div align='center'>in store</div></th>";     echo "<th width='100'> <div align='center'>price</div></th>";     echo "<th width='190'> <div align='center'>quantity purchase</div></th>";     echo "</tr>\n";  while ($product = oci_fetch_array($stid, oci_assoc+oci_return_nulls)) {      echo "<tr>\n";       //echo "<td><div style='text-align:center'><label><input type='radio' name='radio1' value='valor'></label></td></div>";     echo sprintf('<td><div style="text-align:center"><label><input type="radio" name="product" value="%s"></label></td></div>', $product['product_id']);      foreach ($product $aspect) {     echo '<td><div style="text-align:center">'.($aspect !== null ? htmlentities($aspect, ent_quotes) : '')."</td></div>\n";     }     echo '<td width="50"><div align="center"><input name="quantity" type="text" size="27" maxlength="50" placeholder="enter quantity"></div></td>';  } echo "</table>\n"; } echo "<div style='text-align:center'><input type='submit' value='comprar'></div>"; echo"</form>"; ?>  </body> </html> 

these 2 of javascripts have tried far complete this, fail tell me when 1 has been selected, don't know if can try adding code button, , when click it, tell me row radio box checked, , save it:

<script type="text/javascript" src="js/jquery.js"> </script> <script type="text/javascript">  var user_cat = $("input[radio1='user_cat']:checked").val(); if (!$("input[radio1='radio1']").is(':checked')) {    alert('nothing checked!'); } else {    alert('one of radio buttons checked!'); }  $(document).ready(function() {    $('#btnstatus').click(function(){       var ischecked = $('#rdselect').prop('checked');       alert(ischecked);    }); });  </script> 

when use line echo "<td><div style='text-align:center'><label><input type='radio' name='radio1' value='valor'></label></td></div>"; works , displays results

but when use line echo sprintf('<td><div style="text-align:center"><label><input type="radio" name="product" value="%d"></label></td></div>', $product['product_id']);it doesn't work , displays results

ok, picking information comments question , doing little guess work try point right direction. not possible give read-to-use answer, since still there things not clear, let's have try started...

i see have html form includes table. table has header row , dynamic generated rows holding product information each. want have radio button in front of each row allow select row. , want text input field @ end of each row allows enter quantity. want post information server able process it.

i stick "conservative" html approach , not introduce scripting here. reason purpose described before not required. let's keep things simple. nothing speaks against making things more complicated later on :-)

your radio buttons have changed, make no sense. have give individual value, can identify row has been selected later on. give them same static value 'value'. change loop iterates on products like:

while ($product = oci_fetch_array($stid, oci_assoc+oci_return_nulls)) {     echo "<tr>\n";       echo sprintf('<td><div style="text-align:center"><label><input type="radio" name="product" value="%s"></label></td></div>'."\n", $product['product_id']);      foreach ($row $aspect) {         echo '<td><div style="text-align:center">'              .($aspect !== null ? htmlentities($aspect, ent_quotes) : '')             ."</td></div>\n";     }     echo '<td width="50"><div align="center"><input name="quantity" type="text" size="27" maxlength="50" placeholder="enter quantity"></div></td>'."\n"; } 

note: took liberty change chosen names more logical product, aspect , quantity...

that all... when press submit button form should posted target specified: slips.php script of yours... inside script can access data that:

$product  = $_post['product']; $quantity = $_post['quantity']; 

there more issue worth discussing , modifying, said: let's keep things simple , take 1 step after other!


changelog:

  • changed literal key of array element used value inside radio button definition id procduct_id according 1 of comments below

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -