[Solved] Why is it saying no database selected?


Your final code should be identical to:

<?php
    $con = mysqli_connect("localhost", "root", "", "radian");
    if (!$con) {
        exit("Couldn't connect: " . mysqli_connect_error());
    }
    mysqli_set_charset($con, "utf8");

    $insert_data = "UPDATE enquiries SET ResponseDate="" . $current_date . "", Response="" . $txtResponse . "",Enquiry_No = '" . $_SESSION['ses_staff'] . "' WHERE Enquiry_No = '" . $txtStudentId . "'";

    $execute = mysqli_query($con, $insert_data) or die(mysqli_error($con));

    $output="<h4 style="margin-left:1em;
    width:15em;
    color:red;"> Response successful!. </h4>";

Changes made:

  • Remove all instances of mysql_* and replace with the correct mysqli_* function.
  • Remove the orphaned } else {.

Note: Officially mysql_* functions are deprecated. So no point using them. Use either mysqli_* or PDO.

solved Why is it saying no database selected?