-4

I was trying to make a sql database and i have faced some issues regarding INSERT INTO TABLE. I have noticed that sql is not allowing me to insert data in a table if the name of Database is u759286173 i am able to insert data into table using any other name but this particular (u759286173) database name is not allowing me to insert data in table

I have tried various database names which works

  1. 759286173
  2. 759286173_quebec
  3. 759286173_grvnaz
  4. u_grvnaz

Can someone please explain me that why data is not inserting in table when i allow the database name to be u759286173

My Database name : u759286173 My Table name : mydb

Please reply if u face the same issue or have a solution. Any help is appreciated.

My Code

<?php 
$dbServername = "localhost"; 
$dbUsername = "root"; 
$dbPassword = ""; 
$dbName = "u759286173"; 
$dbHost = " localhost"; 
$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);

other code

<?php 
session_start(); 
include 'dbh.inc.php'; 
if (isset($_POST) & !empty($_POST)) { 
    $first = $_POST['first']; 
    $last = $_POST['last']; 
    $email = $_POST['email']; 
    $message = $_POST['message']; 
    $sql = "INSERT INTO mydb (first, last, email, message) 
                VALUES ('$first', '$last', '$email', '$message');"; 
    mysqli_query($conn, $sql); 
    header("location: ../signup.php?send=success"); 
} else { 
    header('location: ../failed.php'); 
    exit(); 
} 
?> 

Form Code

<!DOCTYPE>
    <html>   
        <body>
            <form class="registerform" action="includes/contact.inc.php" method="POST">
                <input type="text" placeholder="first" name="first" required/>
                <input type="text" placeholder="last" name="last" required/>
                <input type="email" placeholder="E-mail ID" name="email"/>
                <input type="text" placeholder="message" name="message" required/>
                <button name="submit" type="submit">Create</button>
            </form>
        </body>
</html>

=Database u759286173

CREATE TABLE IF NOT EXISTS `mydb` (
  `id` int(11) NOT NULL,
  `first` varchar(32) NOT NULL,
  `last` varchar(32) NOT NULL,
  `email` varchar(50) NOT NULL,
  `message` varchar(150) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
grvnaz
  • 1
  • 1
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/202913/discussion-on-question-by-grvnaz-sql-limitation-on-database-name). – Samuel Liew Nov 22 '19 at 19:13
  • @SamuelLiew To be fair, it took all that time/effort to get from "It don't work" to a reason that it didnt work. – RiggsFolly Nov 22 '19 at 20:02

1 Answers1

0

The INSERT statement does not provide a value for the id column.

The id column is defined to be NOT NULL and does not have AUTO_INCREMENT property. (And we assume there isn't a BEFORE INSERT trigger that assigns a value to NEW.id

Given the table definition, we expect that when the INSERT statement is executed, MySQL will issue

Error Code: 1364
Field 'id' doesn't have a default value

(This could be a Warning rather than Error with some settings of sql_mode.)


Most important is that we check for MySQL error condition; this will provide the information we need in order to determine what the problem is.

At the top of the script, enable PHP and mysqli error reporting:

 ini_set('display_errors', 1); 
 ini_set('log_errors',1);
 error_reporting(E_ALL);
 mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

That will get use the information we need when a MySQL error occurs.

spencer7593
  • 106,611
  • 15
  • 112
  • 140