if (isset($_POST['submit']))
{
$f="$";
$d="";
$que="";
//$new_var="";
$var_n="";
echo "hi";
$email= $_POST['email'];
$en_no= $_POST['en_no'];
$name= $_POST['name'];
$q1 = $_POST['q1'];
$q2 = $_POST['q2'];
$q3 = $_POST['q3'];
$q4 = $_POST['q4'];
$q5 = $_POST['q5'];
$q6 = $_POST['q6'];
$q7 = $_POST['q7'];
$query = "SELECT * FROM que";
// for getting no. of ?
$result = $conn->query($query);
$rowcount = 0;
while($row = $result->fetch_array(MYSQLI_ASSOC))
{
$rowcount = $rowcount + 1;
}
echo $rowcount;
$a=array('?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,','?,');
for($y=1;$y<=$rowcount;$y++)
{
$d .= $a[$y];
}
$d1 = rtrim($d, ",");
//echo $d1;
//for creating variables
for($z=1; $z<=$rowcount;$z++)
{
$new_data["q".$z] = $f."_POST['q".$z."']";
}
$type_add ='"';
extract($new_data);
$type = "iss";
$int_type = "i";
for($z=1; $z<=$rowcount;$z++)
{
$var_n .= ${'q'.$z}.",";
$type .= $int_type;
}
$new_var = rtrim($var_n, ",");
//$new_var = ltrim($var_n, "");
$new_type = $type_add.$type.$type_add;
//echo $var_n;
//echo $type;
//adding question colunm name
for($y=1;$y<=$rowcount;$y++)
{
$que .= 'Q'.$y.',';
}
$new_que = rtrim($que,',');
$stm="INSERT INTO `9akw6ofyzo_a`(en_no,name,email,q1,q2,q3,q4,q5,q6,q7) VALUES($en_no,'$name','$email',$q1,$q2,$q3,$q4,$q5,$q6,$q7)";
//$stm->bind_param($type,$en_no,$name,$email,$new_var);
//$stm->execute();
if(mysqli_query($conn, $stm)){
echo "<h3>data stored in a database successfully."
. " Please browse your localhost php my admin"
. " to view the updated data</h3>";
}
else{
echo "ERROR: Hush! Sorry $stm. "
. mysqli_error($conn);
}
}
I got this kind of error
**
hi7ERROR: Hush! Sorry INSERT INTO 9akw6ofyzo_a
(en_no,name,email,Q1,Q2,Q3,Q4,Q5,Q6,Q7) VALUES(123456,'Javal Patel','javalpatel@gnu.ac.in',$_POST['q1'],$_POST['q2'],$_POST['q3'],$_POST['q4'],$_POST['q5'],$_POST['q6'],$_POST['q7']). You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '['q1'],$_POST['q2'],$_POST['q3'],$_POST['q4'],$_POST['q5'],$_POST['q6'],$_POS...' at line 1
**
Read more here: https://stackoverflow.com/questions/66321961/i-got-some-syntax-error-in-sql-here-i-use-php-file-to-import-data
Content Attribution
This content was originally published by Javal at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.