0

This is my code for a jquery mobile application. But the form i created with php result is not working. Form is not posting data on submit. I even tried data-ajax="flase".

<table id="stock">
<? $sql = mysqli_query($con, "SELECT * FROM products WHERE `product_id` = '1'");
    while($row=mysqli_fetch_array($sql)){
        $name = $row['name'];
        $chamecal = $row['chamecal'];
        $price = $row['selling_price'];
        $bprice = $row['buying_price'];
        $quantity = $row['quantity'];
        $manufacturer = $row['manufacturer'];
        $date = $row['date'];
        $edate = $row['expire'];
        $pid = $row['product_id'];
?>
   <form id="stockupdate" method="post" action="medupdate.php">
    <tr>
        <td><?=$name;?></td>
        <td><?=$chamecal;?></td>
        <td><?=$manufacturer;?></td>
        <td><input type="text" name="medbprice" value="<?=$bprice;?>" /></td>
        <td><input type="text" name="medprice" value="<?=$price;?>" /></td>
        <td><?=$date;?></td>
        <td><?=$edate;?></td>
        <td><input type="text" name="medstock" value="<?=$quantity;?>" /></td>
        <td class="ui-screen-hidden"><input type="text" name="pid" value="<?=$pid;?>" /></td>
        <td>
            <input type="submit" title="Update" data-icon="gear" data-theme="f" data-inline="true" data-iconpos="notext" />
        </td>
    </tr>
<?    
    } 
?>
</form>
</table>

Values Handler file medupdate.php

<?php session_start();?>
<?php include_once('include/config.php');?>
<?
$pid        = $_POST['pid'];
$medbprice  = $_POST['medbprice'];
$medprice   = $_POST['medprice'];
$medstock   = $_POST['medstock'];

$sql = mysqli_query($con, "UPDATE `products` SET `quantity` = '$medstock', `buying_price` = '$medbprice' , `selling_price` = '$medprice' WHERE `product_id` = '$pid'");

if($sql){
echo 1;
}
?>
5
  • We need to see the code where you handle the posted values. I can't see a single $_POST global variable in the code you have posted. If the above code is complete, it won't process any of your form data... search Google for 'PHP handle posted values' etc. Commented Oct 15, 2013 at 9:32
  • @R. David is this a mobile app or regular website with jquery mobile supported for responsive ...? Commented Oct 15, 2013 at 9:47
  • @SathyaRaj regular website with jquery mobile supported for responsive. Commented Oct 15, 2013 at 9:49
  • did you mean to write data-ajax="false" or do you really have ="flase"? Commented Oct 15, 2013 at 13:02
  • i tried data-ajax="false". Whatever someone answered my question. The problem was <form> inside <table>. Commented Oct 15, 2013 at 13:05

2 Answers 2

1

If I was to hazard a guess, it's because you're placing

<form id="stockupdate" method="post" action="medupdate.php">

directly within a table element (which is invalid markup). Move this outside your table (before your <table>). When you create invalid markup, the browsers engine tries to correct it which can lead to issues like this.

This is what chrome does to your markup:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

It's a valid point, but he doesn't actually handle the POSTED values anywhere in his code.
1

You cannot follow the html structure, a form inside table like,

<table>
   <form>
     <tr>
        <td>
        </td>
     </tr>
   </form>
</table>

Here is the working code,

Form php

<!DOCTYPE html>


<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
    </head>



    <body>
        <form id="stockupdate" method="post" action="medupdate.php" data-ajax="false">
            <table>
                <tr>
                    <td><input type="text" name="medbprice" value="xxxx" /></td>
                    <td><input type="text" name="medprice" value="yyyyy" /></td>
                    <td><input type="text" name="medstock" value="zzzzzz" /></td>
                    <td class="ui-screen-hidden"><input type="text" name="pid" value="111111" /></td>
                    <td>
                        <input type="submit" title="Update" data-icon="gear" data-theme="f" data-inline="true" data-iconpos="notext" />
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>

medupdate.php

<?php 
session_start();
$pid        = $_POST['pid'];
$medbprice  = $_POST['medbprice'];
$medprice   = $_POST['medprice'];
$medstock   = $_POST['medstock'];
echo $pid;
// your database operations
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.