如何在sql中重复存储相同的值?我正在使用php、ajax和jquery

t98cgbkg  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(378)

问题1:我有多行输入(动态生成),它将输入值存储在mysql数据库中。我有一个只获取一次值的输入字段,我希望这个值被重复地存储在表中。
问题2:如何使用用户输入作为第一个日期,将动态生成字段中的日期递增一天,并将递增的日期传递给我的数据库?
链接到代码
我的 insert.php file:-

<?php
//insert.php
$connect = mysqli_connect("localhost", "root", "", "crondiet");
if(isset($_POST["break_name"]))
{
 $date_entry = $_POST["date_entry"];
 $cid_code = $_POST["cid_code"];
 $break_name = $_POST["break_name"];
 $mid_meal = $_POST["mid_meal"];

 $lunch_name = $_POST["lunch_name"];

 $evening_snacks = $_POST["evening_snacks"];
 $dinner_name = $_POST["dinner_name"];

 print_r($date_entry);

 $query = '';
 for($count = 0; $count<count($break_name); $count++)
 {
  $date_entry_clean = mysqli_real_escape_string($connect, $date_entry[$count]);
  $cid_code_clean = mysqli_real_escape_string($connect, $cid_code[$count]);
  $break_name_clean = mysqli_real_escape_string($connect, $break_name[$count]);
  $mid_meal_clean = mysqli_real_escape_string($connect, $mid_meal[$count]);
  $lunch_name_clean = mysqli_real_escape_string($connect, $lunch_name[$count]);
  $evening_snacks_clean = mysqli_real_escape_string($connect, $evening_snacks[$count]);
  $dinner_name_clean = mysqli_real_escape_string($connect, $dinner_name[$count]);
  if($date_entry_clean != '' &&$cid_code_clean != '' && $break_name_clean != ''&& $mid_meal_clean != '' && $lunch_name_clean != ''&& $evening_snacks_clean != '' && $dinner_name_clean != '')
  {
   $query .= '
   INSERT INTO dietwithmoremeals(date_entry,cid_code,break_name,mid_meal,lunch_name,evening_snacks,dinner_name) 
   VALUES("'.$date_entry_clean.'","'.$cid_code_clean.'","'.$break_name_clean.'","'.$mid_meal_clean.'",  "'.$lunch_name_clean.'","'.$evening_snacks_clean.'", "'.$dinner_name_clean.'"); 
   ';
  }
 }

 if($query != '')
 {
  if(mysqli_multi_query($connect, $query))
  {
   echo 'Item Data Inserted';
  }
  else
  {
   echo 'Error';
  }
 }
 else
 {
  echo 'All Fields are Required';
 }
}
?>
uqjltbpv

uqjltbpv1#

在查询中,可以向插入的值添加一天:

$query .= '
   INSERT INTO dietwithmoremeals(date_entry,cid_code,break_name,mid_meal,lunch_name,evening_snacks,dinner_name) 
   VALUES("'.$date_entry_clean.'" + INTERVAL 1 DAY,"'.$cid_code_clean.'","'.$break_name_clean.'","'.$mid_meal_clean.'",  "'.$lunch_name_clean.'","'.$evening_snacks_clean.'", "'.$dinner_name_clean.'"); 
   ';

相关问题