Results 1 to 8 of 8
  1. #1

    Question MySQL user id problem

    Hi, I am trying to set up a system where by visitors can submit there site with a mini banner to my site. The data needs to be saved in MySQL dadabase table called: site_affiliates_validating. What i have got below works fine, but the only part that doesnt work is the id. Whenever i try to use auto_incriment it will not create the table. I think I have done the rest of it right, but if you spot any errors or things that could be changed, please feel freee to tell me.

    install.php
    PHP Code:
    <?php
    // AFFILIATES - VALIDATING
    mysql_query("DROP TABLE IF EXISTS site_affiliates_validating");
    mysql_query("CREATE TABLE site_affiliates_validating (
        id mediumint(3) default NULL,
        website varchar(40) default NULL,
        url varchar(70) default NULL,
        banner varchar(128) default NULL,
        name varchar(30) NULL,
        email varchar(60) NULL,
        ip_address varchar(16) NOT NULL default '')"
    );
    ?>
    signup_action.php
    PHP Code:
    <?php
    $ip_address 
    getenv("REMOTE_ADDR");

    mysql_query("INSERT INTO site_affiliates_validating SET
        id = LAST_INSERT_ID(),
        website='
    $website',
        url='
    $url',
        banner='
    $banner',
        name='
    $name',
        email='
    $email',
        ip_address='
    $ip_address'");
    ?>
    I hope some one can help me with this matter as this is my first php/mysql project and i'm still not too good.

    Thanks in advance,
    Matt
    http://www.theextremenetwork.com
    MSN: [email protected]

  2. #2
    Join Date
    Nov 2003
    Location
    tampa, fl
    Posts
    326
    I'm new with this stuff too, but, I believe it has something to do with how you declared id. Check this out.

    http://www.mysql.com/doc/en/example-AUTO_INCREMENT.html

    I'm also not sure that the last_insert_id() is needed, but I could be wrong.
    Last edited by recipher; 03-04-2004 at 04:27 PM.

  3. #3
    Still cant get it working :-( Anyone know how I can get it to function properly?
    http://www.theextremenetwork.com
    MSN: [email protected]

  4. #4
    FINALY GOT IT WORKING

    Final Code For Referance:

    install.php
    PHP Code:
    mysql_query("DROP TABLE IF EXISTS site_affiliates_validating");
    mysql_query("CREATE TABLE site_affiliates_validating (
        id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
        website varchar(40) default NULL,
        url varchar(70) default NULL,
        banner varchar(128) default NULL,
        name varchar(30) NULL,
        email varchar(60) NULL,
        ip_address varchar(16) NOT NULL default '')"
    ); 
    signup_action.php
    PHP Code:
    mysql_query("INSERT INTO site_affiliates_validating SET
        website='
    $website',
        url='
    $url',
        banner='
    $banner',
        name='
    $name',
        email='
    $email',
        ip_address='
    $ip_address'"); 
    Thanks for your help recipher!
    Last edited by ballingtonma; 03-04-2004 at 05:33 PM.
    http://www.theextremenetwork.com
    MSN: [email protected]

  5. #5
    Join Date
    Mar 2004
    Location
    california
    Posts
    162
    signup_action.php
    PHP Code:
    mysql_query("INSERT INTO site_affiliates_validating SET
        website='
    $website',
        url='
    $url',
        banner='
    $banner',
        name='
    $name',
        email='
    $email',
        ip_address='
    $ip_address'"); 
    Actually, I would use this:
    PHP Code:
    mysql_query("INSERT INTO site_affiliates_validating (website, url, banner, name, email, ip_address) VALUES ('$website','$url','$banner','$name','$email','$ip_address')"); 
    The point of the auto increment type is that it automatically increments for you (hence the name) so you don't have to insert it. Each time you insert a new record it is always +1 from the previous value.

  6. #6
    Ok, thanks. What is the best way to display the data, I dont know all the code but its something like:
    PHP Code:
    mysql_query("SELECT id, site, url, name, email, ip_address FROM site_affiliates_validating WHERE *???* ORDER BY id LIMIT 100"); 
    I dont know how to do that, and I have been looking everywhere to do it, thanks.
    http://www.theextremenetwork.com
    MSN: [email protected]

  7. #7
    Join Date
    Nov 2003
    Location
    Amidst several dimensions
    Posts
    4,321
    If all registrants will be identified with unique ids - and it has to be so for easy referral purposes in every aspect - then do the id column unique. Hence it wont be possible to have 2 same values in id fields. that is the basic.

    As for the best way to display, ORDER BY id is very good, but as the latest registrant will be having a bigger id number you have to use ORDER BY id DESC LIMIT 100. Else it will sort as the oldest registrant being the topmost, and it will put data in that order either to screen or to any array.

    also why put in all the column names ? use *.

    SELECT * FROM site_affiliates_validating WHERE *your query* ORDER BY id DESC LIMIT 100

    is better. and i guess youll be probably using this table for only validation of registrants, you might as well use

    SELECT * FROM site_affiliates_validating ORDER BY id DESC LIMIT 100

    hope this helps

  8. #8
    Thanks, that helps!

    Yes, it is only for validating. Using checkboxes and a select menu, to delete or accept the site. If i accept the site, i need it to move the row(s) to the site_affiliates table and if i dont accept the row needs to be deleted. Im not sure how to go about setting this up but help is appreciated.
    PHP Code:
    <? 
    echo "<form method=\"post\">";
    // Display the sites awaiting authorisation in the table
    while ( $row mysql_fetch_array($result) ) {
    $id $row["id"];
    $website $row["website"];
    $url $row["url"]; $url wordwrap($url35'<br />'1);
    $banner $row["banner"]; $banner wordwrap($banner35'<br />'1);
    $name $row["name"];
    $email $row["email"];
    $ip_address $row["ip_address"];
    echo 
    "$id $website $url $banner $name $email $ip_address <input type=\"checkbox\" name=\"id\" value=\"$id\">");
    }
    echo <
    select size=\"1\" name=\"authorisation\"><option value=\"authorise\">Authorise</option><option value=\"remove\">Remove</option></select><input type=\"submit\" name=\"submit\" value=\"submit\"></form>";
    ?>
    Thanks,
    Matt
    Last edited by ballingtonma; 03-07-2004 at 01:26 PM.
    http://www.theextremenetwork.com
    MSN: [email protected]

Posting Permissions

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