How to connect database

I have made a html form page and then made a php file for database purposes , I checked it on local host and it worked on phpmyadmin successfully. But when I uploaded these files to my website.
My database is not updating.
I have made a same database on infinityfree and entered all the credentials correct but still not updating.
Please anyone help.

Please share the code you use to connected to the database. Make sure to hide your password.

4 Likes

View my php code

<?php
	$username = $_POST['username'];
	$email= $_POST['email'];
	$phone = $_POST['phone'];
	$message = $_POST['message'];
	

	// Database connection



	$conn = new mysqli('sql204.epizy.com','epiz_33086225','','epiz_33086225_InamsWeb');
	
	if($conn->connect_error){
		echo "$conn->connect_error";
		die("Connection Failed : ". $conn->connect_error);
	} else {
		$stmt = $conn->prepare("insert into Contact(username, email, phone, message) values(?, ?, ?, ?)");
		$stmt->bind_param("ssis", $username, $email, $phone, $message);
		$execval = $stmt->execute();
		echo $execval;
		echo "Registration successfully...";
		$stmt->close();
		$conn->close();
	
	}
?>

mysqli not connected
Try using pdo.

what is pdo

it may new recommended php mysql db connect

MySQLi and PDO are both perfectly fine ways to connect to your database. Only the old mysql_* functions are no longer supported, but you’re not using those, so you don’t need to use a different MySQL adapter.

What do you see on your website when you try to run this code? You say the database is not updating, but do all the PHP functions show successful results?

3 Likes

@Admin I have kept this for my contact.html page when I am entering the blanks in contact form and after clicking my submit button it is doing nothing but the contact.html page comes again. I have added code perfectly but not doing anything after uploading to my website.
Before my page was working on local host and I tested it successfully .

I think I may have found a possible cause: which contact.html are you referring to?

Because I see a contact.html and a contact.php in the main directory. But when I click the Contact button on your home page, I get redirected to https://inamsweb.ml/storage/emulated/0/MR/contact.html

The contact form on this page posts to contact.html, not the PHP script, with no method defined so it sends it as GET, not POST.

This corresponds with the behavior of “doing nothing but the contact.html page comes again”.

The contact.html in the main directory is different and seems to have the right attributes on the <form> element.

4 Likes

I have added GET method but still not working please view my code and edit as necessary

While we can help you correct your code, we are not going to do it for you.

Have you added the PHP file you are using to do something with the data from the form?

4 Likes

Now I have added all the code but I got this error while doing a test to my CONTACT FORM

I have cleared the data cookies of web page but still not working

The 500 HTTP error usually means that your PHP code has crashed.
Please enable PHP display_errors by following the article below:

5 Likes

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