Hi everyone,

I wrote an INSERT for an insert form but for some reason it wont save the data tot he database. In phpMyadmin the rows are taken up with blank nothings. It seems to work but nothing is being stored. code as follows...

    $db_hostname = "localhost";
    $db_password = "";
    $db_username = "root";
    $db_name = "DataStore";
        $prodName = $_POST['prodName'];
        $writtenBy = $_POST['writtenBy'];
        $producedBy = $_POST['producedBy'];
        $prodRating = $_POST['prodRating'];
        $overview = $_POST['overview'];

        $_SESSION['prodName'] = $prodName;
	$_SESSION['writtenBy'] = $writtenBy;
	$_SESSION['producedBy'] = $producedBy;
	$_SESSION['overview'] = $overview;
        $anyErrors = false;
        if ($prodName == "" || $prodName= null){
            $noName  = "<span class=\"alert-red\"> <img src=\"images/icons/warning.png\" /> What is the name of this production?</span>";
            $anyErrors = true;
        if ($writtenBy == "" || $writtenBy = null){
            $noWritten  = "<span class=\"alert-red\"> <img src=\"images/icons/warning.png\" /> Who wrote this production?</span>";
            $anyErrors = true;
        if ($producedBy == "" || $producedBy = null){
            $noProduce  = "<span class=\"alert-red\"> <img src=\"images/icons/warning.png\" /> Who is the Producer?</span>";
            $anyErrors = true;
        if ($prodRating == 0 || $prodRating = null){
            $noRating  = "<span class=\"alert-red\"> <img src=\"images/icons/warning.png\" /> Please select a rating!</span>";
            $anyErrors = true;
        if ($overview == "" || $overview = null){
            $noOverview  = "<span class=\"alert-red\"> <img src=\"images/icons/warning.png\" /> Please enter an overview of the production!</span>";
            $anyErrors = true;
        if ($anyErrors == false){
            $conn = mysql_connect($db_hostname, $db_username, $db_password) or die(mysql_error());
            mysql_select_db($db_name, $conn) or die(mysql_error());
            $prodQuery = "INSERT INTO productions (production_name, written_by, produced_by, overview, parental_advice) VALUES('$prodName', '$writtenBy', '$producedBy', '$overview', '$prodRating')";
            if (!mysql_query($prodQuery,$conn)){
                $prodMess = "<span class=\"alert-green\">Submission Failed <img src=\"images/icons/action_delete.png\" /></span>";
                die('Error: ' . mysql_error());
                $prodMess = "<span class=\"alert-green\">Submission Successful <img src=\"images/icons/action_check.png\" /></span>";

html form code is...

<form name="addProd" method="POST" action="admin_insert.php">
                            <td><label class="right">New Production Name</label></td>
                            <td><input type="text" name="prodName" id="prodName" class="frm-txt3" value="<?php echo $_SESSION['prodName'];?>" > <?php echo $noName;?></td>
                            <td><label class="right">Written By</label></td>
                            <td><input type="text" name="writtenBy" id="writtenBy" class="frm-txt3" value="<?php echo $_SESSION['writtenBy'];?>"> <?php echo $noWritten;?></td>
                            <td><label class="right">Produced By</label></td>
                            <td><input type="text" name="producedBy" id="ProducedBy" class="frm-txt3" value="<?php echo $_SESSION['producedBy'];?>"> <?php echo $noProduce; ?></td>
                            <td><label class="right">Parental Supervision</label></td>
                                <select name="prodRating" id="prodRating">
                                    <option value="0">Select</option>
                                    <option value="1">No parental restrictions</option>
                                    <option value="2">Parental guidance necessary</option>
                                    <option value="3">For mature audiences</option>
                                <?php echo $noRating;?>
                            <td valign="top"><label class="right">Overview of Production</label></td>
                            <td valign="top"> <span valign="top"><?php echo $noOverview;?></span> <textarea name="overview" id="overview" rows="20" cols="50" style="border: 1px solid #666;" value="<?php echo $_SESSION['overview'];?> "></textarea> </td>
                            <td><input type="submit" name="saveProd" class="frm-sub2" value="SAVE  &raquo;" />     <?php echo $prodMess;?></td>

This should be very straight forward, but I just cant figure out what is wrong? Please help.

7 Years
Discussion Span
Last Post by toocoded

echo the $sql statment and see if the variables $prodName, $writtenBy, $producedBy and $prodRating are being populated. If the sql statment comes out as it should then copy the statement directly into PHPmyAdmin and check if it works correctly. However, from your statement saying that the db is being poulated with blanks, it looks like the variables are empty.

echo the variables separately after you pull the variables from the $_POST and check them. You'll know the problem if they are blank. If they are not blank then there is some place in the middle where they are becoming blank. Use the same echo technique to find out where.

All the best!


Your advice worked immensely. Apparently if you look close enough, in the condition where I check if the values are blank (validation) i have the $variable = null while i should have had &variable == null.

Thanks a lot for reminding me of the echo test sudeepjd. :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.