Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15

Thread: Create sql row

  1. #1
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post

    Create sql row

    I made the following code in a text file to import through phpmyadmin and create a row;

    PHP Code:
    ALTER TABLE ws_780_settings
    ADD 
    (     activetheme     varchar(255CHARACTER SET utf8 NOT NULL DEFAULT 'default' ); 
    What i want to do is made it into a php so users can just browse to yoursite.com/install.php, but i cant get the files to work. Can someone rewrite that small peice to put in a .php file, here is what i tried but it doesnt add the row.


    PHP Code:
    <?php
    include ("_mysql.php");
    mysql_connect($host$user$pwd) or die ('FEHLER: Keine Verbindung zu MySQL');
    mysql_select_db($db) or die ('FEHLER: Konnte nicht zur Datenbank "'.$db.'" verbinden');

    mysql_query("INSERT INTO ".PREFIX."settings (activetheme) 
    VALUES (default)"
    );

    echo
    '<center><h2>Theme Selector has be installed.</h2><h2>Make sure to delete install.php from your server.</h2><h2>Visit <a href="http://www.cgshost.com/">CGShost.com</a> for support and more!</h2></center>';
    ?>

    here is an example of another one i have (for a diff mod) that works perfect;

    PHP Code:
    <?php
    include ("_mysql.php");
    mysql_connect($host$user$pwd) or die ('FEHLER: Keine Verbindung zu MySQL');
    mysql_select_db($db) or die ('FEHLER: Konnte nicht zur Datenbank "'.$db.'" verbinden');

    mysql_query("DROP TABLE IF EXISTS ".PREFIX."features");
    mysql_query("CREATE TABLE ".PREFIX."features (
      featureID int(11) NOT NULL auto_increment,
      url varchar(255) NOT NULL default '',
      featurestext varchar(255) NOT NULL default '',
      banner varchar(255) NOT NULL default '',
      sort int(11) NOT NULL default '0',
      PRIMARY KEY  (featureID)
    ) TYPE=MyISAM PACK_KEYS=0 AUTO_INCREMENT=2 "
    );

    echo
    '<center><h2>Features installed sucesfully</h2><br><h2><br><br><br>Please delete install.php</center>';
    ?>
    Thanks for any help!
    Last edited by Cliffo; 03-28-2010 at 05:41 AM.

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    How about instead of someone doing your work for you, you post the broken code and ask for help fixing that?
    Are you a Help Vampire?

  • Users who have thanked tomws for this post:

    Cliffo (03-28-2010)

  • #3
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    Sure sorry about that,

    PHP Code:
    <?php
    include ("_mysql.php");
    mysql_connect($host$user$pwd) or die ('FEHLER: Keine Verbindung zu MySQL');
    mysql_select_db($db) or die ('FEHLER: Konnte nicht zur Datenbank "'.$db.'" verbinden');

    mysql_query("ALTER TABLE ".PREFIX."settings ( ADD
      activetheme varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT 'default') 
      TYPE=MyISAM PACK_KEYS=0 AUTO_INCREMENT=2 "
    );

    echo
    '<center><h2>Theme Selector has installed sucesfully</h2><br><h2><br><br><br>Please delete install.php</center>';
    ?>

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    You mentioned a syntax error in the original post. What is it? And is it from php or mysql?

    EDIT: By the way, there's a misspelling. Should be "successfully".
    Are you a Help Vampire?

  • Users who have thanked tomws for this post:

    Cliffo (03-28-2010)

  • #5
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    When i run it through the web browser there are no errors at all but the row never gets added to the table, syntax errors were from uploading directly but i want to prevent having to do that.

  • #6
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    It's a column (or field) you're adding, not a row.

    The ALTER query in the first post is different than the query in the broken code. Why?
    Are you a Help Vampire?

  • #7
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    I added the prefix command from the _mysql and what not, plus i really only know html still trying to learn sql and php.

  • #8
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    So, you've defined PREFIX somewhere? What about this stuff?
    Code:
    TYPE=MyISAM PACK_KEYS=0 AUTO_INCREMENT=2
    Are you a Help Vampire?

  • #9
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    Not sure, i seen it in the other install.php that does the same thing im trying to do, i have tried dozens of different ways while reading w3schools, here is my latest;

    PHP Code:
    <?php
    include ("_mysql.php");
    mysql_connect($host$user$pwd) or die ('FEHLER: Keine Verbindung zu MySQL');
    mysql_select_db($db) or die ('FEHLER: Konnte nicht zur Datenbank "'.$db.'" verbinden');

    mysql_query("INSERT INTO ".PREFIX."settings (activetheme) 
    VALUES (default)"
    );

    echo
    '<center><h2>Theme Selector has be installed.</h2><h2>Make sure to delete install.php from your server.</h2><h2>Visit <a href="http://www.cgshost.com/">CGShost.com</a> for support and more!</h2></center>';
    ?>

  • #10
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    mysql_query("ALTER TABLE ".PREFIX."settings ADD COLUMN activetheme varchar(255) NOT NULL DEFAULT 'default'") or exit(mysql_error());

  • Users who have thanked MattF for this post:

    Cliffo (03-28-2010)

  • #11
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Why are you attempting an INSERT? Didn't you say that this works through phpmyadmin?
    Code:
    ALTER TABLE ws_780_settings
    ADD (     activetheme     varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT 'default' );
    If so, make that your query. If it works, then you can get more fancy and figure out how to use a prefix.

    The other one does not do what you're trying to do - it creates an entirely new table. You can tell because it says CREATE TABLE.
    Are you a Help Vampire?

  • #12
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    If so, make that your query. If it works, then you can get more fancy and figure out how to use a prefix.
    Obviously i tried that and it doesnt work, syntax errors.

    Matt i tried yours and for some reason it gave a duplicate column error but it defiantly is not there, i even tried on a fresh db and same error.

  • #13
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    Never mind MattF's works, thanks!

  • #14
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by Cliffo View Post
    Obviously i tried that and it doesnt work, syntax errors.
    You were asked for the errors way back in post #4 and then said there really weren't any.
    Are you a Help Vampire?

  • #15
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    Here is the final code, thanks again!

    PHP Code:
    <?php
    include ("_mysql.php");
    mysql_connect($host$user$pwd) or die ('FEHLER: Keine Verbindung zu MySQL');
    mysql_select_db($db) or die ('FEHLER: Konnte nicht zur Datenbank "'.$db.'" verbinden');

    mysql_query("ALTER TABLE ".PREFIX."settings DROP COLUMN activetheme");

    mysql_query("ALTER TABLE ".PREFIX."settings ADD COLUMN activetheme varchar(255) NOT NULL DEFAULT 'default'") or exit(mysql_error());

    echo
    '<center><h2>Theme Selector has be installed.</h2><h2>Make sure to delete install.php from your server.</h2><h2>Visit <a href="http://www.cgshost.com/">CGShost.com</a> for support and more!</h2></center>';
    ?>
    Please set to resolved.


  •  

    Posting Permissions

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