Jump to content

Data is not inserted but nothing wrong with php


Recommended Posts

I have tried to run my code and it works. I am not getting any error message but when I checked my database nothing was added.



include '../Database/connection.php';

if ($_FILES["file"]["error"] > 0)
    echo "Error: " . $_FILES["file"]["error"] . "<br />";
  $filename = $_FILES["file"]["tmp_name"];

$fd = fopen ($filename, "r");
$data = fread ($fd,filesize ($filename));

fclose ($fd);
$delimiter = "\n";
$output = explode($delimiter, $data);

foreach($output as $var) {
$tmp = explode(".", $var);
$question = $tmp[0];
$choice1 = $tmp[1];
$choice2 = $tmp[2];
$choice3 = $tmp[3];
$choice4 = $tmp[4];
$answer1 = $tmp[5];
$answer2 = $tmp[6];
$answer3 = $tmp[7];
$answer4 = $tmp[8];

$sql = "INSERT INTO question SET Que_Question='$question', Que_Choice1='$choice1', Que_Choice2='$choice2', Que_Choice3='$choice3', 
Que_Choice4='$choice4', Que_Answer1='$answer1', Que_Answer2='$answer2', Que_Answer3='$answer3', Que_Answer4='$answer4', Tes_ID='$_SESSION[Tes_ID]'";




My text file holds

What is the sky.where.how.wen.one.

What colour.where.what.how.more.

Link to comment
Share on other sites

The SET syntax can be used for INSERT queries.


If using the full syntax worked, it is likely that there was a required column that wasn't being supplied a value or there was some other error in the posted query and using some error checking logic (which should always be done) for the query would have shown why it was not working.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.