0

Dear Sir,

HTML file has following codes

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Connection Checking</title>
</head>
<body>
<center>
<h1>Connection Checker</h1>
<fieldset style=width:300px;background-color:#E0FFFF>
<legend sytle=font-size:12;>Click Connect</legend>
<form name="form1" action="connect.php" method="post">
<table>
<tr><td></td><td align="center"><input type="submit" name="button1" value="Connect">
</td></tr>
</table>
</form>
</fieldset>
</center>
</body>
</html>

and Connect.php has folllowing codes

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

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

// Connect result
if(!$con){
die('Error Connecting to Database: ' . mysqli_error());
}
else
{
echo "Connected" . mysqli_error($con);
}
//close the connection
//mysql_close($con);
?>

Both files have no problems and works fine.

But I need following modifications:

When connection is established then this line trigs from connect.php

echo "Connected" . mysqli_error($con);

While standing on html page, I want to show a messagebox like this

[IMG]http://i43.tinypic.com/23vc5k5.jpg[/IMG]

Please help

3
Contributors
4
Replies
19
Views
3 Years
Discussion Span
Last Post by Bachu
0

Both files have no problems and works fine.

@tqmd1

I don't understand your question? Are you asking for an opinion? This is like a design question.

If you want a messagebox, then you need jQuery/javascript with php.

Does that make sense?

0

Sir I want to show messagebox on (html) same browser.

But echo shows on php page.

In other words

When I press Connect button then connection result must appear on same page not on other page.

0

When I press Connect button then connection result must appear on same page not on other page.

@tqmd1

then change your file name from html to php.

0

@tqmd1 You can do this using AJAX POST. (You don't change html to php).

Try the below code for index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Connection Checking</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
</head>
<body>
<center>
<h1>Connection Checker</h1>
<fieldset style=width:300px;background-color:#E0FFFF>
<legend sytle=font-size:12;>Click Connect</legend>

<form name="form1" id="form1"  method="post">
<table>
<tr><td></td><td align="center"><input type="submit" name="button1" value="Connect">
</td></tr>
</table>
</form>
</fieldset>
<h1 class="result"></h1>
</center>
<script type="text/javascript">
$(function () {
    $("#form1").submit(function(e){
        e.preventDefault();
        $.post('connect.php',$('#form1').serialize(), function(data) {
            $('.result').html(data);
            alert (data);
        });
    }); 
});
</script>
</body>
</html>

Edited by Bachu: text correction

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.