Current location: Hot Scripts Forums » Programming Languages » PHP » how do i call the php function inside the html tag


how do i call the php function inside the html tag

Reply
  #1 (permalink)  
Old 08-24-06, 07:39 AM
selvam.cit selvam.cit is offline
New Member
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
how do i call the php function inside the html tag

i have file in the name of view.php
it contains

PHP Code:

<?

$uname
=$_POST['uname1'];
$pass=$_POST['pass1'];
$conn=mysql_connect("localhost","root","") or die("Unable to Connect MySQL");
$dbconn=mysql_select_db("selvam",$conn) or die("Unable to Open Database");
$query="SELECT username FROM table2 WHERE username = '$uname' AND password = '$pass'";
$result=mysql_query($query);
$query_data=mysql_fetch_row($result);
session_start();
session_register("userid""userpassword");
$currentvalue=$query_data[0];
$session[userid]=$currentvalue;
if(!
$session[userid]) {
session_unregister("userid");
session_unregister("userpassword");
echo 
"<center><font face='Verdana' size='2' color=red>Wrong Login. Use your correct  Userid and Password and Try <br></center>";
echo 
"<center><input type='button' value='Retry' onClick='history.go(-1)'></center>";
exit;
}
else
{
echo 
"<center><font face='vardana' size='2' color='red'>Successfully Logged in <b> $session[userid] </b></font></center><br>";
print_r($_session);
?>
<form name="s" action="view.php">
<table align="center"  border="0" cellpadding="5" cellspacing="2">
<tr align="center">
<td><input type="button" value="View Profile" name="b1" onclick="<? f()?>"></td>
<td><input type="button" value="Edit Profile" name="b2"></td>
<td><input type="button" value="Logout" name="b3"></td>
</tr>
</table>
</form>
<?
}
?>
<?
function f()
{
echo 
"selvam";
}
?>
here my question is

if i click the viewprofile button it shows the error as

Error:'selvam' is undefined.

but i get a confusion if i call just php function then why it show error message.

give idea to me

thanks.

Last edited by nico_swd; 08-24-06 at 07:43 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-24-06, 09:39 AM
stormshadow's Avatar
stormshadow stormshadow is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 355
Thanks: 0
Thanked 0 Times in 0 Posts
Well...

I didnt go through your script... but in order to call a php function... it MUST be in php tags... so if you are doing html...

Code:
<html>
<title>Inside HTML</title>
<body>
<p>I need to call a function... Here it is...</p>
<p><? $blah = php_function(); echo"$blah"; ?>
</body>
</html>
Do ya get it? it has to be called within the <? and ?> tags...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 08-24-06, 09:44 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Hm, that is not the problem, I think. You cannot call PHP functions like that. The undefined error is Javascript. It attempts to execute a function onclick. "selvam" isn't a function. That's why you're getting the error. If you tell us what exactly you want to do we might can help a bit more.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 08-24-06, 10:08 AM
selvam.cit selvam.cit is offline
New Member
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
helllo nico_swd,

my question is how to call the PHP function inside the button.

for example
i write a function as
PHP Code:

<?

function f()
{
echo 
"selvam";
}
?>
can i call this function as

<input type="button" value="function" onclick="<? f(); ?>">

is it possible

this is my question nothing else

Last edited by nico_swd; 08-24-06 at 10:15 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 08-24-06, 10:14 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
PHP is on the server, and Javascript is on your computer. You cannot trigger PHP functions without submitting data to the server. You can do something like that:
PHP Code:



<form action="" method="post">
<input type="submit" name="submit" value="Submit" />
</form>

<?php

if (isset($_POST['submit']))
{
     
f();
}

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 08-24-06, 10:50 AM
selvam.cit selvam.cit is offline
New Member
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
thank u . thanks for your idea nico_swd
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 08-24-06, 09:25 PM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
Just to be on the safe side as well I recommend using <?php ?> tags and not short tags <? ?> because those are used by XML and other languages and can confilict.

Secondly if you just wanted to echo 'selvam' you could use javascript below.

PHP Code:

<form name="s" action="view.php">

<
table align="center"  border="0" cellpadding="5" cellspacing="2">
<
tr align="center">
<
td><input type="button" value="View Profile" name="b1" onclick="alert('selvam');"></td>
<
td><input type="button" value="Edit Profile" name="b2"></td>
<
td><input type="button" value="Logout" name="b3"></td>
</
tr>
</
table
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
html tutoral thefrtman HTML/XHTML/XML 5 04-27-09 11:25 AM
PHP Help - How do I call this function? INTEL PHP 6 04-02-06 02:59 PM
Classified Ads skipper23 Perl 3 11-22-05 03:22 AM
Please help insert html into php idforforums PHP 5 04-07-05 12:29 AM
edit php in Squirrelmail jrcortrightiii PHP 1 07-10-03 03:08 PM


All times are GMT -5. The time now is 09:25 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.