<?php
$con = mysql_connect("localhost","root","12345");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  echo "connection made";
    if(isset($_POST['nw_update'])){
        echo("You clicked nw_update!");
    }
    else {
    echo" dhur";
    }
?>

 <html>
 <body>
    <form action="<?php echo $_SERVER(PHP_SELF); ?>" method="POST"    >
        <input type="button" id="nw_update" value="NW_Update"/>
    </form>
</body>
</html>

In the above code when the button is clicked i want the echo("You clicked nw_update!"); to be executed. PLease could you help out.

Are you getting an error?

Have you tried it without the mysql connection?

the else part is automatically printed the connection part is ok.. i have already tested that

Why not execute SQL on $_POST instead?

if ($_POST)
{
    //Connection to DB
    //Execute Query
}

@Javvy good idea! Or you could have an hidden attribute inside your form:

<input type="hidden" name="submitted" value="TRUE">

Making sure it's after your submit button and then inside PHP:

<?php
  if(isset($_POST['submitted']))
  {
      // SQL
      // SQL
  }

Your button should be a submit instead as what you have won't submit your form or post your data.
<input type="submit" id="nw_update" value="NW_Update"/>

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.