Click here to Skip to main content
16,020,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below is a function called add_total(); which i use to save typed input fields user id, name, total and date in a form to save them in my database and works 100%.

but how can i save values in a input field which are default values such as value="1500" and value="<?php echo $_GET['total'] ?>" to my database?

HTML
<input  type="text" value="1500" name="total" >


HTML
<input  type="text" value="<?php echo $_GET['total'] ?>" name="total" >


every time i submit such input fields my database records 0. please help! and by the way i am still new to php html and javascript.

What I have tried:

function Add_total()
{

$user_id = $_POST['user_id'];
$name = $_POST['name'];
$total = $_POST['total'];
$date = date('Y-m-d h:i:s');

$sql=sprintf("INSERT INTO `users`(`user_id`, `name`, `total`, `status`, `date`) VALUES ('$user_id','$name','$total','0','$date')");

$rs=mysqli_query($this->connection_to_database,$sql) or die(mysqli_error());
return true;
return false;
}</pre>
Posted
Updated 26-Nov-17 16:30pm

1 solution

The answer lies in understanding the GET and POST of PHP Form Handling[^]
Another important issue is that you should not be injecting arguments directly into SQL statement as it is susceptible to SQL injection. Learn to use PHP Prepared Statements[^] instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900