error, unexpected T_STRING in

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shanehenery
    New Member
    • Feb 2010
    • 24

    #1

    error, unexpected T_STRING in

    Hi
    I will like to add this below code to my data base but I have a string error that I cant correct be for I put it in my db can you pleas help

    I cant find any thing wrong with this line but it tels me that I have a "unexpected T_STRING" error in line 11 that is the line starting with "CREATE TABLE `course` and I sagest if this one line gives me a string error the rest of the lines will give me a error to be cos it all looks the same ore wont that matter


    Code:
    <?php
    
    CREATE TABLE `course` 
    (
    `cname` varchar(50) NOT NULL default",
    `cid` int(6) NOT NULL auto_increment,
    PRIMARY KEY (`cid`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    
    CREATE TABLE `course_student`(
    `sno` int(6) NOT NULL default '0',
    `cid` int(6) NOT NULL default '0',
    `year` int(4) NOT NULL default '0'
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    
    CREATE TABLE `student`(
    `sno` int(6) NOT NULL auto_increment,
    `sname` varchar(40) NOT NULL default",
    `init` varchar(5) NOT NULL default",
    `fname` varchar(40) NOT NULL default",
    `title` varchar(4) NOT NULL default",
    `msname` varchar(40) NOT NULL default",
    `dob` varchar(8) NOT NULL default",
    `sex` char(2) NOT NULL default",
    `lang` varchar(10) NOT NULL default",
    `idno` varchar(13) NOT NULL default",
    `telh` varchar(12) NOT NULL default",
    `telw` varchar(12) NOT NULL default",
    `cel` varchar(12) NOT NULL default",
    `fax` varchar(12) NOT NULL default",
    `email` varchar(40) NOT NULL default",
    `address` tinytext NOT NULL,
    PRIMARY KEY (`sno`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    ?>
    Thanks
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    strings have to be wrapped in " or '.
    Code:
    <?php
    $sql1 = "CREATE TABLE `course` 
    (
    `cname` varchar(50) NOT NULL default,
    `cid` int(6) NOT NULL auto_increment,
    PRIMARY KEY (`cid`)
    ) 
    ENGINE=MyISAM DEFAULT CHARSET=latin1";

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      That simply ain't valid PHP. What's the usefulness of sticking a load of SQL into a PHP file?

      Comment

      • shanehenery
        New Member
        • Feb 2010
        • 24

        #4
        HI
        if that is all I need to do it is still no working
        now it gives me a error unexpected , in line 20
        Code:
        `sname` varchar(40) NOT NULL default",

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          You need to escape that quote with a backslash.

          Comment

          • dlite922
            Recognized Expert Top Contributor
            • Dec 2007
            • 1586

            #6
            How are those SQL codes going to "magically" get added to your database?

            Looks like somebody needs a tutorial:
            With PHP, you can connect to and manipulate databases.





            Dan

            Comment

            • shanehenery
              New Member
              • Feb 2010
              • 24

              #7
              HI
              it is just an example ones there is no error on the script I will add it to my db
              but my db don't want to accept the code be cos there is a error

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                what you have shown here is just plain SQL code. there’s much more required to make a database script.

                Comment

                Working...