Jump to content

mysql input query error creating 2 records (1 blank) from 1 input statement


Recommended Posts

Hey,
I have stumbled upon something i have never experienced before.

When creating an input function i found an issue of when the input was created it then put in the variables in to the new record but about 5 seconds later it created a blank entry below it containing no information at all.

I seperated the Input from the function in to its own script and found there was still a problem with it and it still occured.

i stripped down the input query and regardless of how many of the fields i tried to insert and regardless of them being variables or hard coded results it still created the duplicate record.

The last thing i did was to remove the session_start(); and this instantly resolved the issues. i rebuilt the query and it still worked fine obviously without the users name.

i have coded inputs which use session variables before and have never came across anything like this... any help would be greatly appreciated..

Regards
Jim

[code]<?
session_start();

echo "    <html>
    <head>
    <title>Job Documentation - New Job</title>
    <Link rel=\"stylesheet\" href=\"styles/style.css\">
    </head>
    <body>";

include('styles/style.php');
if ($_GET['status'] == 'insert_job_confirm') {
    
db_connect();
    
    $name = addslashes($_POST['name']);
    $priority = $_POST['priority'];
    $frequency = $_POST['frequency'];
    $frequency_note = addslashes($_POST['frequency_note']);
    $runs_in = $_POST['runs_in'];
    $description = addslashes($_POST['description']);
    $application = $_POST['application'];
    $instructions = addslashes($_POST['instructions']);
    #$username = $_SESSION['user'];
    
    $query_insert_job = "INSERT INTO job (name, priority, frequency, frequency_note, runs_in, description, application, instructions, date_created) VALUES ('{$name}', '{$priority}', '{$frequency}', '{$frequency_note}', '{$runs_in}', '{$description}', '{$application}', '{$instructions}', now())";
    $result_insert_job = mysql_query($query_insert_job);
    
    
} else {
    
    db_connect();
    
    /* PRIORITY SEARCH TO GET ALL PRIORITIES */
    $query_priority = "SELECT priority.id, priority.priority FROM priority ORDER BY priority.priority ASC";
    $result_priority = mysql_query($query_priority);
    /* FREQUENCY SEARCH FOR ALL FREQUENCIES */
    $query_frequency = "SELECT frequency.id, frequency.frequency FROM frequency ORDER BY frequency.frequency ASC";
    $result_frequency = mysql_query($query_frequency);
    /* RUNS_IN SEARCH FOR ALL RUNS_IN */
    $query_runs_in = "SELECT runs_in.id, runs_in.runs_in FROM runs_in ORDER BY runs_in.runs_in ASC";
    $result_runs_in = mysql_query($query_runs_in);
    /* APPLICATION SEARCH TO GET ALL APPLICATIONS */
    $query_application = "SELECT application.id, application.application FROM application ORDER BY application.application ASC";
    $result_application = mysql_query($query_application);
    
    echo '    <b>New Job Creation</b>';
    echo "    <form method=\"POST\" action=\"{$_SERVER['PHP_SELF']}?status=insert_job_confirm&jobid=load\">";
    echo "        <table>
                <tr>
                    <td>
                        <b>Name:</b>
                    </td>
                    <td>
                        <input name=\"name\" value=\"\">
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>Priority:</b>
                    </td>
                    <td>
                        <select name=\"priority\">";
                        while ($priority = mysql_fetch_array($result_priority)) {
                            echo "
                            <option value=\"{$priority['id']}\">{$priority['priority']}</option>";
                        }
    echo "
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>Frequency:</b>
                    </td>
                    <td>
                        <select name=\"frequency\">";
                        while ($frequency = mysql_fetch_array($result_frequency)) {
                            echo "
                            <option value=\"{$frequency['id']}\">{$frequency['frequency']}</option>";
                        }
    echo "
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>Frequency Note:</b>
                    </td>
                    <td>
                        <input name=\"frequency_note\" value=\"\">
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>Runs In:</b>
                    </td>
                    <td>
                        <select name=\"runs_in\">";
                        while ($runs_in = mysql_fetch_array($result_runs_in)) {
                            echo "
                            <option value=\"{$runs_in['id']}\">{$runs_in['runs_in']}</option>";
                        }
    echo "
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>Description:</b>
                    </td>
                    <td>
                        <input name=\"description\" value=\"\">
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>Application:</b>
                    </td>
                    <td>
                        <select name=\"application\">";
                        while ($application = mysql_fetch_array($result_application)) {
                            echo "
                            <option value=\"{$application['id']}\">{$application['application']}</option>";
                        }
    echo "
                    </td>
                </tr>
                <tr>
                    <td>
                        <br>
                        <b>Instructions:</b>
                    </td>
                </tr>
                <tr>
                    <td colspan=2>
                        <textarea name=\"instructions\" cols=\"50\" rows=\"7\"></textarea>
                    </td>
                </tr>
                <tr>
                    <td colspan=\"2\">
                        <input type=\"submit\" name=\"Submit\" value=\"Submit\">
                    </td>
                </tr>
            </table>
        </form>
        ";
}
    
?>
    [/code]
[!--quoteo(post=378344:date=May 30 2006, 05:01 AM:name=samshel)--][div class=\'quotetop\']QUOTE(samshel @ May 30 2006, 05:01 AM) [snapback]378344[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hello,

Instead of using

if ($_GET['status'] == 'insert_job_confirm') {

why dont you check for submit button ...

if ($_POST['Submit']) {

hth
[/quote]

Thanks for the advice,
at current the main reason i dont do that is because i have multiple parts to it not just purely variables on that modify script. theres another part that has to be seperate so if i did set it on post then it would impact that.

Regards
Jim
just a work around

before inserting check if the values are set...this will avoid blank record going in....

if(trim($name) && $priority......) {
$query_insert_job = "INSERT INTO job (name, priority, frequency, frequency_note, runs_in, description, application, instructions, date_created) VALUES ('{$name}', '{$priority}', '{$frequency}', '{$frequency_note}', '{$runs_in}', '{$description}', '{$application}', '{$instructions}', now())";

}
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.