Error 500 caused by connecting to the mysql database

Hi everyone … I am creating an internal search engine to search for articles, only going to connect my php file to the mysql database once I visit the page gives me error 500 the page does not work … I leave you the code and the link to the page.
this is the code: Nov 04 4:45 PM - Codeshare
link: https://hard-questions.com/try/ggg.php

Search Bar using PHP Search

https://infinityfree.net/support/http-error-500/

4 Likes

also in other all browsers… why? what i must do resolve?

I didn’t post that article for mistake, plz read it.

also:

$con mysql_connect("sql300.epizy.com","epiz_24872058","plz censor","");

should be:

$con = mysqli_connect("sql300.epizy.com","epiz_24872058","plz censor","database name must be entered");
2 Likes

The error that he show is Parse error : syntax error, unexpected ‘mysql_connect’ (T_STRING) in /home/vol6_5/epizy.com/epiz_24872058/htdocs/try/ggg.php on line 21
But i don’t understand what is error of syntax, (i think the lines 21 is righ)

updated my post.

Edit: you must use PDO connection instead of mysqli ones because your codes are PDO related.

2 Likes

sorry but where i can find the database name?

from Cpanel->Phpmyadmin

2 Likes

this? epiz_24872058_hardquestions

if exists yes.

just one thing off the topic, what does this mean? Fatal error: Uncaught Error: Call to undefined method mysqli_stmt :: setFetchMode () in /home/vol6_5/epizy.com/epiz_24872058/htdocs/try/ggg.php:28 Stack trace: # 0 {main} thrown in / home / vol6_5 / epizy.com / epiz_24872058 / htdocs / try / ggg.php on line 28

sorry if I’m bothering you too much but I’m new to this field :sweat_smile::disappointed_relieved:

np, it’s ok to ask and learn

It’s because you’re connecting with mysqli, but the rest of functions only work with pdo. I’ll fix the code:

<!DOCTYPE html>
<html>
<head>
	<title>Search Bar using PHP</title>
</head>
<body>

<form method="post">
<label>Search</label>
<input type="text" name="search">
<input type="submit" name="submit">
	
</form>

</body>
</html>

<?php

$con = new PDO("mysql:host=sql300.epizy.com;dbname=epiz_24872058_hardquestions",'epiz_24872058','your password');
//$con mysql_connect("sql300.epizy.com","epiz_24872058","...");


if (isset($_POST["submit"])) {
	$str = $_POST["search"];
	$sth = $con->prepare("SELECT * FROM `search` WHERE Name = '$str'");

	$sth->setFetchMode(PDO:: FETCH_OBJ);
	$sth -> execute();

	if($row = $sth->fetch())
	{
		?>
		<br><br><br>
		<table>
			<tr>
				<th>Name</th>
				<th>Description</th>
			</tr>
			<tr>
				<td><?php echo $row->Name; ?></td>
				<td><?php echo $row->Description;?></td>
			</tr>

		</table>
<?php 
	}
		
		
		else{
			echo "Name Does not exist";
		}


}

?>
4 Likes

Thanks so much, thanks, thanks thanks and thanks :wink:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.