Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Junior Member KingLionheart's Avatar
    Join Date
    Feb 2006
    Posts
    3
    Member #
    12570
    I will try to explain my problem in as much detail as possible. I haven't touched MySQL or anything Database related for about two years and it appears I've lost memory.

    My friend set up a database called ABC for me. I can connect to the database fine, that's not the problem.

    I created a table called "league" and under that I added five fields:

    name - Type: varchar14
    played
    points
    won
    lost

    Everything is an integer except "name" which is a varchar(14). I also didn't know what to set, i think is called. "primary key" or "index", so I set name to it.

    As I stated earlier I can connect to the database, just not add any info.

    Here is what I am trying to do:
    PHP Code:
    mysql_query ("INSERT INTO league (name, played) VALUES ('Lionheart', '0')"); 
    I tried that as a test and it didn't work. I'm really tired so I'm probably doing something stupid here. I'm stuck as i'm not sure if it's a problem due to a completely wrong/messed database entries, or something to do with the PHP.

    Any help is really appreciated, thanks

  2.  

  3. #2
    Senior Member karinne's Avatar
    Join Date
    Dec 2003
    Location
    Aylmer QC Canada
    Posts
    1,607
    Member #
    4335
    Liked
    8 times
    Try

    PHP Code:
    $insert mysql_query("insert into league (name, played) values ('Lionheart', 0)"); 
    Notice that there is no ' ' around the 0 since it's an interger you don't need the ' '.

    As for your primary key, you have to make sure it's unique. For example, since "name" is your PK, you cannot have another Lionheart in there.

    This might help - http://dev.mysql.com/doc/refman/5.0/...ate-table.html - just scroll down a bit to the bullets and there info in there on PK.

    hth
    [a web design portfolio - Currently NOT AVAILABLE for work | web design | Re-coding | PSD-to-HTML]
    I'm also on: virb - facebook - twitter - flickr - del.icio.us

  4. #3
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Hey.

    You do not need single quotes around the integer value.

    (I created a similar table - http://bfsog.co.uk/testing/league.php

    PHP Code:
    <?php
        $res 
    mysql_query ("INSERT INTO league (name, played) VALUES ('Lionheart', 0)");
    ?>

  5. #4
    Junior Member KingLionheart's Avatar
    Join Date
    Feb 2006
    Posts
    3
    Member #
    12570
    Ah, it was me being very stupid. I didn't add all the fields in :cross-eyed:

    The information you guys gave me was great however, thank you very much :smoker:

  6. #5
    Senior Member karinne's Avatar
    Join Date
    Dec 2003
    Location
    Aylmer QC Canada
    Posts
    1,607
    Member #
    4335
    Liked
    8 times
    You don't have to add all the fields in if you have chosen your column to have null values (nothing in them).
    [a web design portfolio - Currently NOT AVAILABLE for work | web design | Re-coding | PSD-to-HTML]
    I'm also on: virb - facebook - twitter - flickr - del.icio.us


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:08 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com