php, mysql , xampp, database

931

It is showing connected but table not created. can you please tell where the error is?

<?php
$con=mysqli_connect("localhost","root","", "Students");

if(mysqli_connect_errno()){
  echo "Connection Failed".mysqli_connect_errno();
} else{
  echo"connected";
}
mysqli_select_db($con,"Students");
$sql= "create table information(TITLE varchar(10), LNAME varchar(20),FNAME varchar(20),DESIGNATION varchar(20),DEPARTMENT varchar(20),ORGANISATION varchar(20),ADDRESS varchar(30),PRODUCT varchar(20),PERIOD varchar(20))";
if(mysqli_query($con, $sql)){
  echo "Table Created";
} else {
  echo "Table not Created";
}
?>
830

Answer

Solution:

Fixed a few errors (removed white space & added{} to the last else statement): try the following :

<?php

$con = mysqli_connect("localhost", "root", "", "Students");

if (mysqli_connect_errno()) {
    echo "Connection Failed" . mysqli_connect_errno();
} else {
    echo"connected";
}
mysqli_select_db($con, "Students");
$sql = "create table information(TITLE varchar(10), LNAME varchar(20),FNAME 
varchar(20),DESIGNATION varchar(20),DEPARTMENT varchar(20),ORGANISATION 
varchar(20),ADDRESS varchar(30),PRODUCT varchar(20),PERIOD varchar(20))";
if (mysqli_query($con, $sql)) {
    echo "Table Created";
} else {
    echo "Table not Created";
}
?>

People are also looking for solutions to the problem: php - Mocking Laravel Eloquent models - Mocking model that is used in AppServiceProvider

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.