Database TestDB, table user column email and nikename
HTML code:
<form method= "POST" action= "search1.php" name= "search" > <input name= "Search" type= "text" value= "" size= " > <input type= "Submit" value= "Search" > </form> the following adds:...</p> to the database <div> <form action= "insert.php" method= "POST" >nikename: <input type= "text" name= "Nikename"/>email: <input Type= "text" name= "email"/><input type= "Submit"/></form></div>
search1.php Code:
<?php$con = mysql_connect ("localhost", "root", "root"), if (! $con) {die (' Could not connect: '. Mysql_error () ); } mysql_select_db ("TestDB", $con); $searchs = $_post[' search ']; The value passed in the search box $searchs = Trim ($searchs); the IF (! $searchs) {echo ' search box cannot be empty. '; Exit;} $result = mysql_query ("SELECT * from user where nikename like '% $searchs% '"); if (Mysql_num_rows ($result) < 1) echo ' No number According to '; while ($row = Mysql_fetch_array ($result)) { echo $row [' Nikename ']. " " . $row [' email ']; echo "<br/>"; } Mysql_close ($con);? >
The insert.php code is as follows:
<?php$con = mysql_connect ("localhost", "root", "root"), if (! $con) {die (' Could not connect: '. Mysql_error () ); } mysql_select_db ("TestDB", $con); $nikename =$_post[' nikename ']; Create short variable names$email=$_post[' email ']; $nikename = Trim ($nikename); if (! $nikename | |! $email)//determine if NULL {echo ' cannot be empty '; exit;} $sql = "INSERT into user (nikename, email) VALUES (' $nikename ', ' $emai L ') "; if (!mysql_query ($sql, $con)) {die (' Error: '. mysql_error ()); } echo "1 record added"; Mysql_close ($con)?>
PHP simple implementation of MySQL data search, add data functions