Sir, I am new to php. I have following codes to connect with mysql

<?php
// Connection variables
$host="localhost";
$username="root";
$password="";
$db_name="asia"; 

// Connect to host
$con=mysqli_connect($host, $username, $password);

// Connect result
if(!$con){
die '<script type="text/javascript">alert("Error Connecting to HOST")'. mysqli_connect_error($con).'</script>'; 
}
else
{
echo "Connected" . mysqli_error($con);
}

// Database Selection
$sel =mysqli_select_db($con,"$db_name");

// Database Selection result
if(!$sel){
die '<script type="text/javascript">alert("Error Connecting to database")'. mysqli_connect_error($con).'</script>'; 
}
else
{
echo "Database Selected" . mysqli_error($con);
}
?>

On this line

die '<script type="text/javascript">alert("Error Connecting to HOST")'. mysqli_connect_error($con).'</script>'; 

it says:
**Parse error: syntax error, unexpected ''<script type="text/javascript' (T_CONSTANT_ENCAPSED_STRING) in C:\wamp\www\connect.php on line 13

**

Actually I want to show alert messagebox.

Please let me know what am doing wrong?

The die (aka exit) construct requires parenthesis when you send a status, so this is wrong:

die 'error here';

The correct version is:

die('error here');

Reference: http://php.net/manual/en/function.exit.php

Thanks sir it works

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.