Hello im having trouble connecting my php file to the database. The error states 'No connection could be made because the target machine activley refuses it.
Hello im having trouble connecting my php file to the
<html>
<body>
<?php
$link = mysqli_connect('localhost', 'cs4451', 'WxOYbuXB', 'cs332m1');
if(!$link){
die('Could not connect' .mysql_error());
}
echo 'Connected successfully<p>';
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "<b> Student Course History (Courses Taken and Grades) </b>";
echo "<hr>";
$CWID = $_POST["CWID"];
$get_student_info = "SELECT GRADE, COURSE_SECTION, CNUM FROM Enrollment, Section WHERE Enrollment.CWID = '$CWID' AND Enrollment.COURSE_SECTION = Section.SNUM";
$result = $conn->query($get_student_info);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if ($row["CNUM"] == "332") {
$class = "CPSC";
}
if ($row["CNUM"] == "240") {
$class = "CPSC";
}
if ($row["CNUM"] == "150B") {
$class = "MATH";
}
if ($row["CNUM"] == "338") {
$class = "MATH";
}
echo "<b> Course Name and Section: </b><br>" .$class. " " .$row["CNUM"]. "";
echo " Section " .$row["COURSE_SECTION"]. "<br>";
echo "<b> Grade: </b>" .$row["GRADE"]. "<br><br>";
}
} else {
echo "Invalid CWID. Please enter a valid one.";
}
echo "<br>";
$result->free_result();
$conn->close();
?>
<button type="button" onclick="history.back();">Go Back</button>
</body>
</html>
Step by step
Solved in 2 steps with 1 images