php insert a form data into 2 tables

Solutions on MaxInterview for php insert a form data into 2 tables by the best coders in the world

showing results for - "php insert a form data into 2 tables"
Eleonora
27 Jan 2020
1
2<strong>Fill up the form/strong><br /><br>                
3
4    <form enctype="multipart/form-data" action="upfileone.php" method="POST">
5        Date: <?php echo date("d-M-Y") ?>
6
7            <p>Title:
8                <input type="text" name="title" value="<?php echo $sel_filepage['file_title']; ?>" id="file_title" />
9            </p>
10
11            <p>Descriptionbr>
12                <textarea name="description" rows="4" cols="24">
13                <?php echo $sel_filepage['content']; ?></textarea>
14            </p>
15
16        Category:
17        <select name="select_cat">
18        <?php $cat_set = get_all_categs();
19            while($category = mysql_fetch_array($cat_set)){
20                $catname = $category['cat_name'];
21                echo '<option value="'.$catname.'">'.$catname.'</option>';
22            }
23        ?>
24        </select>
25        <br><br>
26        <label for="file">Choose File to Upload/label>
27        <input type="file" name="upfile" id="upfile" > <br /><br />
28        <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
29        <input type="hidden" name="filepage" value="<?php echo $_GET['filepage']?>">
30        <input type="submit" name="upload" value="Add" class="pure-button pure-button-success">
31        <a href="content.php?filepage=<?php echo $sel_filepage['id']; ?>" class="pure-button">Cancel</a>
32    </form> <!-- END FORM -->
33Action FILE:
34
35<?php
36require_once("includes/functions.php");
37
38// directory to be saved
39$target = "server/php/files/";
40$target = $target . basename($_FILES['upfile']['name']);
41
42// gets info from FORM
43$currentDate = date("Y-m-d");
44$file_title = $_POST['title'];
45$content = $_POST['description'];
46$category = $_POST['select_cat'];
47$upfile = ($_FILES['upfile']['name']);
48
49// connects to db
50$con = mysqli_connect("localhost", "root", "password", "database");
51if(mysqli_connect_errno())
52{
53    echo "error connection" . mysqli_connect_error();
54}
55
56// insert to database
57$sql = "INSERT INTO filepages (category_id,file_title,content)
58VALUES ('$category','$file_title','$content')";
59
60/*$sql2 = "BEGIN
61            INSERT INTO filepages (category_id, file_title, content)
62                VALUES ('$category','$file_title','$content')
63            INSERT INTO fileserv (file_date)
64                VALUES ($currentDate)
65            COMMIT";*/
66
67if(!mysqli_query($con, $sql))
68{
69    die('Error ' . mysqli_error());
70}
71echo "1 File Added <br>";
72
73    if (file_exists("server/php/files/" . $_FILES["upfile"]["name"]))
74      {
75      echo $_FILES["upfile"]["name"] . " already exists. ";
76      }
77    else
78      {
79        insertFile( $_POST['filepage'], 
80                    $_FILES["upfile"]["type"], 
81                    ($_FILES["upfile"]["size"] / 1024), 
82                    $_FILES["upfile"]["name"]);       
83        move_uploaded_file($_FILES["upfile"]["tmp_name"],"server/php/files/" . $_FILES["upfile"]["name"]);
84
85        echo "The FILE " . basename($_FILES['upfile']['name']) . " has been uploaded.<br>";
86        echo "Stored in: " . "server/php/files/" . $_FILES["upfile"]["name"] . "<br>";
87        echo "Upload: " . $_FILES["upfile"]["name"] . "<br>";
88        echo "Type: " . $_FILES["upfile"]["type"] . "<br>";
89        echo "Size: " . ($_FILES["upfile"]["size"] / 1024) . " kB<br>";
90        echo "Temp file: " . $_FILES["upfile"]["tmp_name"] . "<br>";
91
92      }
93
94
95?>
96
97