Question on my practical

Database connection code

<?php 
	/*Connect Database*/
	$conn = mysqli_connect('localhost','root','') or die(mysqli_error());
	/*Select Database*/
	$select_db = mysqli_select_db($conn,'practise') or die(mysqli_error());
?>

<?php 
//Database connection
include("includes/dbconnet.php");

//Insert data into database
		$name=$_POST['name'];
		$email=$_POST['email'];
		$telephone=$_POST['telephone'];
		$subject=$_POST['subject'];
		$mesg=$_POST['mesg'];

//Sql Query to Insert Data in table
$sql="INSERT INTO pract SET name='$name',
							email='$email',
							telephone='$telephone',
							subject='$subject',
							mesg='$mesg'";
	/*Execute Query*/
	$result=mysqli_query($conn,$sql) or die (mysqli_error());
	if($result==true)
	{
	header('location:index.php?success');
	
	}
	else
	{
		echo "Error";
		}
?>

Error message received

Warning: mysqli_error() expects exactly 1 parameter,

Please kindly help to fixed the error

You know, if you took two seconds to RTFM you would know what the problem is. I will make it easy for you. Click this link and read the page. http://php.net/manual/en/mysqli.error.php

We don’t mind helping, but for gawd sake, try putting in a little effort on your own. This page will be helpful if you are going to be posting on forums. http://www.catb.org/esr/faqs/smart-questions.html

Aside from your actual problem, never ever put variables in your query. You need to use PDO with Prepared Statements. https://phpdelusions.net/pdo

Do not output internal system errors to the user. That info is only good to hackers.

Always kill the script after a header redirect or the script will keep running to the end.

Do not create variables for nothing. You already have the POST variables, just use them.

The INSERT INTO SET syntax is not an SQL standard.

Standard syntax:

INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...); 

Welcome to the forum. :grinning:

Sponsor our Newsletter | Privacy Policy | Terms of Service