PHP Learning Connection Database Micro Blog

Source: Internet
Author: User

First Step: Database connection

<php    // CREATE database connection    error_reporting(e_all & ~e_ DEPRECATED);    @mysql_connectdie ("Database connection error"); // Connect database address user name password   @mysql_select_dbdie ("DB connection Failed"); // Connection Library   mysql_query ("Set names ' GBK '"); // Code ?>

The second part interacts with the database

A, in the database interaction we need to be divided into front-end and back-end. The front end is used for the user's presentation. Back end for database invocation

First write the front-end display code as follows:

1 <formAction= "add.php"Method= "POST">2Title<inputtype= "text"name= "title"><BR>3Content<textareaRow= "5"cols= " the"name= "Con"></textarea><BR><!--TextArea is a multi-line input row for showing that you can display a few lines cols for setting width--4         <inputtype= "Submit"name= "Sub"value= "Submit"><!--Submit button --5 </form>

HTML code Explanation

<!--textarea is a multi-line input row for showing that you can display a few lines cols for setting width--

B, the front-end display completed the front-end input to make a judgment is not empty. And the database to do the backstage handover, like we insert the data

1<?PHP2     include(' conn.php ');3     if(!Empty($_post[Sub])) {//Empty to determine if NULL!empty indicates NOT NULL4         $title=$_post[' title '];5         $con=$_post[' Con '];6         $sql= "INSERT into ' news ' (' id ', ' title ', ' dates ', ' contents ') VALUES (null, '$title', now (), '$con‘)";//mysql statement, inserting data7         $ret=mysql_query($sql);8         Echo"Insert Succeeded"Ten     } A?>

PHP Learning Connection Database Micro Blog

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.