Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP $_POST returning null value for unseen reason

Tags:

html

php

My issue is I have a PHP $_POST that returns a null or empty value, and I personally do not see any error with my code (but I know its there) and I can't really step away from it for a few hours since I am on a time schedule. So, I was hoping someone could help me out ;)

Here is what I have, basically:

<table border="0" align="center">
<tr>
    <td>
        <div id="lvl3">Project Name:</div>
    </td>
    <td>
        <input type="text" name="prjname" maxlength="250">
    </td>
</tr>
<tr>
    <td colspan="2" align="center">
        <input type="submit" value="Submit" name="prjsubmitname">
        <input type="button" value="Cancel" onclick="$('#popupoverlay').hide(); $('#prjpopupbox').hide(); $('#prjname').hide(); $('#prjdescription').hide(); $('#prjversion').hide(); $('#prjrelease').hide();">
    </td>
</tr>

This is my table for editing a project name- what is important here is the textbox input, I think.

Next I have my PHP:

//Did the user change the Project Name
if (isset($_POST['prjsubmitname']))
{
//Is the input empty
if (!trim($_POST['prjname']))
{
    //Input is empty
    echo('<script>senderror("Please enter a valid Project Name empty");</script>');
} else {

    //Input isnt empty, assign variables
    $url = geturlext();
    $prjname = mysql_real_escape_string(trim($_POST['prjname']));

    //Is input invalid
    if (strcasecmp($prjname, "main") == 0 | $prjname == "404")
    {
        //Input is invalid
        echo('<script>senderror("Please enter a valid Project Name invalid");</script>');
    } else {

        //Input is valid, connect to database
        dbconnect();

        $checkquery = mysql_query("SELECT * FROM projects WHERE name = '$prjname'") or die(mysql_error());
        $check = mysql_num_rows($checkquery);

        //Does Project Name already exist
        if ($check == 0)
        {
            //No it does not
            $updatequery = mysql_query("UPDATE projects SET name = '$prjname' WHERE name = '$url'") or die(mysql_error());

            echo("<script>location.href='index.php?page=" . $prjname . "'</script>");
        } else {
            //Yes it does
            echo('<script>senderror("That Project Name already exists");</script>');
        }
    }
}
}

This is where I get my issue; No matter what I enter in the textbox, I always get the error message for 'Input is empty'. I have printed the output of $_POST['prjname'] and it is indeed empty.

Now the weird part is, I have this exact same (at least I think) setup for changing the project description, and it works flawlessly. For the sake of comparison- i've included the same parts of the project description editor below.

The table:

<table border="0" align="center">
<tr>
    <td>
        <div id="lvl3">Project Description:</div>
    </td>
    <td>
        <textarea type="text" name="prjdescription" maxlength="750" style="width:300px; height:100px; resize:none;"></textarea>
    </td>
</tr>
<tr>
    <td colspan="2" align="center">
        <input type="submit" value="Submit" name="prjsubmitdescription">
        <input type="button" value="Cancel" onclick="$('#popupoverlay').hide(); $('#prjpopupbox').hide(); $('#prjname').hide(); $('#prjdescription').hide(); $('#prjversion').hide(); $('#prjrelease').hide();">
    </td>
</tr>

And the PHP:

//Did the user change the Project Description
if (isset($_POST['prjsubmitdescription'])) 
{
//Is the input empty
if (!trim($_POST['prjdescription']))
{
    //Input is empty
    echo('<script>senderror("Please enter a valid Project Description");</script>');
} else {

    //Input isnt empty, do stuff
    $url = geturlext();
    $prjdescription = mysql_real_escape_string(trim($_POST['prjdescription']));

    //Connect and change description
    dbconnect();

    $updatequery = mysql_query("UPDATE projects SET description = '$prjdescription' WHERE name = '$url'") or die(mysql_error());
    echo("<script>location.href='index.php?page=" . $url . "'</script>");
}
}

For clarification, both tables are in the same form tag, and the PHP is right next to eachother.

No errors on Firebug, matter of fact Firebug doesn't give me anything. Other than that, I'm sure it's some really small typo that I am overlooking.

like image 513
Arpy Clarkson Avatar asked Aug 11 '26 17:08

Arpy Clarkson


1 Answers

I have found a solution to this issue:

Renaming the variable '$prjname' in the Project Name editing PHP fixes the issue.

It would seem that having a variable ($prjname) with the same name as a $_POST (['prjname']) returns an empty or null string. No idea why.

Thanks to those who tried to help

EDIT: Actually, I get the error again if I only change the variable name ($prjname)- It only fixes when I change the $_POST name... Odd.

like image 67
Arpy Clarkson Avatar answered Aug 13 '26 08:08

Arpy Clarkson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!