<html>
<body>
<?php
$con=mysql_connect("localhost","root");
if(!$con)
{
echo "problem in connection".mysql_errror();
}
mysql_select_db("my_db",$con);
function inst($fn,$ln,$mn,$hn,$em)
{
mysql_query("insert into mobi_dat values('$fn','$ln','$mn','$hn','$em')");
echo '<script language="javascript">';
echo 'alert("Data addded successfully")';
echo '</script>';
}
echo '<form name=insef method=post action="">';
echo ' Enter the First Name: <input type=text name=fname style="left:200px;top:10px; position:absolute;"><br><br>';
echo ' Enter The Last Name: <input type=text name=lname style="left:200px; position:absolute;"><br><br>';
echo ' Enter The Mobile Number: <input type=text name=mnum style="left:200px; position:absolute;"><br><br>';
echo ' Enter The Home Number: <input type=text name=hnum style="left:200px;position:absolute;"><br><br>';
echo ' Enter The Email Id: <input type=text name=email style="left:200px; position:absolute;"><br><br>';
echo "<button style='left:200px; position:absolute;' onClick='inst(fname,lname,mnum,hnum,email)'>Insert</button>";
echo ' </form>';
?>
</body>
</html>
in above program i got five text field from textbox,,, i want to insert those values to database without sending data to other php file such like using post and get,,, no error in this program but values not inserted,,,,pls help me
i cant call a function
Moderator: General Moderators
Re: i cant call a function
You are mixing server-side (PHP) with client-side (JavaScript)
You cannot call PHP function with onclick handler, you have to call JavaScript function, the JS function can perform an AJAX request to the PHP
You cannot call PHP function with onclick handler, you have to call JavaScript function, the JS function can perform an AJAX request to the PHP