Page 1 of 1

i cant call a function

Posted: Sat Dec 25, 2010 3:25 am
by madu
<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:&nbsp<input type=text name=fname style="left:200px;top:10px; position:absolute;"><br><br>';
echo ' Enter The Last Name:&nbsp<input type=text name=lname style="left:200px; position:absolute;"><br><br>';
echo ' Enter The Mobile Number:&nbsp<input type=text name=mnum style="left:200px; position:absolute;"><br><br>';
echo ' Enter The Home Number:&nbsp<input type=text name=hnum style="left:200px;position:absolute;"><br><br>';
echo ' Enter The Email Id:&nbsp<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

Re: i cant call a function

Posted: Sat Dec 25, 2010 4:35 am
by Darhazer
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