PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, October 28, 2022

[FIXED] When I check for input, it always gives a negative response, why is that?

 October 28, 2022     html, is-empty, php, post, sql     No comments   

Issue

I made a system where I can input data, and show it in a table. I also made a check for the input (empty or not) but now my data doesnt get stored anymore. What can I do to fix this? Ive tried alot, a link to a different question with the answer would be good as well. Here is my code:

<?php
if(isset($_POST['vtprof']))
{
    if (empty($_POST["tun"])) {
        echo ('<br>Er zijn velden leeg');
    } elseif (empty($_POST["tpw"])) {
        echo ('<br>Er zijn velden leeg');
    } elseif (empty($_POST["tnm"])) {
        echo ('<br>Er zijn velden leeg');
    } elseif (empty($_POST["tbs"])) {
        echo ('<br>Er zijn velden leeg');
    } elseif (empty($_POST["tpl"])) {
        echo ('<br>Er zijn velden leeg');
    } elseif (empty($_POST["tps"])) {
        echo ('<br>Er zijn velden leeg');
    } elseif (empty($_POST["tgd"])) {
        echo ('<br>Er zijn velden leeg');
    } elseif (empty($_POST["tbd"])) {
        echo ('<br>Er zijn velden leeg');
    } else {
        $v_username = $_POST['tun'];
        $v_password = $_POST['tpw'];
        $v_name = $_POST['tnm'];
        $v_basis = $_POST['tbs'];
        $v_positie = $_POST['tps'];
        $v_plaatsing = $_POST['tpl'];
        $v_geboortedatum = $_POST['tgd'];
        $v_startdatum = $_POST['tsd'];
        $query = "INSERT INTO users 
                    VALUES (0, '$v_username', '$v_password', 
                            '$v_name', '$v_geboortedatum', '$v_startdatum', 
                            '$v_basis', '$v_positie', '$v_plaatsing')";
        $stm = $con->prepare($query);
        if ($stm->execute()) { 
            header("location:editprofiles.php");
        } else {
            echo ('Aanmaken mislukt');
        }

Solution

I think you have a Typo by checking your $_POST variables.

you check for

elseif (empty($_POST["tbd"]))

but want to get

$v_startdatum = $_POST['tsd'];

So the ckecking can't be true.

But please consider the advices in the comments.



Answered By - ivion
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing