xxreenaxx1 Posted April 10, 2011 Share Posted April 10, 2011 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. <?php session_start(); 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]'"; mysql_query($sql); } ?> My text file holds What is the sky.where.how.wen.one.0.0.1.0 What colour.where.what.how.more.0.0.1.0 Quote Link to comment https://forums.phpfreaks.com/topic/233260-data-is-not-inserted-but-nothing-wrong-with-php/ Share on other sites More sharing options...
litebearer Posted April 10, 2011 Share Posted April 10, 2011 SET is used when UPDATING - try here - http://www.tizag.com/mysqlTutorial/mysqlinsert.php Quote Link to comment https://forums.phpfreaks.com/topic/233260-data-is-not-inserted-but-nothing-wrong-with-php/#findComment-1199616 Share on other sites More sharing options...
xxreenaxx1 Posted April 10, 2011 Author Share Posted April 10, 2011 Thank you. Its working Quote Link to comment https://forums.phpfreaks.com/topic/233260-data-is-not-inserted-but-nothing-wrong-with-php/#findComment-1199618 Share on other sites More sharing options...
PFMaBiSmAd Posted April 10, 2011 Share Posted April 10, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233260-data-is-not-inserted-but-nothing-wrong-with-php/#findComment-1199619 Share on other sites More sharing options...
xxreenaxx1 Posted April 10, 2011 Author Share Posted April 10, 2011 My connection wasnt correct. That was my error Thanks Quote Link to comment https://forums.phpfreaks.com/topic/233260-data-is-not-inserted-but-nothing-wrong-with-php/#findComment-1199621 Share on other sites More sharing options...
PFMaBiSmAd Posted April 10, 2011 Share Posted April 10, 2011 Having some error checking and error reporting logic for the query have alerted you to a problem with the connection. Quote Link to comment https://forums.phpfreaks.com/topic/233260-data-is-not-inserted-but-nothing-wrong-with-php/#findComment-1199642 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.