简体   繁体   English

sql插入/从php中选择

[英]sql insert into / select from php

would it be possible to combine insert into and select from?是否可以将插入和选择结合起来? what im trying to do is for the user to fill out an application the user can fill out as many applications as he or she wants each one is different.我试图做的是让用户填写一个应用程序,用户可以填写尽可能多的应用程序,因为他或她希望每个应用程序都不同。 at the end of the application the user has to put an email address they need to put the correct email address that they used to log in. if they do not type the correct email address a message will show saying invalid email address he or she will not be able to continue until they get it right.在应用程序结束时,用户必须输入他们需要输入的电子邮件地址,输入他们用于登录的正确电子邮件地址。如果他们没有输入正确的电子邮件地址,则会显示一条消息,说他或她将输入无效的电子邮件地址不能继续,直到他们做对了。 my problem is that the message shows invalid email address but the info is still being uploaded我的问题是该消息显示无效的电子邮件地址,但信息仍在上传

Insert page :插入页面:

<?php
     require_once("configur.php");
     $mysqli = new mysqli(localhost);

     $query='INSERT INTO profile_table SET email="'.$_POST[email].'", name="'.$_POST[name].'", age="'.$_POST[age].'", status="display"';

     if ($mysqli->query($query) === TRUE) 
        {
          echo "Record updated successfully";
        }
     else
        {
          echo "Error updating record: " . $conn->error;
        }

     $mysqli->close();
 ?>

Main Page :主页 :

<?php 
    require_once("configur.php");
    $mysqli = new mysqli(localhost );
    # check connection
    if ($mysqli->connect_errno) 
        {
            echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
            exit();
        }

    $email=$_POST['email']; 

    $sql = "SELECT * from register_login WHERE  email='$email'";
    $result = $mysqli->query($sql);
    if (!$result->num_rows == 1) 
        {
            echo "<p>Invalid email Address</p>";
        }
    else 
        {
            $_SESSION['email'] = $email;
            echo "<p>Logged in successfully</p>";
            // do stuffs
        }
?>  
require_once("configur.php");

$mysqli = new mysqli(localhost );
# check connection

if ($mysqli->connect_errno) 
    {
        echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
        exit();
    }

$email=$_POST['email']; 

$sql = "SELECT * from register_login WHERE  email='$email'";
$result = $mysqli->query($sql);

if ($result->num_rows == 0 ) // email id not present
    {
        echo "<p>Invalid email Address</p>";
    }
else 
    {
        $_SESSION['email'] = $email;

        echo "<p>Logged in successfully</p>";

        $query='INSERT INTO profile_table SET email="'.$_POST[email].'", name="'.$_POST[name].'", age="'.$_POST[age].'", status="display"';

       if ($mysqli->query($query) === TRUE) 
       {
               echo "Record updated successfully";
       }
       else
       {
             echo "Error updating record: " . $conn->error;
       }

        $mysqli->close();

    }

Your code is confusing me, I am not getting how these two scripts are related I mean is Main Page code calling or including Insert page你的代码让我很困惑,我不明白这两个脚本是如何相关的我的意思是主页代码调用或包括插入页面

Still I have one solution for you, you can combine two scripts in a single script like this.我仍然为您提供一个解决方案,您可以像这样将两个脚本组合在一个脚本中。

You can use page redirection to call insert file but as you are using same $_POST array you should combine both scripts .您可以使用页面重定向来调用插入文件,但是当您使用相同的 $_POST 数组时,您应该组合两个脚本

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

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