在PHP代码中调用HTML代码

时间:2017-04-20 19:28:14

标签: javascript php html twitter-bootstrap

我有以下.PHP代码,其中包含HTML标记中的表。该代码用于事故报告,如果正确完成,则应返回用户输入。如果用户未填写字段,则代码将返回错误消息并允许用户再次尝试填写报告。

当前编写php代码的方式如果报表不符合要求,我可以返回错误消息,但是当报表填写正确时,我似乎无法返回用户输入列表。

代码:

http://myserver.com/auth.php?callback=?email=example@mail.com&password=password&login=

我试图将html代码部分分配给变量并在php标记中调用它,但我不清楚这是如何正确完成的。任何帮助,将不胜感激。

7 个答案:

答案 0 :(得分:1)

使用echo而不是print。 喜欢

function main(input) {
    //Enter your code here
    var num = parseInt(input, 10);//This line expects input to be a string so convert to an int as per problem
    var res=1;
    for(var i=num;i>1;i--) {
        res *= i; 
    }
    process.stdout.write(res);//This is how you write output.
} 

答案 1 :(得分:1)

您有条件检查

if(!empty($species1)&& is_string($species1)&& !empty($location)&& is_string($location) && isset($latitude) && is_numeric($latitude) && isset($longitude) && is_numeric($longitude))

这样,即使其中只有一个值为空/未正确设置,最终也会以其他方式结束。你应该做的是分别检查每个变量。如果它们中的任何一个没有输出或输出错误,则将它们设置为默认值并显示错误消息和表格。

简短的例子:

$everything_ok = true;
$species = 'Wrong value'; //default
if(isset($_POST['species'])) {
    $species1 = $_POST['species'];
} else {
    $everything_ok = false;
}

if(!$everything_ok) {
    //display error
}

//Display the table regardless of if everything is ok. $species will display 'Wrong value'

答案 2 :(得分:0)

在if条件下,您正在测试许多我在代码中无法看到的变量。

isset($latitude) && is_numeric($latitude) && isset($longitude) && is_numeric($longitude)

可能是$ long而不是$ longitude和$ lat而不是$ latitude?

答案 3 :(得分:0)

我猜你的if条件是错误的,你是 使用

!empty($location)&& is_string($location) && isset($latitude) && is_numeric($latitude) && isset($longitude) && is_numeric($longitude)

但是你的帖子

$lat = $_POST['lat']; 

  $long = $_POST['long'];

我猜你错过了一些变量声明,创建了一个错误的if else块

或者您在问题中错误地粘贴了脚本。否则,你做的方式似乎很好。

答案 4 :(得分:0)

您可以从文件中读取HTML部分并将其回显。例如:

<h2> pure html here </h2>
<?php
$myfile = fopen("header.html", "r") or die("Unable to open file!");
echo fread($myfile,filesize("header.html"));
fclose($myfile);
?>

答案 5 :(得分:0)

我猜它总是在else语句中,因为你的if条件失败了。检查你的条件

答案 6 :(得分:0)

我通过删除html标记并将代码转换为php语法来修改代码。现在一切都有效。感谢所有的输入。