/    Sign up×
Community /Pin to ProfileBookmark

PHP in Javascript…

Hello,

I tried embedding php in javascript but am not able to do so. I want to access the database using php but am not able to implement even a very simple echo statement. On clicking a submit button the javascript function with the embedded php is called. Enclosing below the code.

[CODE]function dblookup()
{
<?php
echo “Get values from the database”;
?>
}
<HTML>
<BODY>
<FORM>

<INPUT type=”button” name=”PowerSubmit” value=”Submit” style=”position:absolute;left:600px;top:260px;z-index:76″ onClick=”dblookup()”>

</FORM>
</BODY>

</HTML>[/CODE]

Please could you help me out with this simple query.

Thanks in advance

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@salmanshafiqOct 04.2007 — This Function Returns the field form database and store it in to a single varible and then alert that value and check it out and tell me in case of any problem
[code=php]
<?php
define("SERVERNAME","localhost");
define("USERNAME","root");
define("PASSWORS","");
define("DBName","chat");
$con=mysql_connect(SERVERNAME,USERNAME,PASSWORS) or die("Server not Connected");
mysql_select_db(DBName,$con) or die("Database not Selected");

?>
<script language="javascript" type="text/javascript">
function dblookup()
{
var variable="<?
$query="SELECT * FROM chat";
$result=mysql_query($query);
$row=mysql_fetch_object($result);
echo $row->text;
?>";
alert (variable);

}
</script>
<HTML>
<BODY>
<FORM>

<INPUT type="button" name="PowerSubmit" value="Submit" style="position:absolute;left:600px;top:260px;z-index:76" onClick="dblookup()">

</FORM>
</BODY>

</HTML>
[/code]
×

Success!

Help @ruchi_bhindwale spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...