Thread: New to php

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

    Join Date
    Nov 2012
    Posts
    13
    Rep Power
    0

    New to php


    <?php
    $db=mysql_connect("localhost","root","") or die("Unable to connect!Pls check your connection parameters.");
    mysql_select_db(moviesite,$db) or die(mysql_error($db));


    //alter the movie table to include time,cost and takings
    $query='ALTER TABLE movie ADD COLUMN(
    movie_running_time TINYINT UNSIGNED NULL,
    movie_cost DECIMAL(4,1) NULL,
    movie_takings DECIMAL(4,1) NULL)';
    mysql_query($query,$db) or die(mysql_error($db));

    //insert new data into the movie table for each movie
    $query="UPDATE movie SET movie_running_time=111,movie_cost=81,movie_takings=242.6 WHERE movie_id=1";
    mysql_query($query,$db) or die(mysql_error($db));

    $query="UPDATE movie SET movie_running_time=87,movie_cost=10,movie_takings=10.8 WHERE movie_id=2";
    mysql_query($query,$db) or die(mysql_error($db));

    $query="UPDATE movie SET movie_running_time=164,movie_cost=NULL,movie_takings=33.2 WHERE movie_id=3";
    mysql_query($query,$db) or die(mysql_error($db));

    echo "Movie database successfully updated";




    ?>





    error is Duplicate column name 'movie_running_time'
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    399
    Rep Power
    190
    Here you try to alter the table to add three columns. The second time you run your code, you will error out, because they were already created before.

    Code:
    $query='ALTER TABLE movie ADD COLUMN(
    movie_running_time TINYINT UNSIGNED NULL,
    movie_cost DECIMAL(4,1) NULL,
    movie_takings DECIMAL(4,1) NULL)';
    mysql_query($query,$db) or die(mysql_error($db));
    Thomas Tremain
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    13
    Rep Power
    0

    thanx


    thanx thomas ur reply was reallly helpful!! thanx a lot thank you

IMN logo majestic logo threadwatch logo seochat tools logo