1

OK, here is the deal. I have 3 queries putting data in different tables. 2 of them are in included files. I've tried to put them into the main code, the result was the same. The first two queries inserts one row with the data and a blank row. The third works fine. Here is the code.

This in the main page:

<? $p=0;
    if ($select2)
    {
        $event=$select2;
    }
    else
    {
        require_once("insert_gal_name.php5");
    }

    if ($select)
    {
        $folder=$select;
    }
    else
    {
        require_once("insert_folder.php5");
        if (file_exists("Connections/".$folder))
        {
        }
        else
        {
             mkdir("Connections/$folder",0777);
        }
    }

    while($p<$number)
    {
        $p++;

        $dir = 'Connections/'.$folder.'/'; // Директорията в която ще се записват файловете
        copy($_FILES['file']['tmp_name'][$p],"$dir".$_FILES['file']['name'][$p]); //Копиране на файла
        echo "Файлът бе качен успешно!<br>"; // Извеждане на съобщение показващо, че файла е качен
        if($_FILES['file']['name'][$p])
        {
            $real_file_name = $dif_of_files.$_FILES['file']['name'][$p];
            $nom_file = str_replace(" ", "", $real_file_name); }

            $query = "INSERT INTO gallery (name, title, day, month, year) VALUES ('$nom_file', '$event', '$day', '$month', '$year')";
            $result = mysql_query($query) or die(mysql_error());
        }
        if (!$result)
        {
            echo "Error";
        }
        else
        {
            echo "All data was uploaded successfuly.";
        }
?>

And here are the includes in the order they are placed in the source

<?  $query = "INSERT INTO gallery_names (name) VALUES ('$event')";
    $result = mysql_query($query) or die(mysql_error());
    if (!$result)
    {
        echo "Error";
    }
    else
    {
        echo "The gallery was created successfuly.";
    }
?>

<? $query = "INSERT INTO folders (name) VALUES ('$folder')";
    $result = mysql_query($query) or die(mysql_error());
    if (!$result)
    {
        echo "Error";
    }
    else
    {
        echo "The folder was created successfuly.";
    }
?>
3
  • Exactly which query is being added more than once? Commented Dec 30, 2010 at 16:16
  • Instead of doing if($select), use something like if(isset($select)) or if($select === true). Its much more precise and easier to read/debug. Commented Dec 30, 2010 at 16:19
  • Citizen the last two shown in the code above. Commented Dec 30, 2010 at 16:22

2 Answers 2

2
<?
    if($event!='')
    {
        $query1 = "INSERT INTO gallery_names (name) VALUES ('$event')";
        $result1 = mysql_query($query1) or die(mysql_error());
        if (!$result1)
        {
            echo "Error";
        }
        else
        {
            echo "The gallery was created successfuly.";
        }
    }
?>
Sign up to request clarification or add additional context in comments.

8 Comments

The first query should be this: ` $query = "INSERT INTO gallery (name, title, day, month, year) VALUES ('".$nom_file."', '".$event."', '".$day."', '".$month."', '".$year."')";`
I don't know if this is the issue because my data is inserted properly exept the blank row. I've puted if(isset($select)) and now it does not include my pages and yet there now only the blank row is inserted
then use echo $nom_file; exit; and check that
in gallery_names and folders in this queries is the problem. Everything else works fine.
then echo $event ;exit; before the query and check that $event is not null
|
1

If $select2 is false then this code will do two inserts. If $event is empty one of these will be an empty row which sounds like the problem you're having.
What are the values of $select2 and $event? Have you tried debugging them?

4 Comments

$select2 are the existing galleries genereted in a list menu form the mysql table. The idea it to select an existing gllarey or to write down a new one and this is the $evenet var
Is $event only set when $select2 has a value? If so this is what will cause the empty row since insert_gal_name.php5 will have nothing to insert.
No. $event is a field in the form. If there is $select which is a previous event $event assume the value of the $select else the value in the field is inserted
The idea is if there is a gallery chosen the insert_gal_name.php5 not to be executed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.