在php页面中回显输入字段值

时间:2017-02-25 06:20:31

标签: javascript php

您的建议中的新代码(仍然没有工作) 我试图通过post方法从注册表单到php页面获取值,然后在该页面中回显它,所以我知道它有效。如果是这样,我将尝试获取所有值并将它们插入到我的用户表中。我不介意sql注入风险,我现在必须清理输入,我只想让它工作。但它没有,你们看到我做错了什么?也可以改为获取数组中的所有值并发布它们,这样我就不必使用这么多变量。

 form.php (another page)
<?php include_once("connect.php"); ?>
<?php include_once("getTrycksaker.php"); ?>
<?php include_once("header.php"); ?>
<!-- BUILD COLUMN SYSTEM FOR CROSSDEVICE USABILITY -->
<div class="container">
<div class="row">
    <div class="col-md-1 col-sm-0 col-xs-0"></div>
    <div class="col-md-10 col-sm-12 col-xs-12">
        <h3 class="title">&nbsp;Registrering Företagskonto</h3><hr>
        <div class="alert alert-info" role="alert">Ange vänligen inloggningsuppgifter samt namn och telefonnummer till företagets kontaktperson.</div>
    </div>
    <div class="col-md-1 col-sm-0 col-xs-0"></div>
</div>
<div class="row">
    <div class="col-md-1 col-sm-0 col-xs-0"></div>
    <form class="form" method="post" id="compReg">
        <div class="col-md-5 col-sm-12 col-xs-12">
            <div class="input-group">
                <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                <input type="text" name="name" id="name" class="form-control" placeholder="Kontaktperson"></div><br>
            <div class="input-group">
                <span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></span>
                <input type="email" name="email" id="email" class="form-control" placeholder="E-postadress"></div><br>
            <div class="input-group">
                <span class="input-group-addon"><span class="glyphicon glyphicon-earphone"></span></span>
                <input type="text" class="form-control" placeholder="Telefon"></div><br>
        </div>
        <div class="col-md-5 col-sm-12 col-xs-12">
            <div class="input-group">
                <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
                <input type="password" name="password" id="password" class="form-control" placeholder="Lösenord"></div><br>
            <div class="input-group">
                <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
                <input type="password" name="cpassword" id="cpassword" class="form-control" placeholder="Upprepa Lösenordet"></div><br>
        </div>
        <div class="col-md-1 col-sm-0 col-xs-0"></div>
</div>
<div class="row">
    <div class="col-md-1 col-sm-0 col-xs-0"></div>
    <div class="col-md-10 col-sm-12 col-xs-12">
        <br><div class="alert alert-info" role="alert">Ange vänligen företagets namn, postadress samt organisationsnummer. Avvikande leveransadresser kan registreras vid order.</div>
    </div>
    <div class="col-md-1 col-sm-0 col-xs-0"></div>
</div>
<div class="row">
    <div class="col-md-1 col-sm-0 col-xs-0"></div>
    <div class="col-md-5 col-sm-12 col-xs-12">
        <div class="input-group">
            <span class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></span>
            <input type="text" class="form-control" placeholder="Företagsnamn"></div><br>
        <div class="input-group">
            <span class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></span>
            <input type="text" class="form-control" placeholder="Organisationsnummer"></div><br>
        <div class="input-group">
            <span class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></span>
            <input type="text" class="form-control" placeholder="Gatuadress"></div><br>
    </div>
    <div class="col-md-5 col-sm-12 col-xs-12">
        <div class="input-group">
            <span class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></span>
            <input type="text" class="form-control" placeholder="Postnummer"></div><br>
        <div class="input-group">
            <span class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></span>
            <input type="text" class="form-control" placeholder="Postort"></div><br>
        <div class="input-group">
            <span class="input-group-addon"><span class="glyphicon glyphicon-paperclip"></span></span>
            <input type="text" class="form-control" placeholder="Eventuell c/o adress"></div><br>
    </div>
    <div class="col-md-1 col-sm-0 col-xs-0"></div>
</div>
<div class="row">
    <div class="col-md-1 col-sm-0 col-xs-0"></div>
    <div class="col-md-10 col-sm-0 col-xs-0">
        <label class="btn btn-info btn-file">Skapa Konto &nbsp;&nbsp;&nbsp;<input id="submitBtn" onclick="rAlert('Go')" type="submit" style="display: none;"><span class="glyphicon glyphicon-ok-sign" ></span></label>
        <br><br><br>
    </div>
    </form>
    <div class="col-md-1 col-sm-0 col-xs-0"></div>
</div>
<?php include_once("footer.php"); ?>


process.php (another page)
<?php print_r($_POST);?>

3 个答案:

答案 0 :(得分:0)

您可以使用元素名称获取值。所有值都在$_POST Array.Just print_r($_POST)内。您将看到所有发布的值。

process.php;

extract($_POST);
echo $name;//prints name
echo $email;//prints email
  

extract()函数将变量从数组导入到本地符号表中。此函数使用数组键作为变量名称和值作为变量值。对于每个元素,它将在当前符号表中创建一个变量。

答案 1 :(得分:0)

您可以使用<?php print_r($_POST); ?>来确切地检查传递给php的内容。 这将显示从表单传递的所有变量及其值。

另外值得注意的是,表单只传递具有有效名称属性的输入。

答案 2 :(得分:0)

我认为,这个示例代码会对您有所帮助。运行我的代码并在代码中使用这个想法。

in form.php

<form class="form" method="post" action="process.php"> 

<input type="text" name="name[]" value="a"/>
<input type="text" name="name[]" value="b"/>
<input type="text" name="name[]" value="c"/>

<label>Skapa Konto &nbsp;&nbsp;&nbsp;<input  type="submit" ></label>

in process.php

<?php
$nvals = count($_REQUEST['name']);
 // do something with $_REQUEST['name'][$i] for example
 echo 'Hello ' . $_REQUEST['name'][1] . '!'; 
?>

它将打印出“你好b!&#39;

如果你想使用for循环获取所有值,请使用此代码。

<?php 
$nofval = count($_REQUEST['name']);
for ($i = 0; $i < $nofval; $i++) {
   echo 'Hello ' .$_REQUEST['name'][$i] . '!';
}  
?>