Why I can not upload file to my database?

user9987783

I need to create a form about companies with couple of information (as you can see down below), but every time I want to upload a new row I get 1's in every column.

So, I want to know what should I do with my code?

        <?php 
        include('mysql.php');

        if ($_POST) {
                 $companyName = isset($_POST['cname']);
                 $address = isset($_POST['address']);
                 $phoneNubmber = isset($_POST['phoneNubmber']);

                      $result = $connection->query("INSERT INTO `companies` 
                      (`name`, `email`, `phone`) VALUES('$cegnev ', 
                     '$address', '$pn')");

    header('Location: http://localhost/phptest/test.php');

    mysqli_close($connection);
}
?>

<!DOCTYPE html>
<html>
    <head>
        <title>Form</title>
        <meta charset="UTF-8">
        <link rel="stylesheet" tpe="text/css" href="urlapcss.css">
    </head>
    <body>
    <div id="container">
        <form id="reg" action="test.php" method="post">
            <fieldset>
                <legend>Form</legend>
                <ol>
                <li>
                        <label for="cname">Name of the company<em>*</em></label>
                        <input id="cname" type="text"  name="cname"/>
                    </li><li>
                        <label for="address">Email<em>*</em></label>
                        <input id="address" type="text"  name="address"/>
                    </li><li>
                        <label for="phoneNubmber">Phone number<em>*</em></label>
                        <input id="phoneNubmber" type="text" name="phoneNubmber" />
                    </li>
                </ol>
            </fieldset>
            <input type="submit" value="OK"/>
        </form>
    </div>
    </body>
</html>

Here is the table.

Btw, the mysql.php, if you wondering what this .php file contains :

<?php
$host = "localhost";
$userName = "root";
$password = "";
$DBname = "hgeza06";

$connection = new mysqli($host, $userName, $password, $DBname);
if ($connection->connect_error) {
    die("Error");
} else {
    echo "Succes!";
}
?>
Ionut S.

isset($_POST['cname']) - will return 1 if you have $_POST['cname'] or 0 if you don't have it.

A better way will be :

$companyName = isset($_POST['cname']) ? $_POST['cname'] : '' ; //add a empty value if is not filled
$address = isset($_POST['address']) ? $_POST['address'] : '';
$phoneNubmber = isset($_POST['phoneNubmber']) ? $_POST['phoneNubmber'] : '';

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I want to upload some picture files to my server and record the file name in mysql database but somehow there exists a problem

Why can't I redirect the output of my binary to a file?

Can I upload italic and/or bold text to my firebase database?

why I can not open my sqlite database from firedac?

Why I can't select a table existing in my database?

Why can't I upload a file to s3 with my Lambda function?

Why I can't submit my form to Database when I pass `LoginRequiredMixin` to my `view` in Django?

how can i upload image using react native expo image to my local server PHP / Database MySQL

Why can I only load local resources for my index file?

Why I can not see the content (File Explorer) my phone in DDMS?

Where can I find where to upload my apk file?

How can I upload a GarageBand (.band) file into my rails app?

Why can I not rename the directory of my file?

Why i can not delete user log in in my database?

Why Can't I Connect to My Database Over the Internet

Java FXML: Why is my imageView not Showing, and how can I upload an image from my computer?

Why doesn't my tmp_file_upload file exist? I'm using php 5.6

Why can't I create a new file in my working directory?

Why can't I retrieve data from my Json file?

Is there any file i can use to be my game database?

Why can't I upload the dSYM of my new app to HockeyApp?

Can I download or upload file using CURL for file://///my_windows/test (non-http link)

Why can't I require a Java library in my Clojure file?

Why can't I search my project database? - Various warnings

Why can't I delete this file from my Xcode project?

Why cant i upload image on Database in php?

Can't upload data from excel file to my database (mysql) using c#

How can i upload a file to Kloudless from my android?

Why I can't find my database file in C: disc from DB Browser

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive