I am receiving an error that I cant seem to fix. Can I get some help please? The
ID: 3858345 • Letter: I
Question
I am receiving an error that I cant seem to fix. Can I get some help please? The error I am receiving is : Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C: mpphtdocshello.php:37 Stack trace: #0 {main} thrown in C: mpphtdocshello.php on line 37
Research indicated that I change code from mysql to msqli but that did not work either.
The code is :
<html>
<head>
<title>Book Store</title>
</head>
<body>
<h3> Book Store </h3>
<p> *****Welcome to use book store system***** <p>
<form action = "hello.php" method = "GET">
Find entries that are:<br/>
Author: <input type = "text" name = "author" />
Title : <input type = "text" name = "title" />
<p></p>
Year :
<p></p>
<select name = "select">
<option value=""/></option>
<option value=2005/>2005</option>
<option value=2007/>2007</option>
<option value=2009/>2009</option>
<option value=2010/>2010</option>
</select>
<p></p>
<input type = "submit" name="submit" value="search"/>
</form>
</body>
</html>
<?php
session_start();
if($_GET){
$author = $_GET['author'];
$title = $_GET['title'];
$select = $_GET['select'];
$connect = mysql_connect("localhost", "root", "") or die(mysql_error());
if($connect)
{
mysql_select_db("mysql", $connect);
$query = "SELECT * FROM bookstore WHERE author='" . $author . "' or Title='" . $title . "' ";
$query2 = "SELECT * FROM bookstore WHERE Year = '" . $select ."' ";
$result = mysql_query($query) or die(mysql_error());
$result2 = mysql_query($query2) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo $row['ISBN'] . "<br/>" . $row['Title'] . "<br/>" . $row['Author'] . "<br/>" . $row['Publisher'] . "<br/>" . $row['Year'] . "<br/>";
}
while($row2 = mysql_fetch_array($result2)){
echo $row2['ISBN'] . "<br/>" . $row2['Title'] . "<br/>" . $row2['Author'] . "<br/>" . $row2['Publisher'] . "<br/>" . $row2['Year'] . "<br/>";
}
} else {
die(mysql_error());
}
mysql_free_result($result);
mysql_close();
}
?>
Explanation / Answer
I will talk with respect to mysqli, since you have provided us that.
Part1
Part2
For example
$server = "localhost";
$user = "username";
$password = "password";
// now connecting to a database
$connect = mysqli_connect($serve, $user, $password);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.