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

    Join Date
    Oct 2013
    Posts
    11
    Rep Power
    0

    Help with PHP Code


    Hi all, I am having a problem with this code to create a table in a selected database. My connectivity is good and I can create the Database no problem, however when I go to run the script I recieve no errors and a blank screen on my local host but when I check to see if the table has been created on phpmyadmin there is no table there also when I check the tables for my database in the cmd line there are no tables also here is my code any help is greatly appreciated.

    John


    <head>
    </head>
    <body>
    <?php
    $con = mysql_connect("localhost","root","");
    if(!$con){
    die("Cannot Connect: " . mysql_error());
    }
    mysql_select_db("ListParts2",$con);

    $sql = "CREATE TABLE manufacturer (
    Maker varchar(20)'
    Contact varchar(20),
    Location varchar(20),
    Phone int
    )";

    mysql_query($sql,$con);

    mysql_close($con);

    ?>
    </body>
    </html>
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,926
    Rep Power
    1045
    There's a quote instead of the comma -- which you would have found out yourself if you had tested the query or checked the database errors.

    What's much worse, though, is that your way of accessing the database is totally outdated. The mysql_* functions are obsolete since almost a decade. People today use PDO or MySQLi:

    How to (properly) access a MySQL database with PHP

    However, that's something for the PHP forum.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    You shouldn't be creating tables inside PHP scripts unless this script is meant to be an installer for something. You also REALLY shouldn't be connecting as root from a web script, nor should you be using the deprecated mysql_ functions.
    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