I want to insert records from one table to another. Both tables are in the same database. The idea is this: a value is read into the $ temp1 variable, a record from another table must be written into another variable (this is the last name). In another table there are only 2 columns - number and surname. This error is written in the logs:
PHP Catchable fatal error: Object of class stdClass could not be converted to string in D:\\Server\\htdocs\\www\\add.php on line 9 add.php
<?php include("connect.php"); $link=Connection(); $temp1=$_POST['temp1']; $sql= "SELECT sname FROM names WHERE (UID='$temp1')"; $result = mysqli_query($link,$sql); $sname=mysqli_fetch_object($result); $query = "INSERT INTO `templog` (`temperature`,`sname`) VALUES ('".$temp1."','".$sname."')"; mysqli_query($link,$query); //var_dump(mysqli_error($link)); mysqli_close($link); ?>
insert into templog(...) select uid, sname from names where uid=?And use the bindable variables, and do not insert values directly into the query text. If there is any quotation mark to you now in sname, then your insertion will fly off with at least an error - Mike