SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    Seattle, WA
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm new to PHP & MySQL, so please bear with me. I'm running PHP & MySQL on Windows Apache on my Windows ME machine. Here's my problem:

    I've developed a user registration form which requests new user information on my "register1.php" page. When the new user hits the submit button, the form action="register2.php" sends the user to the next page and the code for "register2.php" creates a connection, selects my database and the inserts the data received from the "register1.php" page.

    All this works fine -- sometimes!! At other times, however, I get an error message, "Couldn't execute query," which is the error message associated with query which should insert the data.

    I know my code is correct, because it works just like I want it to -- it just doesn't work every time I try it.

    VERY frustrating! Does anyone have an explanation/solution?

    SeattleDan

  2. #2
    SitePoint Zealot DarkMonkey's Avatar
    Join Date
    Apr 2001
    Location
    uk
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not quite sure about that, but it sounds like it could be a windows problem, cause like you have to start apache each time and **** and stuff and...

    I'm not sure

  3. #3
    Idea Developer
    Join Date
    Sep 2000
    Location
    Bethlehem, PA
    Posts
    521
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the problem cant have anything to do with windows or php.

    What did you designate as the primary key? Probably hte login, if you did then it will say cannot execute query, it will give you that if the login name already exists in the database.

  4. #4
    SitePoint Zealot DarkMonkey's Avatar
    Join Date
    Apr 2001
    Location
    uk
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should probably punch me
    I just assumed that if it worked sometimes but not others that the database was working sometimes, and not others.

    But I guess that was a vague assumption. I've never heard the error msg before, so I wouldn't know.

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    Seattle, WA
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The primary key in my table is an auto-incremented integer which I have designated as "user_id." Thus, there is no way another new user could end up with the same user_id as another user.

    The database seems to work just fine -- sometimes. When it doesn't, the error message that I get is one that I designated to show up if and when the query does not complete the "insert" data function.

    I sure hope you guys can figure this one out for me. Thanks for your thoughts.

    SeattleDan

  6. #6
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Post your code.

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    Seattle, WA
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    O.K. The data is collected from new users in a form on the page titled "register1.php and is then passed to the page titled "register2.php where it's inserted into the "users" table. Here's the code for the page titled "register2.php:

    <?
    // file: register2.php
    // purpose: Script to add users' personal info to "users" table in a MySQL database
    // created April 17, 2001
    ?>

    <?
    // include error message alert box (error.inc)
    INCLUDE "includes/error.inc";


    // Check to be sure all required fields are filled in
    if ((!$acct_name) || (!$user_fname) || (!$user_lname) || (!$user_email) || (!$user_phone)) {
    error("One or more required fields were left blank.\\n".
    "Please fill them in and try again.");
    }
    ?>

    <HTML>
    <HEAD>
    <TITLE>Customer Registration - Step 1</TITLE>
    </HEAD>
    <BODY BACKGROUND="images/blueback.gif">

    <?
    $user_password = substr(md5(time()),0,6);

    $sql = "INSERT INTO users (acct_name, user_password, user_fname, user_mi, user_lname, user_title, user_email, user_phone, user_fax)
    VALUES ('$acct_name', '$user_password', '$user_fname', '$user_mi', '$user_lname', '$user_title', '$user_email', '$user_phone', '$user_fax')";

    // create connection
    $connection = mysql_connect("localhost","root","katylynn") or die ("Couldn't connect to server.");

    // select database
    $db = mysql_select_db("iso",$connection) or die ("Couldn't select database.");

    // execute SQL query and get result
    $sql_result = mysql_query($sql,$connection) or die ("Couldn't execute query.");
    ?>

    ...... [more code, not relevant to this issue]

    </BODY>
    </HTML>

    I hope this helps in figuring out what's causing this problem. Thanks again for your efforts.

    SeattleDan


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
  •