Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 JimChuD

JimChuD
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 30 May 2006 - 08:21 AM

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

<?
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>
        ";
}
    
?>
    


#2 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 30 May 2006 - 10:01 AM

Hello,

Instead of using

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

why dont you check for submit button ...

if ($_POST['Submit']) {

hth
Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#3 JimChuD

JimChuD
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 30 May 2006 - 10:21 AM

[!--quoteo(post=378344:date=May 30 2006, 05:01 AM:name=samshel)--][div class=\'quotetop\']QUOTE(samshel @ May 30 2006, 05:01 AM) View Post[/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

#4 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 30 May 2006 - 10:57 AM

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())";

}
Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#5 JimChuD

JimChuD
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 30 May 2006 - 11:11 AM

i appreciate the assistance.
i will put it in and test it

Thanks :)

Regards
Jim

#6 JimChuD

JimChuD
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 30 May 2006 - 03:50 PM

after some testing i removed the single quotes around some of the fields that were number orientated and it seems to have resolved it.

i need to do some testing but i beleive it is now resolved.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users