我的php代码没有插入数据库

问题描述:

所以,我在我的网站上工作。 10分钟后我准备好了。我尝试过这个。我的数据库中有4列。 id,times,left_overbruh。当我尝试它时,一切都被插入,但不是bruh,我不知道我做错了什么。这里是我的脚本:我的php代码没有插入数据库

$link = mysqli_connect("localhost", "root", "", "testang"); 
if($link === false){ 
    die("ERROR: Could not connect. " . mysqli_connect_error()); 
} 
$channelid = mysqli_real_escape_string($link, $_POST['channelid']); 
$subs = mysqli_real_escape_string($link, $_POST['subs']); 
$points = $subs*20; 
$lell = $userRow['userid']; 
$lel = $userRow['userpoints']; 
$pointsreal = $lel - $points; 
if ($points > $lel) { 
header("Refresh:0; url=NO.php"); 
} 
$bew = "INSERT INTO yt (times, left_over, bruh) 
VALUES ('0', '$subs', '$channelid')"; 
if ($link->query($bew) === TRUE) { 
    echo ""; 
} else { 
    echo "Error: " . $bew . "<br>" . $link->error; 
} 
mysqli_close($link); 

而且我没有收到任何消息,说明有什么问题。一切都在插入,但不是bruh。有人知道为什么吗?

这是我的形式:

<form action="insert.php" method="post"> 
    <p> 
     <label for="firstName">Youtube channel ID</label><br> 
     <input type="text" name="id" id="channelid"> 
    </p><br><br> 
    <p> 
     <label for="lastName">What is your email?</label><br> 
     <input type="text" name="subs" id="subs"> 
    </p><br><br> 
    <input type="submit" value="Submit"> 
</form> 
+0

很可能您的变量'$ channelid'为null。 –

+0

向我们显示您的HTML表单。另外,你应该考虑使用准备好的语句。 –

+0

但是我有这个:'
' –

现在,我从评论什么是错的知道,让我澄清一点什么是错在这里。在你的领域:

<input type="text" name="id" id="channelid"> 

你有ID:channelid和名称:id。为了能够获得$_POST['channelid'],您需要使用与您的$_POST索引中相同的字符串设置属性name。因此:

<input type="text" name="channelid" id="channelid"> 
+0

@Aaron [接受答案如何工作?](http://meta.stackexchange.com/questions/5234)...这就是我们如何在这里滚动。 – Drew