Web Analytics Made Easy -
StatCounter A $_GET problem! Done! - CodingForum

Announcement

Collapse
No announcement yet.

A $_GET problem! Done!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • A $_GET problem! Done!

    There was something wrong when I was creating the forum.
    I had created the table named “forums” as follow:

    CREATE TABLE forums(
    id TINYINT AUTO_INCREMENT PRIMARY KEY,
    cat_id TINYINT,
    name VARCHAR(30),
    description VARCHAR(255));
    and I also inserted some values into the table as follow:

    INSERT INTO forums
    (
    id,
    cat_id,
    name,
    description
    )
    VALUES
    (
    /* id */NULL,
    /* cat_id */1,
    /* name */'Comedy',
    /* description */'First that make you laugh'
    )
    (I set the id with the property with “AUTO_INCREMENT” when I created the table, so that’s why I keep the “id” NULL.)
    As a result, there is a message in the table.
    I tried to connect the database (MySQL) by typing the codes as follow:

    $db = mysql_connect($dbhost, $dbuser, $dbpassword);
    mysql_select_db($dbdatabase, $db);

    if(isset($_GET['id']) == TRUE) {
    if(is_numeric($_GET['id']) == FALSE) {
    header("Location: " . $config_basedir);
    }
    $validforum = $_GET['id'];
    }
    else {
    header("Location: " . $config_basedir);
    }

    “$config_basedir” is a variable which was defined in another file and I also “include” at the top.

    As you see, I though $_GET[‘id’] can return the value from the database, but it didn’t work. Instead, $validforum get the value of NULL, I checked the database, the value of “id” is 1. I had no idea…
    Some one helps me please, thank you!
    Last edited by ShawnLin; Apr 17, 2009, 02:03 AM.

  • #2
    you dont need to set the id you can just do like this
    PHP Code:
    INSERT INTO forums
    (
    cat_id,
    name,
    description
    )
    VALUES
    (
    /* cat_id */1,
    /* name */'Comedy',
    /* description */'First that make you laugh'

    you see that would work because when it is on auto increment it would automaticly set a value which is +1 higher than the last one that where set (i dont know never tried with comments in the mysql query .. )
    btw dont know if thisis just a snapshoot of your code but to execute it you should use mysql_query() ^^ unless youu are creating the table and query in a prompt ...
    Last edited by diload; Apr 16, 2009, 09:54 AM.

    Comment


    • #3
      Originally posted by diload View Post
      you dont need to set the id you can just do like this
      PHP Code:
      INSERT INTO forums
      (
      cat_id,
      name,
      description
      )
      VALUES
      (
      /* cat_id */1,
      /* name */'Comedy',
      /* description */'First that make you laugh'

      you see that would work because when it is on auto increment it would automaticly set a value which is +1 higher than the last one that where set (i dont know never tried with comments in the mysql query .. )
      btw dont know if thisis just a snapshoot of your code but to execute it you should use mysql_query() ^^ unless youu are creating the table and query in a prompt ...
      First of all, thank you for your help.
      I create the table on the phpMyadmin platform.
      I typed the code because I think I can express the problem more exactly.
      BTW, I was using the assistant software named SQL assistant. Adding comments is just to make you more clearly with the variables.
      I don't quite understand your idea. you were telling me to distribute "id" a value? Can you explain more exactly? thanks~

      Comment


      • #4
        i mean when you have your id in mysql set too atuto increment you dont have to set it in the php script it will be set to the last id set +1 automaticly btw you only have to set the values in a script to things you set in your mysql table to not null and dont have a default value set so you could basicly just set1 thing and the rest would be set to the default value you set (and if you didnt set its is nothing) like you could just set the name in a user login like this like this
        PHP Code:
        INSERT INTO members
        (
        username
        )
        VALUES
        (
        'someusername'

        in a table with e.g. id,username,password and email and maybe some other things ..

        hope you understand my english aint the best ...:S

        Comment


        • #5
          Originally posted by diload View Post
          i mean when you have your id in mysql set too atuto increment you dont have to set it in the php script it will be set to the last id set +1 automaticly btw you only have to set the values in a script to things you set in your mysql table to not null and dont have a default value set so you could basicly just set1 thing and the rest would be set to the default value you set (and if you didnt set its is nothing) like you could just set the name in a user login like this like this
          PHP Code:
          INSERT INTO members
          (
          username
          )
          VALUES
          (
          'someusername'

          in a table with e.g. id,username,password and email and maybe some other things ..

          hope you understand my english aint the best ...:S
          I think I can reach you a little, but what you thought is not the point.
          I have figured it out.
          $GET is only used on the Querystring, I typed the wrong url on my browser, that's why it didn't work. The codes is right.
          Anyway, thank you all the same.

          Comment

          Working...
          X