Member Avatar for Borderline

I've used the code below previously with success, but I'm having problems this time around, and hoped someone could point me in the right direction. I complete the form, click submit, and receive the message confirming data has been added. However, when I look at the database, there's nothing there.

Any pointers on where I've goofed, please?

To confirm, I do have connection information in an include file, just haven't shown it here.

<div id="content">

        <?php
        if (!isset($_POST['submit'])) {
        ?>
        
        <form action="" method="post">

            <table border='0' cellpadding='2' width='60%'>

            <tr>
                <td>Date:</td>
                <td><input type='text' size='12' name='date' value='YYYY-MM-DD'></td>
            </tr>

            <tr>
                <td>Link:</td>
                <td><input type='text' size='17' name='link' value='YYYY-MM-DD.php'></td>
            </tr>
            
            <tr>
                <td>Stable Name:</td>
                <td><input type='text' size='30' name='by' value='Sir Dean'></td>
            </tr>


            <tr>
                <td>Race 1 Time:</td>
                <td><input type='text' size='5' name='time1' value='20:00'></td>            
            </tr>


            <tr>
                <td>Race 1 Tip:</td>
                <td><textarea name='tip1' rows='7' cols='35'></textarea></td>
            </tr>

            <tr>
                <td>Race 2 Time:</td>
                <td><input type='text' size='5' name='time2' value='20:05'></td>
            </tr>


            <tr>
                <td>Race 2 Tip:</td>
                <td><textarea name='tip2' rows='7' cols='35'></textarea></td>
            </tr>

            <tr>
                <td>Race 3 Time:</td>
                <td><input type='text' size='5' name='time3' value='20:10'></td>
            </tr>


            <tr>
                <td>Race 3 Tip:</td>
                <td><textarea name='tip3' rows='7' cols='35'></textarea></td>
            </tr>

            <tr>
                <td>Race 4 Time:</td>
                <td><input type='text' size='5' name='time4' value='20:15'></td>
            </tr>


            <tr>
                <td>Race 4 Tip:</td>
                <td><textarea name='tip4' rows='7' cols='35'></textarea></td>
            </tr>

            <tr>
                <td>Race 5 Time:</td>
                <td><input type='text' size='5' name='time5' value='20:20'></td>
            </tr>


            <tr>
                <td>Race 5 Tip:</td>
                <td><textarea name='tip5' rows='7' cols='35'></textarea></td>
            </tr>

            <tr>
                <td>Race 6 Time:</td>
                <td><input type='text' size='5' name='time6' value='20:25'></td>
            </tr>


            <tr>
                <td>Race 6 Tip:</td>
                <td><textarea name='tip6' rows='7' cols='35'></textarea></td>
            </tr>

            <tr>
                <td>Race 7 Time:</td>
                <td><input type='text' size='5' name='time7' value='20:30'></td>
            </tr>


            <tr>
                <td>Race 7 Tip:</td>
                <td><textarea name='tip7' rows='7' cols='35'></textarea></td>
            </tr>
            
            <tr>
                <td>Race 8 Time:</td>
                <td><input type='text' size='5' name='time8' value='20:35'></td>
            </tr>


            <tr>
                <td>Race 8 Tip:</td>
                <td><textarea name='tip8' rows='7' cols='35' value='20:35'></textarea></td>
            </tr>
            
            <tr>
                <td></td>
                <td><input type='submit' name='submit' value='Submit!'></textarea></td>
            </tr>
        </form>


        <?php
        } else {
            $date        =     $_POST['date'];
            $link        =     $_POST['link'];
            $by            =     $_POST['by'];
            $time1        =     $_POST['time1'];
            $tip1        =     $_POST['tip1'];        
            $time2        =     $_POST['time2'];
            $tip2        =     $_POST['tip2'];
            $time3        =     $_POST['time3'];
            $tip3        =     $_POST['tip3'];
            $time4        =     $_POST['time4'];
            $tip4        =     $_POST['tip4'];
            $time5        =     $_POST['time5'];
            $tip5        =     $_POST['tip5'];            
            $time6        =     $_POST['time6'];
            $tip6        =     $_POST['tip6'];        
            $time7        =     $_POST['time7'];
            $tip7        =     $_POST['tip7'];        
            $time8        =     $_POST['time8'];
            $tip8        =     $_POST['tip8'];            
            
        mysql_query("INSERT INTO `markyourcard` (date, link, by, time1, tip1, time2, tip2, time3, tip3, time4, tip4, time5, tip5, time6, tip6, time7, tip7, time8, tip8)
        VALUES ('$date', '$link', '$by','$time1','$tip1','$time2','$tip2','$time3','$tip3','$time4','$tip4','$time5','$tip5','$time6','$tip6','$time7','$tip7','$time8','$tip8')");

        echo 

        "Success! This overview has been added to the database!";
        }
        ?>

instead of simply executing mysql_query("..."); use mysql_query("...") or die( mysql_error() ); . This way you will get details about the error.

As for your ACTUAL problem, I am seeing field named "by", which is a keyword. To avoid this "beginner's mistake" (no offense), ALWAYS enclose the db name, table and field names in backticks:

mysql_query("INSERT INTO `markyourcard` (`date`, `link`, `by`, `time1`, `tip1`, `time2`, `tip2`, `time3`, `tip3`, `time4`, `tip4`, `time5`, `tip5`, `time6`, `tip6`, `time7`, `tip7`, `time8`, `tip8`)
        VALUES ('$date', '$link', '$by','$time1','$tip1','$time2','$tip2','$time3','$tip3','$time4','$tip4','$time5','$tip5','$time6','$tip6','$time7','$tip7','$time8','$tip8')") or die(mysql_error());

Lastly, to avoid "SQL injection" (if you don't know what that is, search it - there are tons of articles out there on the subject), instead of these:

$date        =     $_POST['date'];
            $link        =     $_POST['link'];
...

use these:

$date        =     mysql_real_escape_string($_POST['date']);
            $link        =     mysql_real_escape_string($_POST['link']);
...
Member Avatar for Borderline

Appreciate the feedback, thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.