SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: PHP updates

  1. #1
    SitePoint Addict
    Join Date
    Dec 2001
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP updates

    Alright I decided that I'm going to build my whole site in php so all of our partners can update the site without all the weight on my shoulders. What I want to do is name all the different sections on my site and be able to update them. Such as title, news, tournament, etc... but I want to be able to update one thing at a time without screwing up the rest of the page. So I'm going to use a table named joe and user name lou and password mike (made up of course) then I would enter whats on the homepage in the database for now. I was going to put all the code on one page for each type of page so that all the items I can change for the homepage will be in one spot. I know how to set up the table and connect to the table im using but I dont know the rest. If I make just one submit button and only update one field then leaving the rest blank it will only update the one field I want leaving the rest blank. Isnt there a way where I can fix this? Also for the submit button how do I link it to the database to change the data? Also I have a page with 30 golf courses all in a table. Im going to make a courses.php page where it will just enter all the info from the table into the template. But how do I link to that one course? I used an ID for each item and am not sure how to get the correct course info to appear. Can someone please help me?

    You can see the form I made so far at http://www.easterngolflinks.com/uhome.html
    Last edited by Rockwilda; Jul 17, 2002 at 15:52.

  2. #2
    SitePoint Addict
    Join Date
    Dec 2001
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guys I'm asking how I can edit a table in my database from a form that goes through a PHP file. I have the table set up with all the info in it. Anyone help me?

  3. #3
    SitePoint Addict
    Join Date
    Dec 2001
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Come on guys, no answers for me?

  4. #4
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you know how to SELECT information from your database?
    PHP Code:
    <?php
    // Connect to the Database
    $Query=mysql_query("SELECT * FROM joe WHERE id=1");
    ?>
    Then, print all of that information to a form:
    PHP Code:
    <?php
    $Result
    =mysql_fetch_assoc($Query);
    ?>
    // HTML Form coding here
    <input type="text" name="ititle1" value="<?php echo($Result['title']); ?>" />
    That way, when you go to the page, all of the information is places in the forms. Use the same methods for textarea and other form types.

    Once you edit your information, use your form submittal (sending it to whatever.php), and on whatever.php, have something like:
    PHP Code:
    <?php
    // If the form data was submitted
    if(isset($_POST['submit'])){
         
    mysql_query("UPDATE joe SET title='{$_POST['ititle1']}', tourhead='{$_POST['itourhead']}' ... WHERE id=1")
              or exit(
    'An error was encountered: '.mysql_error());
    }
    ?>
    Does that make sense? You'll probably want to place the ID of the row you're editing into a hidden form field so that when you submit the data the correct row in your database is updated.

    If you need any more help let me know; this is more of a rough outline as to how to do it rather than a step by step guide.

    -Colin
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you start with some tutorials first?

    Start with MySQL. Get a RDBMS like dbTools (www.dbtools.com.br) and connect up. Create some tables for testing and use the Query Editor to handtype some SQL queries. If you can't get this to work, this site below has a live SQL Query tool you can use...

    http://www.sqlcourse.com/

    Once you've got a decent grasp on SQL, try sticking it into some PHP pages.

    Tutorial:
    http://hotwired.lycos.com/webmonkey/99/21/index2a_page4
    Or, download the first 4 chapters of the book available for sale on this site
    http://sitepoint.com/books/?bookid=PHPMSQL
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  6. #6
    SitePoint Addict
    Join Date
    Dec 2001
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aes:
    Thank you very much for your help. Let me make sure that I understand what you are saying. First off I need to make a table and make just one ID entry. Placing all of the different sections of my homepage under one ID. Then I use the second code to automatically fill in the forms with the current information. Then I make any changes that I want to the current forms and submit back to my mysql database to update it. Is this right?

    Also I made a table with 30 or so golf courses each having their own ID #. How do I set up a link to a course. Im going to make them all link to courses.php which will fill in all the information but I am confused what to put as the html code for the link. For example, ID 1 would be Joes Golf Course. How would I make a link to have all the information fill into courses.php with Joes information?

    Once again thank you very much for all you help. Beetle I went to the webmonkey site and printed all 3 lessons so I can read them at work. Also I read the sitepoint chapters before and I am ready a book on PHP and MySQL and find it easier to learn by example. Thank you guys.

  7. #7
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes; the things I typed were just rough examples of how to do it, but you pretty much have it correct.

    Generally, ALWAYS always always assign a unique identifier to your database tables. I typically assign this column as id INT NOT NULL PRIMARY KEY auto_increment. Then, all of the data in that particular row is associated with that ID. So, in your tables, as long as you have unique ID's for the data, you can do anything!

    As for your golf courses and links, I would do something like:
    PHP Code:
    <?php
    // Connect to the database
    // Run the query
    $Query=mysql_query("SELECT * FROM joe ORDER BY id");
    // Loop through all of the results And display links to courses.php
    // With the id defined.  This way the appropriate information for
    // Each course is pulled according to the id in each link.
    while($Result=mysql_fetch_assoc($Query)){
         echo(
    "<a href=\"courses.php?id={$Result['id']}\">{$Result['name']}</a>");
    }
    ?>
    Then, on courses.php, you would simply have a script that would take that ID in the url, and pull the course information from the database that has the ID specified. So something like this would be in order:
    PHP Code:
    <?php
    // Connect to the database
    // Retrieve information according to the ID in the url
    $Query=mysql_query("SELECT * FROM joe WHERE id={$_GET['id']}");
    // Then, just echo that out onto the page.
    ?>


    -Colin
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.


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
  •