Announcement

Collapse
No announcement yet.

[none-vB] PHP/MySQL back-end question(s)

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

  • [none-vB] PHP/MySQL back-end question(s)

    I am sorry if these are dumb questions, but I just want to learn to do it properly, and my eyes aren't really helping me (so reading pages with code from PHP for dummies stresses me a lot). I do have some experience, and I hope I learn quick. Sorry if this isn't the right board. Oh, nope, this has nothing to do with vBulletin...

    Here is what I want.

    I have 2 public pages, and then some "backend" pages to 'manage' them.

    Getting the information from the database is not really a problem for me, and putting them into a .php page with the html around it, works for me too. The problem currently lies here; I need a boost, a startup on how to properly add/modify/delete stuff from the database.

    So, imagine a back-end page, called add.php which lets me add a new category to a list of categories. This list will be displayed on one of the two public pages, where they can click on the category and end up on the second page, where they can select something to download.

    With help from sparkz I was able to think straight and I figured out the command to make a table in my database. With the rows that I require. So, feel free to check them and tell me if they are correct.

    Code:
    CREATE TABLE dl_category (
      category_id int(11) NOT NULL auto_increment,
      category_title varchar(100) default NULL,
      category_url  varchar(100) default NULL,
      category_description varchar(100) default NULL,
      PRIMARY KEY  (category_id)
    )
    I exec. this through phpMyAdmin as a query and it worked ok, successfull return. Then I manually added one row.
    category_id = 1 (or should the first one be 0?)
    category_title = codecs
    category_url = http://theurl.we/need/for.download.html
    category_desciption = blah blah codecs blah blah
    with an insert into .. query. and that was successful too.
    When I make a quick list.php file which gets all the rows from the table and lists them, it is able to get this one, so that all works.

    Ok, here we go: So what do I do now to get a add.php page which lets me add another row to the table?

    add.php
    PHP Code:
    <?php
    require("admin/conf.php");

    if (
    $submit == "click"){

      
    $query "insert into dl_category values ('', '$title', '$url', '$description')";
      
    $result mysql_db_query ("baz"$query); // is baz here the name of my database where the table dl_category is in, and if so, is this correct code?
      
    if ($result){
        echo 
    "Added!";
      }
      else{
        echo 
    mysql_errno().": ".mysql_error()."<BR>";
      }

      
    mysql_close ();
    }
    else{
      echo 
    "
        <html><body>

        <form method=\"post\" action=\"add.php\">

        Enter a new category title: 
        <input type=\"text\" name=\"title\"><br>
        Enter the url: 
        <input type=\"text\" name=\"url\"><br>
        Enter the description:
        <input type=\"text\" name=\"description\"><br>

        <input type=\"submit\" name=\"submit\" value=\"click\">

        </form>

        </body></html>
      "
    ;
    }

    ?>
    Obviously the above code is not correct, otherwise I wouldn't be asking here.

    I do hope someone is able and willing to help me get this figured out properly, and maybe then I can just do the rest on my own.

    The page seems to work, and it might actually tries to insert the input stuff, but I get this error: 1136: Column count doesn't match value count at row 1 which might mean that I need to include category_id too when I insert? But how do I do that, if it auto increm. ?

    AH STUPID ME
    I just found it,
    the above code WORKS - fixed it myself.
    for auto increament, just leave empty ('', ..other values)
    I overlooked that, so stupid, MOO.

    I no longer need help with this problem! Sorry!
    Last edited by Floris; Thu 13 Jun '02, 10:53am.
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...
X