简体   繁体   中英

php mysql query form send value to other page

i have troublesome with mysql query form here's my code example

    <?
    $query="select * from data where  data_id=".$data_id."  order by data_id desc";
    $result=mysql_query($query);
    while ($dataresult=mysql_fetch_array($result))
            {   
    ?>

   <form style="display:table-row-group" id="form_data" name="form_data" action="view/view_data"  method="get" >
   <input type="hidden" name="ref" id="ref" value="hv" readonly />
   <input type='hidden' name='dataid' id='dataid' value='<? echo"$dataresult[data_id]"?>' readonly />

    <?
    echo" name = $dataresult[name] <br> 
         <button class=buttonimage onclick=$('#form_data').submit() type=button >Pesan</button>";
     ?>

    </form>
    <?
     }
     ?>

example printscreen : name : john button select name : merry button select

and the output i want like this is one selected : you selected name john idnumber

but it's not working it's always show end of id from query example if i select name john but the result show name merry

any one can help? thank you

You are missing single quete on couple of places around name and change your echo button part as well.

echo" name =". $dataresult['name'].'<br>'; 
echo "<button class=buttonimage onclick=$('#form_data').submit() type=button >Pesan</button>";

<input type='hidden' name='dataid' id='dataid' value='<? echo"$dataresult[data_id]"?>' readonly />
<input type='hidden' name='dataid' id='dataid' value='<? echo"$dataresult['data_id']"?>' readonly />//Use this 

and use the php tag like this

<?php //Opening tag

?> //Closing tag

Also use mysqli_ function or PDO As mysql is deprecated.

Modified your code to work properly:

<?php
$query="select * from data where data_id=".$data_id."  order by data_id DESC";
$result=mysql_query($query);
while ($dataresult=mysql_fetch_assoc($result)) // You can use _array also but this one is preferred if using only keys
{   
?>
<form style="display:table-row-group" id="form_data" name="form_data" action="view/view_data"  method="get" >
<input type="hidden" name="ref" id="ref" value="hv" readonly="readonly" />
<input type="hidden" name="dataid" id="dataid" value="<?php echo $dataresult['data_id']; ?>"  readonly="readonly" />
<?php echo "name=".$dataresult['name']; ?> <br />
<button class="buttonimage" onclick="$('#form_data').submit();" type="button">Pesan</button>
</form>
<?php 
 }
 ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM