mysqli - Unable to insert into Mysql db from PHP -
the following code generating integer value in variable $insertstatement, insert statement failing have tried long time couldn't figure out reason issue appreciated :)
<?php $con=mysqli_connect("localhost","root","","loadtest"); if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); } if( $_get["value"] != null || $_get["value"]!="" ) { $rand=uniqid(); $insertstatement=""; date("m-d-y"); for($i=0;$i<$_get["value"];$i++){ $insertstatement +="insert test values('"+$date+"','"+$rand+"','column1','column2','column3','column4','column5','column6','column7','column8','column9','column10');"; } echo $insertstatement; mysqli_query($con,$insertstatement)or die("cannot insert"); mysqli_close($con); echo "<p style=\"color:green\">inserted</p>"; } else{ echo "couldn't insert"; } ?>
change this:
$insertstatement +="insert test values('"+$date+"','"+$rand+"','column1','column2','column3','column4','column5','column6','column7','column8','column9','column10');";
to this:
$insertstatement .="insert test values('" . $date . "','" . $rand . "','column1','column2','column3','column4','column5','column6','column7','column8','column9','column10');";
to concatenate strings in php use .
.
echo "a" + "b"; // outputs 0 echo "a" . "b"; // outputs "ab"
read: http://php.net/manual/en/language.operators.string.php
Comments
Post a Comment