2

So, i was working on my website. And after 10 minutes I was ready. I tried it. I have 4 column in my database. id, times, left_over and bruh. When I tried it Everything was getting inserted but not bruh, I don't know what I've did wrong. Here is my script:

$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);

And I don't get any messages that there's gone something wrong. Everything is getting inserted but bruh not. Does some one know why?

This is my form:

<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>
8
  • Most likely your variable $channelid is null. Commented Sep 24, 2016 at 11:12
  • Show us your HTML form. Also, you should consider using prepared statements. Commented Sep 24, 2016 at 11:14
  • But I have this: ` <label for="firstName">Youtube channel ID</label><br><input type="text" name="id" id="channelid">` Commented Sep 24, 2016 at 11:15
  • 1
    It should be name="channelid" Commented Sep 24, 2016 at 11:15
  • I've added my form Commented Sep 24, 2016 at 11:17

1 Answer 1

1

Now that I know from comments what's wrong, let me clarify a bit what's wrong in here. In your field:

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

You have ID: channelid and name: id. To be able to get $_POST['channelid'], you need to set attribute name with the same string as in your $_POST index. Therefore:

<input type="text" name="channelid" id="channelid">
Sign up to request clarification or add additional context in comments.

1 Comment

@Aaron How does accepting an answer work? ... that's how we roll here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.