SitePoint Sponsor

User Tag List

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

    Angry Why Wont this Work!

    i do not understant why this will not work, it will go thru all the echo "passed" marks, but will not write to the mysql database, please someone help.

    +-----------------------------------+
    trim($username);
    trim($pass);

    if (!$username)
    {
    echo "enter Username";
    exit;
    }
    if (!$pass)
    {
    echo "Enter Pass";
    exit;
    }

    echo "Passed1";

    $dbuser = 'design';

    $dbhost = 'localhost';

    $dbpass = 'xxxxxx';

    $dbname = 'designman';

    $dbtble = 'auth';

    $mysql_link = mysql_connect($dbhost,$dbuser,$dbpass);

    echo "Passed2";

    if (!$mysql_link)
    {
    echo "Could Not Connect";
    }

    echo "Passed3";

    mysql_select_db($dbname);
    $query = "insert into auth values
    ('".$username."', '".$pass."')";
    $result = mysql_query($query);
    if ($result)
    echo mysql_affected_rows()." inserted into database.";
    +-----------------------------------+

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $query = "insert into auth values
    ('".$username."', '".$pass."')";
    __________


    try:

    $query = "INSERT INTO auth(username, pass) VALUES('$username','$pass')";

    it's a good habit to capitalize sql statements. your table will grow, you'll have more variables, field names, etc.
    it's not necessary, but easier to read.

    put vars in single quotes. even if you have only two columns (username and pass), it's a good habit to declare which is which.

    if you have also an auto-increment-id field, it's safer anyway. don't let mysql guess where it has to insert what.

  3. #3
    SitePoint Member
    Join Date
    May 2002
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you it worked :-)


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
  •