SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    can't write to database?

    So I wrote a tiny bit of PHP script to write to my database, looking like this:

    PHP Code:
    <?
    if ($signup == go) {
    MYSQL_CONNECT(localhostshhxxxxx) OR DIE("Unable to connect to database");

    @
    mysql_select_db("shh") or die("Unable to select database");

    $query "INSERT INTO users VALUES('$username','$password')";
    $result MYSQL_QUERY($query);

    echo (
    "Thank you:" $username "and" $password "have been added to the database.");

    MYSQL_CLOSE();
    } else {
    echo (
    "<form action=" $PHP_SELF " method=get>username: <input type=text name=username><br>password: <input type=text name=password><br><input type=submit name=signup value=go>");
    }
    ?>
    I've also tried it in various other forms, and none have worked. My table, "users" is setup, with the fields "UID" (primary integer, auto_increment) "username" (text) and "password" (text).

    The script, when run, returns that the values have been added, but when I check on the database, it's empty.

    Can anyone explain where I've gone wrong?

  2. #2
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change this:

    $query = "INSERT INTO users VALUES('$username','$password')";
    $result = MYSQL_QUERY($query);

    To This:

    $query = "INSERT INTO users (username,password) VALUES('$username','$password')";
    $result = MYSQL_QUERY($query)or die("Something Bummed out");

    Then run it. See what happens

  3. #3
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you! it now works like a charm!


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
  •