« Home « Kết quả tìm kiếm

Create dynamic sites with PHP & MySQL


Tóm tắt Xem thử

- gunzip -dc php-x.x.xx.tar.gz | tar xv.
- cd php-x.x.xx.
- cp php.ini-dist /usr/local/lib/php.ini.
- And for PHP 4.x, use:.
- #AddType application/x-httpd-php .php.
- AddType application/x-httpd-php .php .phtml AddType application/x-httpd-php-source .phps.
- Type the following code in a text editor and save it as test.php in a directory accessible by your Web server:.
- echo "Hello World";.
- Save the file as first.php and view it in the browser (remember to set the permission to chmod 775 first).
- Save the following text as viewdb.php:.
- echo "<TABLE>";.
- echo"<TR><TD><B>Full Name</B><TD><B>Nick Name</B><TD><B>Salary</B></TR>";.
- echo "<TR><TD>";.
- echo ".
- echo "<TD>";.
- echo "</TABLE>";.
- action="datain.php">.
- name="first"><br>.
- name="last"><br>.
- name="nickname"><br>.
- name="email"><br>.
- name="salary"><br>.
- value="Enter information">.
- Now we have a form that will post the information to a page "datain.php".
- The following listing of datain.php will do that:.
- echo "Thank you! Information entered.\n";.
- We will call it input.php.
- action="input.php">.
- value="Enter information"></form>.
- viewdb.php..
- in our script input.php.
- http://yourhost/input.php?first=Rick&last=Denver&nickname=Mike&[email protected]&salary=25000&submit=Enter+information Look closely.
- Save the following code as view.php.
- Try viewing it through your Web server as http://yourhost/view.php?id=2 (here we have passed the variable.
- echo "First Name: ".$myrow["firstname"];.
- echo "<br>Last Name: ".$myrow["lastname"];.
- echo "<br>Nick Name: ".$myrow["nick"];.
- echo "<br>Email address: ".$myrow["email"];.
- echo "<br>Salary: ".$myrow["salary"];.
- We immediately modify our previous viewdb.php to viewdb2.php so that it can call view.php with the proper query string..
- echo "<TABLE BORDER=2>";.
- echo"<TR><TD><B>Full Name</B><TD><B>Nick Name</B><TD><B>Options</B></TR>";.
- echo "<TR><TD>".$myrow["firstname"].".
- ".$myrow["lastname lt;TD>".$myrow["nick"];.
- echo "<TD><a href=\"view.php?id=".$myrow[id gt;View</a>";.
- The link should be something like http://yourhost/view.php?id=3 and the links in each row will be different.
- It will bring up our previously coded view.php showing the detailed information of that person.
- Let's take a look at our code viewdb2.php.
- is a concatenating operator in PHP, which means it concatenates the two strings on its two sides, which in turn means that if we write echo "Hello"."World", the output will actually be.
- <TR><TD>Camilla Anderson<TD>Rose<TD><a href="view.php?id=2">View</a>.
- Where's the fun if we can't trash some of those data, at least the useless ones? Our delete.php will do just that.
- It works exactly like view.php.
- echo "Information Deleted";.
- Once again we modify our previous viewdb2.php script to viewdb3.php to add this new feature.
- echo "<TR><TD>".$myrow["firstname .
- ".$myrow["nick"];.
- echo "<TD><a href=\"view.php?id=".$myrow[id gt;View</a>.
- echo "<a href=\"delete.php?id=".$myrow[id gt;Delete</a>";.
- Try clicking on delete and then view the database again with viewdb3.php to verify that the row was really deleted.
- For this we will modify our previously coded input.php file.
- addedit.php:.
- echo "Thank you! Information updated.\n";.
- action="<?php echo $PHP_SELF?>">.
- name="id".
- value="<?php echo $myrow["id"]?>">.
- value="<?php echo.
- value="<?php echo $myrow["lastname"]?>"><br>.
- value="<?php echo $myrow["nick"]?>"><br>.
- value="<?php echo $myrow["email"]?>"><br>.
- value="<?php echo $myrow["salary"]?>"><br>.
- value="Update information"></form>.
- Hmmm...the code looks quite complex.
- Previously input.php had two features:.
- Verify whether the database is updated by viewing the database with viewdb3.php..
- Here's the listing for viewdb4.php:.
- ".$myrow["lastname lt;/a><TD>".$myrow["nick"];.
- echo "<a href=\"delete.php?id=".$myrow[id gt;Delete</a>.
- echo "<a href=\"addedit.php?id=".$myrow[id gt;Edit</a>";.
- echo "<TD><a href=\"view.php?id=".$myrow["id gt;View</a>";.
- action="<?php $PHP_SELF ?>">.
- <tr><td>Insert you search string here</td>.
- <td>Search type</td></tr>.
- <td><input type="text".
- size gt;</td>.
- <td><select size="1".
- name="searchtype">.
- <option value="lastname">Last Name</option>.
- <option value="nick">Nick Name</option>.
- </select></td>.
- <p><input type="submit".
- name="B1"><input type="reset".
- ></p>.
- The part of code that searches is similar to our viewdb2.php.
- echo "Latest News:<br>";.
- echo "<a /a><br>";

Xem thử không khả dụng, vui lòng xem tại trang nguồn
hoặc xem Tóm tắt