This question already has an answer here:
I get the error
no database selected
I am using wamp. I am very new to php and sql. here is the php html. the inputs comes from a html file first when the submit button is pressed.
<?php
$link = mysqli_connect("localhost", "erthiph", "");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
$db_select = mysql_select_db( 'inewsfeed' ,$connection);
if (!$db_select) {
die("Database selection failed:: " . mysql_error());
}
}
$Qid = mysqli_real_escape_string($link, $_POST['Qid']);
$Mclass = mysqli_real_escape_string($link, $_POST['Mclass']);
$Sclass = mysqli_real_escape_string($link, $_POST['Sclass']);
$Question = mysqli_real_escape_string($link, $_POST['Question']);
$Answer = mysqli_real_escape_string($link, $_POST['Answer']);
$Doc = mysqli_real_escape_string($link, $_POST['Doc']);
$Time = mysqli_real_escape_string($link, $_POST['Time']);
$sql = "INSERT INTO feed (Qid, Mclass, Sclass, Question, Answer, Doc, Time) VALUES ('$Qid', '$Mclass', '$Sclass', '$Question', '$Answer', '$Doc', '$Time')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
?>
</div>
What @saty said is correct.You can try like this also,
mysqli_connect("localhost","username","password","dbname");
Because you are mixing mysql add mysqli
Instead of this
mysql_select_db( 'inewsfeed' ,$connection);
use
mysqli_select_db($link,"inewsfeed");