i cant call a function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
madu
Forum Commoner
Posts: 32
Joined: Sat Dec 25, 2010 3:19 am
Location: india

i cant call a function

Post 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
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: i cant call a function

Post 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
Post Reply