An error has occurred.

Incorrect date value: 'Array' for column 'дата сдачи' at row 1 

Here is my code:

 <form action=' ' method='post' > <?php include '../db.php'; { /* выборка группы */ $qwer =("SELECT * FROM группа"); $sql = mysql_query($qwer) or die(mysql_error()); $row = mysql_fetch_array($sql); echo "<select name='group'>"; do { echo "<option value=" .$row['номер групп'].">".$row['номер групп']."</option>"; } while($row = mysql_fetch_array($sql)); echo "</select>"; } { /*выборка дисциплины*/ $qw =("SELECT * FROM дисциплины"); $sq = mysql_query($qw) or die(mysql_error()); $ro = mysql_fetch_array($sq); echo "<select name='дисциплина'>"."<option >"."Выборка"."</option>"; do { echo "<option value=" .$ro['дисциплина'].">".$ro['дисциплина']."</option>"; } while($ro = mysql_fetch_array($sq)); echo "</select>"; } ?> Следить за посещением лекций? да <input type="radio" name='vlec' value='On'/> нет <input type="radio" name='vlec' value='off' checked="checked"/><br> <input type='submit' name='redgr' > <?php if(isset($_POST['redgr']) && $_POST['vlec'] =='On') { $g=$_POST['group']; $d=$_POST['дисциплина']; echo $g,$d; echo "Сколько лекций <input type='text' name='collec' value='numberl'> <input type='submit' name='n' >"; echo ""; } if(isset($_POST['n'])) { $ks=$_POST['collec']; echo $ks.'<br>'; for($i=0; $i<$ks; $i++) { echo $i . " " . "введите дату занятия<input type='date' name='calendar[]'> Введите тип<input type='text' name='type[]'><br>"." введите норме<input type='text' name='name[]'><br>"; } echo $ks."<input type='submit' name='dd2' />"; } if( isset( $_POST['dd2'])) { $g=$_POST['group']; $d=$_POST['дисциплина']; $typew=$_POST['type']; $namew=$_POST['name']; $value=$_POST['calendar']; $rt=$_POST['calendar']; print_r ($rt) ." не работает че то<br>"; do { $adstudent = ("INSERT INTO `назначенные` (`номер группы`,`дисциплина`,`тип работы`,`имя работы`,`дата сдачи`) VALUES ('$g','$d','$typew','$namew','$value')"); $studentsql = mysql_query($adstudent) or die(mysql_error()); } while( print_r($rt )); $typew=$_POST['type']; $namew=$_POST['name']; echo $typew; } echo '<form>'; ?> 
  • firstly - do not use the mysql extension (use mysqli or PDO), and secondly - the Russian names of variables, tables, databases. - zb '
  • four
    and format the code - zb '
  • one
    Mysql tells you the same Russian language - you are trying to add an entry whose foreign key requires the existence of an entry in the 'jobs' table. Once this error occurs, the record with (discipline, type of work, name of work) is absent in the table of works. Either you need to add the corresponding entry to this table first, or redesign the database - for example, create foreign keys to other tables (from which you take values) - BOPOH
  • ncorrect date value: 'Array' for column 'put date' at row 1 is this because with the keys adds? how to do normally? - Stein_
  • @Stein_ some sort of nonsense suggested to you. If you fail with keys, mysql will produce a completely different result. And yes, zb is right, do not use mysql. Better yet - put php7 - strangeqargo

1 answer 1

you pass an array to a string. An array in php of your version turns into an Array line. the value "Array" is not something you can write to a date / timestamp field, etc.

your $ value comes from the html form from the name='calendar[]' field (I don’t know why you are so confusing, why couldn’t you name the $ calendar variable?)

php interprets such fields as arrays.

when you try to turn an array into a string, you get the string "array" - this is the standard behavior in php5.

that's the whole solution. can do var_dump($value); before the insert into the base, and see for yourself

check:

php -r '$a=array(); echo $a;' ,

get php warning:

PHP Notice: Array to string conversion in Command line code on line 1

conclusion:

Array

PS (comment to the comment) I do not see the connection

You are trying to add a record whose foreign key requires the existence of a record in the 'works' table.

and by message

“Incorrect date value”

Pps

if you included warnings, you yourself would notice and google the error in the code.

PPPS never again give a column in the database name with a space. It is unacceptable. field_name , not field name .