0

what is wrong in this i am new in php invalid argument implode in php i don't know what is wrong in this happening

 <?php
 /*Insert values into database*/
 if($_POST['is_submit'] == 'yes'){
  $dbhost = 'localhost';
 $dbuser = 'root';
 $dbpass = '';
$dbnam = 'canonent_db';
 $conn = mysqli_connect($dbhost, $dbuser, $dbpass,$dbnam);
 if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
 }

$count = count($_POST['c1']);
$query_values=array();
for($i=0; $i<$count; $i++){
$c11 = mysql_real_escape_string($_POST['c11'][$i]);
$c31 = mysql_real_escape_string($_POST['c31'][$i]);
$c41 = mysql_real_escape_string($_POST['c41'][$i]);
$c51 = mysql_real_escape_string($_POST['c51'][$i]);
$c1 = mysql_real_escape_string($_POST['c1'][$i]);
$c2 = mysql_real_escape_string($_POST['c2'][$i]);
$c3 = mysql_real_escape_string($_POST['c3'][$i]);
$c4 = mysql_real_escape_string($_POST['c4'][$i]);
$c5 = mysql_real_escape_string($_POST['c5'][$i]);
$fc_id1 = mysql_real_escape_string($_POST['c11'][$i]);
$fc_id2 = mysql_real_escape_string($_POST['c31'][$i]);
$fc_id_total=($fc_id1.$fc_id2);
$query_values= ('$c11','$c31','$c41','$c51','$c1','$c2','$c3','$c4','$c5','$fc_id_total') ";

  }
$values = implode("," , $query_values);

$sql = "INSERT INTO  fileno_data2 (`meter`, `palla`, `pcs`, `c/p`, `date`,`operation`, `e.name`, `qty`, `sing`, `fc_id`)  VALUES ('$values')";

mysqli_query( $conn, $sql );
if ($conn->query($sql) === TRUE) {
  echo "New record created successfully";
}  
 else {

echo "Error: "   . $conn->error;
}

$conn->close();


}
?>

i have used some ajax in main page need help from respectable seniors implode give warning

  • Look at your highlighting here. Notice anything? Also, arrays are made with `[]`, or `array()`, but not `()`. – aynber Nov 01 '16 at 16:44
  • 1
    **WARNING**: When using `mysqli` you should be using [parameterized queries](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and [`bind_param`](http://php.net/manual/en/mysqli-stmt.bind-param.php) to add user data to your query. **DO NOT** use manual escaping and string interpolation or concatenation to accomplish this because you will create severe [SQL injection bugs](http://bobby-tables.com/) if you ever forget to properly escape something. – tadman Nov 01 '16 at 16:46
  • 1
    **WARNING**: You should not be mixing `mysqli` and legacy functions like `mysql_real_escape_string`. – tadman Nov 01 '16 at 16:47
  • 1
    This code's a disaster. PHP syntax errors, SQL syntax errors, mixing MySQL APIs... ouch. – Marc B Nov 01 '16 at 16:49
  • another way to insert – user3602024 Nov 01 '16 at 17:03

0 Answers0