Home php教程 PHP开发 How to share values ​​between PHP HTML JavaScript MySQL codes

How to share values ​​between PHP HTML JavaScript MySQL codes

Nov 25, 2016 am 09:35 AM

1.PHP

a.PHP -> HTML & JavaScript

html code

<input type="" readonly="readonly" style=&#39;background-color:#DCDCDC&#39; value=<?php echo $perinfo[ID];?> />
Copy after login


JavaScript code
Copy code The code is as follows:

<script type="text/javascript"> 
var ability=<?php echo JSON($array);?>; 
</script>
Copy after login

b.PHP <-> MySQL

php In the code
The code is as follows:

<?php 
$dbcnx = @mysql_connect ( "localhost", "root", "1234" ); 
if (! $dbcnx) { 
echo ("Unable to connect to the " . "database server at this time."); 
exit (); 
} 
if (! @mysql_select_db ( "pms" )) { 
echo ("Unable to locate the joke " . "database at this time."); 
exit (); 
} 
mysql_query ( "SET NAMES &#39;GB2312&#39;" ); 
$q=mysql_query("select * from ability where ALV = 1"); 
while($row=mysql_fetch_array($q)){ 
$array1[] = $row[AName]; 
} 
?>
Copy after login

2.HTML

a. HTML -> PHP (POST method)

In the html code
Copy the code The code is as follows:

<form id="form" name="form" method="POST" action="do.php"> 
<input type="hidden" id="count" name="count" value="1"/> 
<input type="submit" name="Submit" value="Search"/> 
</form>
Copy after login
Copy after login

do.php In the file code
Copy the code The code is as follows:

<?php 
echo $_POST[&#39;count&#39;]; 
?>
Copy after login
Copy after login

b. HTML -> JavaScript


JavaScript code (available and can be changed)
Copy code The code is as follows:

<script type="text/javascript"> 
var te = document.getElementById("count"); 
te.value = 1; 
</script>
Copy after login

3.JavaScript

a. JavaScript -> HTML ( Common law, not verified)

The
code in the JavaScript code is as follows:

<script type="text/javascript"> 
function f(){ 
var id = "2"; 
var a = document.getElementById("a"); 
a.href.replace("(n)", id); 
} 
</script>
Copy after login


html code
The code is as follows:

<a id="a" href="http://www.php1.cn/"> 
  b. JavaScript -> PHP
Copy after login

 Transfer through html

1. The JavaScript code is given to html first
The code is as follows:

<script type="text/javascript"> 
var i = 1; 
var te = document.getElementById("count"); 
te.value = i; 
</script>
Copy after login

2.html code is sent to php
The code is as follows:

<form id="form" name="form" method="POST" action="do.php"> 
<input type="hidden" id="count" name="count" value="1"/> 
<input type="submit" name="Submit" value="Search"/> 
</form>
Copy after login
Copy after login

 3.do.php receives
The code is as follows:

<?php 
echo $_POST[&#39;count&#39;]; 
?>
Copy after login
Copy after login


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)