Squeeze some time to write a blog-php&mysql practice

Source: Internet
Author: User
Tags php and mysql

Hi

In the evening to eat hot pot, squeeze a little time to write something, don't be found by the boss OH

1. PHP and MySQL

Article release system behind the table

5.2 Creating configuration files and initialization files

For unified configuration and ease of administration, there is also a reduction in code redundancy.

Config.php and connect.php, respectively.

config.php

<?php
/*
* Configuration file
*/
Information about the configuration database
Since it is a constant, it is used directly with define
Define (' HOST ', ' 127.0.0.1 ');
Define (' USERNAME ', ' root ');
Define (' PASSWORD ', ');

connect.php

<?php
/*
* Files linked to the database
* Mainly link to the database server and select the database.
* Special is to set character sets.
* Then want to judge each operation
*/

Include Configuration files
Require_once ' config.php ';

Even library
if (! $con =mysqli_connect (Host,username,password)) {
echo Mysqli_error ($con);
}

Select Library
if (mysqli_select_db ($con, ' info ')) {
echo Mysqli_error ($con);
}

Character
if (Mysqli_query ($con, ' Set names UTF8 ')) {
echo Mysqli_error ($con);
}

After the completion of testing the link file is OK. Mysqli and MySQL are ok here, as long as the format is correct.

5.3 Publishing Articles

Article Publishing Interface article.add.php

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Untitled Document </title>
<style type= "Text/css" >
Body {
margin-left:0px;
margin-top:0px;
margin-right:0px;
margin-bottom:0px;
}
</style>

<body>
<table width= "100%" height= "520" border= "0" cellpadding= "8" cellspacing= "1" bgcolor= "#000000" >
<tr>
&LT;TD height= "colspan=" 2 "bgcolor=" #FFFF99 "><strong> admin system </strong></td>
</tr>
<tr>
&LT;TD width= "156" height= "287" align= "left" valign= "Top" bgcolor= "#FFFF99" ><p><a href= "article.add.php" > Publish Articles </a></p>
<p><a href= "article.manage.php" > Administration articles </a></p> <a href= "article.add.php" ></a> </td>
&LT;TD width= "837" valign= "Top" bgcolor= "#FFFFFF" >
<form id= "Form1" Name= "Form1" method= "Post" action= "article.add.handle.php" >
<table width= "779" border= "0" cellpadding= "8" cellspacing= "1" >
<tr>
&LT;TD colspan= "2" align= "center" > Publish Articles </td>
</tr>
<tr>
&LT;TD width= "119" > title </td>
&LT;TD width= "625" ><label for= "title" ></label>
<input type= "text" name= "title" id= "title"/></td>
</tr>
<tr>
<td> author </td>
<td><input type= "text" name= "author" id= "author"/></td>
</tr>
<tr>
<td> Introduction </td>
<td><label for= "description" ></label>
<textarea name= "description" id= "description" cols= "rows=" 5 "></textarea></td>
</tr>
<tr>
<td> content </td>
<td><textarea name= "Content" cols= "rows=" id= "content" ></textarea></td>
</tr>
<tr>
&LT;TD colspan= "2" align= "right" ><input type= "Submit" name= "button" id= "button" value= "Commit"/></td>
</tr>
</table>
</form></td>
</tr>
<tr>
&LT;TD colspan= "2" bgcolor= "#FFFF99" ><strong> All rights reserved </strong></td>
</tr>
</table>
</body>

It's not so beautiful, it's learning.

Article release Handler article.add.handle.php

<?php
Require_once ('.. /connect.php ');
Put the information passed over to the storage, before the storage of all the information to verify.
if (! ( Isset ($_post[' title ') && (!empty ($_post[' title ')))) {
echo "<script>alert (' title cannot be empty '); window.location.href= ' article.add.php ';</script>";
}
$title = $_post[' title '];
$author = $_post[' author ');
$description = $_post[' description ');
$content = $_post[' content '];
$dateline = time ();
$insertsql = "INSERT into article (title, author, description, content, Dateline) VALUES (' $title ', ' $author ', ' $descriptio n ', ' $content ', $dateline) ";
if (Mysqli_query ($con, $insertsql)) {
echo "<script>alert (' published article success '); window.location.href= ' article.manage.php ';</script>";
}else{
echo "<script>alert (' Publish failed '); window.location.href= ' article.manage.php ';</script>";
}
?>

Note the function and connection of the two, that is, the add page to pass things to handle processing

------------------------

Because I have encountered the previous not seen the garbled problem ... On my knees to solve the problem .... Hope everyone wamp Environment, Mysql,zend, browser has been set to Utf8,apache configuration file added Adddefaultcharset UTF-8, the problem still exists, I faint ah .... )

Squeeze some time to write a blog-php&mysql practice

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.