SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    ********* Scotland Saltire's Avatar
    Join Date
    Jan 2000
    Location
    Scotland
    Posts
    660
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using ALTER in php script?

    I need to be able to ADD a new column to my mysql database table, when a new 'date' is created for a mailing list i.e. list_2004-12-15 as a column name, but am unsure on how to go about getting the code correct to allow this sort of query to be executed.

    I tried a couple of times with output from phpmyadmin but it just gave expecting ` errors.

    Any help as ever, appreciated.

  2. #2
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want to have a look at the alter table page in the MySQL manual.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  3. #3
    ********* Scotland Saltire's Avatar
    Join Date
    Jan 2000
    Location
    Scotland
    Posts
    660
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So this doesn't work:

    $mailing_name = $mname . _ . $date;
    $update_add_mailingname = mysql_query("ALTER TABLE emails ADD $mailing_name ENUM('N','Y') DEFAULT 'N'");

    But the below does add a table, just not with the name of the name of the variable.

    $mailing_name = $mname . _ . $date;
    $update_add_mailingname = mysql_query("ALTER TABLE emails ADD mailing_240904 ENUM('N','Y') DEFAULT 'N'");

    So how would I get it to add it with the variable as the table name?

  4. #4
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What table name gets added? Did you echo the value of $mailing_name to see if that is what you expect?
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  5. #5
    ********* Scotland Saltire's Avatar
    Join Date
    Jan 2000
    Location
    Scotland
    Posts
    660
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It just gives me an error message which I put in if the query does not execute successfully...

    I know the value of $mailing_name is as expected as it inputs this correctly into the database record of the mailing name.

  6. #6
    ********* Scotland Saltire's Avatar
    Join Date
    Jan 2000
    Location
    Scotland
    Posts
    660
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I fixed it.

    The problem was due to the mysql_query before the first ("

    Removing mysql_query fixed it.

    Strange, I thought I had tried it that way before and it errored.

    Oh well!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •