SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2001
    0 Post(s)
    0 Thread(s)

    prob w/mysql table settings and insert data

    i have a script here that adds info to a table. now it works fine with one table, but when i changed the variables so it would work with my other table it does not. i know the problem MUST be with how i made the table, meaning the settings/properties. cuz i tried it with a table in which i only gave "username varchar(50)" properties. and it worked. so heres my script and heres the table creation code. hope you can help. im pretty new with mysql so im not sure about these settings i gave it, which is probably why im gettin errors. a link to a tutorial for learning all these settings would be a big help too . thank you

    create table users (
    userid int not null unsigned auto_increment primary key,
    user varchar(50),
    password varchar(50,
    email varchar(50)

    and now heres the script.. it doesnt throw an error, it tells me it is successful. but no data gets entered into table =/.----

    if ($user) {
    mysql_connect("localhost", "user", "pass") or die ("Problem connecting with database");
    $query = "insert into user values ('$user')";
    $result = mysql_db_query("box", $query);

    echo "data inserted. new table: <br><p></p>";
    $query = "SELECT * FROM user";
    $result = mysql_db_query("box", $query);

    if ($result) {
    while ($r = mysql_fetch_array($result)) {
    $user = $r["user"];

    echo "<table class='outline_table' width='100%' cellpadding='5'><tr>
    <td align='left'>$user </td></tr><tr>
    </tr></table><br />";
    } //end while loop

    } else {
    echo"No data.";
    } // end of if ($result)

    } else {
    echo "No UserName entered. Please go back and reenter UserName";
    } // end of if ($user)
    echo "<p></p>";

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    0 Post(s)
    0 Thread(s)

    $query = "insert into user values ('$user')";

    When I read that insert statement, I can see that you are inserting into a table called "user" and I can see you want to insert the value "$user", but I can't see which of the fields you want to insert "$user" into. Do you think that since you have a field called "user" that mysql somehow knows that it should insert $user into "user" and not into "userid", "password", or "email" ?
    Last edited by 7stud; May 27, 2001 at 21:27.

  3. #3
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    0 Post(s)
    0 Thread(s)
    try this.

    $insert = "insert into user (user) values ('$user')";
    $query = mysql_query($insert);

    if(!$query) {
    echo "Error : $insert <br>" . mysql_error();
    Last edited by kunal; May 28, 2001 at 10:12.
    i dunno...


Posting Permissions

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