PHP
  Home arrow PHP arrow Page 8 - PHP 101 (part 4) - Look, Ma...It's Ali...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

PHP 101 (part 4) - Look, Ma...It's Alive!
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 4
    2000-09-01

    Table of Contents:
  • PHP 101 (part 4) - Look, Ma...It's Alive!
  • Dumped!
  • Hello Database!
  • Different Strokes...
  • ...For Different Folks
  • What's In A Name?
  • New Friends
  • Today's Special
  • Nuking The People
  • Oops!

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    PHP 101 (part 4) - Look, Ma...It's Alive! - Today's Special


    (Page 8 of 10 )

    You should also give your users the option of updating their list of preferred Web sites - in SQL, this is accomplished via an UPDATE statement. The example below asks for a user name and then displays the list of URLs which can be edited - this list is obtained from the database.

    Once you submit the form with your modifications, another PHP script, "modify.php4", is called; this script is responsible for generating the UPDATE query and modifying the items in the database.

    [list.php4]

    <?php // this script checks the username and then displays the URLs // for the user as editable text boxes // check if the form has been submitted if($submit) { // initialize database connection $conn = mysql_connect("localhost", "test", "test"); mysql_select_db("php101", $conn); $result = mysql_query("select title1,url1,title2,url2,title3,url3 from url_list where uid = '$username'", $conn); // check if the user name is valid $num_rows = mysql_num_rows($result); // if no rows are returned then the username is invalid if(!$num_rows) { ?> <html> <head> <basefont face="Arial"> </head> <body> <center> <font size="3">User name not found!</font><br> <a href="list.php4">Click here to try again.</a> </center> </body> </html> <?php } else { // else if user name is valid // display list $result = mysql_query("select title1,url1,title2,url2,title3,url3 from url_list where uid = '$username'", $conn); list($title1,$url1,$title2,$url2,$title3,$url3) = mysql_fetch_row($result); ?> <html> <head> <basefont face="Arial"> </head> <body> <center> <font size="3">Welcome, <?php echo $username; ?>!</font><br> Select the sites you'd like to modify: <p> <form action="modify.php4" method="post"> <table border=1> <tr> <td> <input type=text name=title1 value="<? echo $title1; ?>"> </td> <td> <input type=text name=url1 value="<? echo $url1; ?>"> </td> </tr> <tr> <td> <input type=text name=title2 value="<? echo $title2; ?>"> </td> <td> <input type=text name=url2 value="<? echo $url2; ?>"> </td> </tr> <tr> <td> <input type=text name=title3 value="<? echo $title3; ?>"> </td> <td> <input type=text name=url3 value="<? echo $url3; ?>"> </td> </tr> <tr> <td colspan=3 align=center> <input type=submit value="Modify!"> </td> </tr> </table> <input type=hidden name=username value="<? echo $username; ?>"> </form> </center> </body> </html> <?php mysql_free_result($result); } } else { // $submit not found // so display a form ?> <html> <head> <basefont face="Arial"> </head> <body> <form action="list.php4" method="POST"> <table> <tr> <td> Username: </td> <td> <input type="text" name="username" length=10 maxlength="30"> </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" name="submit" value="Log in"> </td> </tr> </table> </form> </body> </html> <?php } ?>
    [modify.php4]

    <?php // this script takes all the information from list.php4 // and updates the database // connect $connection = mysql_connect("localhost", "test", "test") or die("Invalid server or user"); // select database mysql_select_db("php101",$connection) or die("Invalid database"); // generate query $query = "update url_list set title1 = '$title1', url1 = '$url1', title2 = '$title2', url2 = '$url2', title3 = '$title3', url3 = '$url3' where uid = '$username'"; $result = mysql_query($query,$connection) or die("Error in query"); ?> <html> <head> <basefont face=Arial> </head> <body> <?php if($result) { echo "<center><h3>Success!</h3><p>$username's bookmarks have been modified.</center>"; } ?> </body> </html>

    More PHP Articles
    More By Vikram Vaswani and Harish Kamath, (c) Melonfire


     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT