#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0

    Error while creating table at mySql (noob)


    Hi guys i am getting this error

    mysqli_error() expects exactly 1 parameter, 0 given

    at this line

    Code:
    echo "Error creating table: " . mysqli_error();
    here is the complete code:

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>


    <?php
    $con
    =mysqli_connect("127.0.0.1:3306","root""""project2");
    // Check connection
    if (mysqli_connect_errno())
      {
      echo 
    "Failed to connect to MySQL: " mysqli_connect_error();
      }

    // Create database

    $sql="CREATE DATABASE proj2";
    if (
    mysqli_query($con,$sql))
      {
      echo 
    "Database proj2 created successfully";
      }
    else
      {
      echo 
    "Error creating database: " mysqli_error();
      }
      
      
      
      
      
    // Create table
      
     
    $sql="CREATE TABLE contacts
        (
        ID INT(5) NOT NULL AUTO_INCREMENT,
        primay key(ID),
        Firstname CHAR(30),
        Lastname CHAR(30), Phone VARCHAR(45), 
        Email VARCHAR(45))"
    ;
        
        
        
        
        
        
        
        
        

    // Execute query
    if (mysqli_query($con,$sql))
      {
      echo 
    "Table persons created successfully";
      }
    else
      {
      echo 
    "Error creating table: " mysqli_error();
      }
      
      
    ?>
    </body>
    </html>
    Any solutions ?
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,749
    Rep Power
    9397
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,232
    Rep Power
    593
    You have mixed syntax.
    PHP Code:
    echo "Error creating table: " mysqli_error
    or
    PHP Code:
    echo "Error creating table: " mysqli_error($con); 
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0
    One more question guys, how can i check if database or table exists and if yes delete and make new ones ?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,232
    Rep Power
    593
    MySQL has a built in 'if exists' syntax. Look it up.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0
    Originally Posted by gw1500se
    MySQL has a built in 'if exists' syntax. Look it up.
    i try this
    PHP Code:
    mysql_query("DROP TABLE IF EXISTS contacts"); 
    over create table command but it does not works i get this error

    Warning: mysqli_error() expects exactly 1 parameter, 0 given in D:\xampp\htdocs\project2.php on line 32
    Error creating database: Error creating table: Table 'contacts' already exists
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    Again, your error about mysqli_error is unrelated to the line about mysql_query. mysqli_error expects an argument. Give it one.

    Why are you even dropping and recreating a table? You can just "DELETE FROM CONTACTS;"

    Also, your script calls the table by two different names.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0
    Originally Posted by ManiacDan
    Again, your error about mysqli_error is unrelated to the line about mysql_query. mysqli_error expects an argument. Give it one

    Can you be more specific on this ?




    Why are you even dropping and recreating a table? You can just "DELETE FROM CONTACTS;"

    i want to check if database or table already exists and drop it, because if i change something to my script and reload, i must go to mysql workbench and drop proj2 database all the time.
    If would like to hear a soluthion for this, if there is any






    Also, your script calls the table by two different names.

    Where is this hapenning ?


    Really thanks for your help and for your time !
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,232
    Rep Power
    593
    I already gave you the solution for the mysqli_error problem. Pick one.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  18. #10
  19. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    Can you be more specific on this ?
    As GW said, you've been given this solution. You were handed this solution even after being linked to the manual page for it.

    i want to check if database or table already exists and drop it, because if i change something to my script and reload, i must go to mysql workbench and drop proj2 database all the time.
    If would like to hear a soluthion for this, if there is any
    You're saying "database" now instead of "table." If you're dropping an entire database every time you alter your script, you're doing it wrong. Set up your data structure first, and make your scripts flexible enough so that new columns won't break them. However, the DROP TABLE syntax should still work regardless.

    Where is this hapenning ?
    Your success message says "persons", your query says "contacts"
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo