简体   繁体   English

让PHP从提示框中获取价值

[英]let PHP get value from prompt box

I am really new to PHP and I basically want php to get the data from a prompt box. 我对PHP真的很陌生,我基本上希望php从提示框中获取数据。 Can someone help me with it? 有人可以帮我吗? Right now I just have the javascript code: 现在我只有javascript代码:

var name;
var person = prompt ("May I ask your name?");
if (person!=null && person!="") {
    name = person;
} else {
    name = "Anonymous";
}

The variable 'name' is what I am trying to get in PHP 变量“名称”是我想要在PHP中获得的

Thanks! 谢谢!

You need to post the name to the php page. 您需要将名称发布到php页面。 Javascript is run in the browser and PHP is run on the server. Javascript在浏览器中运行,PHP在服务器上运行。

A simple way would be to take the value set it as a value in a hidden form and call the submit event on the form. 一种简单的方法是将值设置为隐藏表单中的值,然后在表单上调用submit事件。 Since you said that you are new to php and javascript. 因为您说过您是php和javascript的新手。 Otherwise you would send the data via AJAX. 否则,您将通过AJAX发送数据。

In PHP .. 在PHP中..

<form method="post" name="formname">
    <input name="inputname" type="text" />
</form>

to get the var 得到变种

$name = mysql_real_escape_string($_POST['inputname']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM