在db中插入steam用户信息

时间:2017-11-11 15:15:57

标签: php

我试图插入蒸汽,蒸汽真名。当用户登录我的网站时,将蒸汽名称输入我的数据库

mycode:

<?php


if (isset($_GET['login'])){

$steamids= $steamprofile['steam_steamid'];
$name = $steamprofile['personaname'];
$real = $steamprofile['realname'];
$ESCAPING_real= mysqli_real_escape_string($connection,$real);
$ESCAPING_name= mysqli_real_escape_string($connection,$name);
$ESCAPING_steamids= mysqli_real_escape_string($connection,$steamids);

  $query = "INSERT INTO users(steamnid,steamname, steamreal,user_logindate) ";

  $query .= "VALUES('{$steamids}','{$name}', '{$real}', now())";


  $insert_query = mysqli_query($connection,$query);

  if(!$insert_query){

  die("failed".mysqli_error($connection));




}
}


 ?>



$button = "<a href='?login'><img src='http".(isset($_SERVER['HTTPS']) ? "s" : "")."://steamcommunity-a.akamaihd.net/public/images/signinthroughsteam/sits_".$button[$buttonstyle].".png'></a>";

当用户登录时,我没有在db中获得任何内容。

我尝试使用会话存储用户信息,但它可以正常复制值

代码有点凌乱因为我还在学习

任何想法?

2 个答案:

答案 0 :(得分:1)

我没有看到你的HTML表格,但我添加了,我认为它的工作检查了这个

<?php 

if (isset($_GET['login'])){

$steamids= $_GET['steam_steamid'];
$name = $_GET['personaname'];
$real = $_GET['realname'];
$ESCAPING_real= mysqli_real_escape_string($connection,$real);
$ESCAPING_name= mysqli_real_escape_string($connection,$name);
$ESCAPING_steamids= mysqli_real_escape_string($connection,$steamids);

  $query = "INSERT INTO users(steamnid,steamname, steamreal,user_logindate) ";

  $query .= "VALUES('{$steamids}','{$name}', '{$real}', now())";


  $insert_query = mysqli_query($connection,$query);

  if(!$insert_query){

  die("failed".mysqli_error($connection));




}

}


 ?>


<form action="" method="GET">
<div class="form-group">
    <label for="steam_steamid">Steam ID : </label>
    <input name="steam_steamid" type="text">
</div><br>
    <div class="form-group">
    <label for="steam_steamid">Personal Name: </label>
    <input name="personaname" type="text">
    </div><br>
    <div class="form-group">
    <label for="steam_steamid">Real Name: </label>
    <input name="realname" type="text">
    </div><br>
<button type="submit"><img src='https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded'></button>

</form>

您可以在图片标记中添加src,只需将其复制并粘贴到图片标记

中即可

答案 1 :(得分:1)

<?php 
$db = array("DB_HOST"=>"localhost","DB_USER"=>"root","DB_PASS"=>"mysql","DB_NAME"=>"databasename",);
foreach ($db as $key => $value)
{
    define($key , $value);
}
$connection = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
if (!$connection)
{
    die ('<h1>connecting failed</h1>');

}

if (isset($_GET['login'])){

$steamids= $_GET['steam_steamid'];
$name = $_GET['personaname'];
$real = $_GET['realname'];
$ESCAPING_real= mysqli_real_escape_string($connection,$real);
$ESCAPING_name= mysqli_real_escape_string($connection,$name);
$ESCAPING_steamids= mysqli_real_escape_string($connection,$steamids);
$query = "INSERT INTO users(steamnid,steamname, steamreal,user_logindate) ";

  $query .= "VALUES('{$steamids}','{$name}', '{$real}', now())";

$insert_query = mysqli_query($connection , $query);
    if ($insert_query) {
        echo "User added";
    }else{
        die("we have error " . mysqli_error($connection));
    }
}


 ?>


<form action="" method="GET">
<div class="form-group">
    <label for="steam_steamid">Steam ID : </label>
    <input name="steam_steamid" type="text">
</div><br>
    <div class="form-group">
    <label for="steam_steamid">Personal Name: </label>
    <input name="personaname" type="text">
    </div><br>
    <div class="form-group">
    <label for="steam_steamid">Real Name: </label>
    <input name="realname" type="text">
    </div><br>

<button type="submit" name="login"><img src='https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded'></button>

</form>

检查一下,我们已经创建了数据库并检查了我的表用户所拥有的代码 steamid(varchar 255) steamname(varchar 255) steamreal(varchar 255) user_logindate(日期)