I want to save the post value after submitting the form in my code, please help (in the field of the number of input fields)

require_once "db/database.php";
$db = new Database();
$db->connect(); 
foreach($_POST['add_to_cart'] as $id)
 {
 $select_datas = "SELECT * FROM sub_category where sub_category_id = $id";
 $display_datas = $db->executeStatement($select_datas);
 $get_sub_category_data_results=mysqli_fetch_assoc($display_datas); 
 $sub_category_name= $get_sub_category_data_results['sub_category_name'];
 $model_no= $get_sub_category_data_results['model_no'];
 $amount= $get_sub_category_data_results['amount'];

$result .= '<tr>';?>
<?php $result .= '<td> '.$sub_category_name.' </td>';?> 
<?php $result .= '<td> '.$model_no.'   </td>';?>
<?php $result .= '<td> '.$amount.'   </td>';?>
<?php $result .= '<td>' .'<input type="text"  value="'.(isset($_POST['quantity']) ?     $_POST['quantity'] : '').' "   name="quantity" />'.'</td></tr>';?>
<?php
 }
$result .= '</table>';
echo $result;

I want to save data after the form. if i use echobefore (isset($_POST['quantity']) ? $_POST['quantity'] : '')it showsParse error: syntax error, unexpected 'echo' (T_ECHO) in..

+3
source share
2 answers
<?php $quantity = isset($_POST['quantity']) ? $_POST['quantity'] : ''; ?>
<?php $result .= '<td>' .'<input type="text"  value="'. $quantity .' "   name="quantity" />'.'</td></tr>';?>

The above should work.

0
source

An echo is not required because you are already telling him to add the result of the if statement to the $ result variable, using .to combine them.

To save the value, $resultyou just need an echo value as the input value of the form to submit:

<input type='hidden' name='result' value='<?php echo $result?>'>

In addition, this line:

<?php $result .= '<td>' .'<input type="text"  value="'.(isset($_POST['quantity']) ?     $_POST['quantity'] : '').' "   name="quantity" />'.'</td></tr>';?>

Change to this:

<?php $result .= '<td>' .'<input type="text"  value="'.((isset($_POST['quantity'])) ?     $_POST['quantity'] : '').' "   name="quantity" />'.'</td></tr>';?>

The entire if statement must be enclosed in quotation marks for proper operation.

0
source

All Articles