Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Senior Member
    Join Date
    Oct 2007
    Posts
    241
    Member #
    15910
    I am just starting my first database and php programming. I will have a database to store news articles and a website that will display the news on various pages in different legths (one page just the title and first sentence, another only title, another full text). The table sturcture is basically news id, date, title, paragraph 1, parag2, ....contact info1, picture 1, spare column1 etc....(and no, I am not planning to use joomla, drupal wordpress etc...)
    1) To update this database, what is the most eficient way - to use a form that I should create with php or using myphpadmin that I have in my webhost's database control panel? Because I will enter the same type of info every time so instead of using mysql commands wouldnt it be easier if I use a form that updates the database?
    2) If a web form is better, is there a sample script you guys can send / suggest?
    3) Again, if a form is better, where should this form be located exactly? Under my website folder or where? If this php form is located on the web how do you prevent others who gets to this website to edit database?

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,659
    Member #
    5580
    Liked
    713 times
    There are many tutorials about this.

    You are correct in using a form.

    Here is one tutorial I found ... seems easy to understand:
    http://teamtutorials.com/web-develop...base-using-php

    =========

    For now, you could display the form page as normal, but eventually, you'll want to
    only display that form if a PHP session is set (with a password). You don't want
    just anyone updating your database.

    Here's the Google search with more tutorials:
    http://teamtutorials.com/web-develop...base-using-php

    =========

    There is also issues about "MySQL injection" ... a security issue about injecting
    code into a database. See if any of those tutorials mention that too.


  4. #3
    Senior Member
    Join Date
    Oct 2007
    Posts
    241
    Member #
    15910
    I looked at the tutorials and found that it is giving a complete informational guide, from updating database to displaying results, thanks. I will look at it further, if the one below does not work, which I found before and was trying to make work:...

    1-In the program below what does $yourfield refer to?

    2-Isn't this supposed to display the contents of my table? It is not displaying anything, not an error message, nothing, just blank screen - I created table, databse host name password are all correct, and I already inserted a test row to my table.


    <?php
    //Connect To Database
    $hostname='. ......... ....';
    $username='. ......... ....';
    $password='. ......... .......';
    $dbname='... ........' ;
    $usertable=' ......... ....';
    $yourfield = '........... ..';
    mysql_connect( $hostname, $username, $password) OR DIE ('Unable to connect to database! Please try again later.');
    mysql_select_ db($dbname) ;
    $query = 'SELECT * FROM $usertable';
    $result = mysql_query( $query);
    if($result) {
    while($row = mysql_fetch_ array($result) ){
    $name = $row['$yourfield' ];
    echo 'Name: '.$name;
    }
    }
    ?>

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,659
    Member #
    5580
    Liked
    713 times
    It will only display something if this line is true: if($result){

    So, I would guess that $usertable needs to be defined as
    a name of a table that you actually have.

    And then, $yourfield is the name of one of the fields in that table.

    You can show us all of your actual code, except you should wipe-out these 3 lines:
    $hostname='. ......... ....';
    $username='. ......... ....';
    $password='. ......... .......';

    But the rest of your code you can post here.



Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:38 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com