Tag Archives: SQL

use php process a web form feedback–continue

since you got a form collect your information , so now you need create a database

here it is , you could save this as inc_connect.php

$db_name = “chinese_zodiac_database”;
$DBConnect = mysql_connect(“severname”,”usename”,”password”);
if (!$DBConnect)
echo “<p>unable to connect to the database server “.mysql_error().”</p>”;
$db = mysql_select_db($db_name);
echo “<p>unable to connect to the database server “.mysql_error().”</p>”;
$DBConnect = false;





some useful function php with mysql

  • mysql_connect(‘servers’,’admin’,’password’)
  • mysql_select_db(‘name of databases’)
  • mysql_query(‘sql querys’)
  • mysql_num_row(‘my sql query result’)
  • mysql_affected_row() and mysql_info() return information on the records that were affected by an insert,update,or delete query.
  • mysql_fetch_array()
  • mysql_fetch_assoc()
  • mysql_fetch_row()
  • mysql_fetch_lengths()
  • mysql_free_result() This ensures that the resultset doesn’t keep taking up space in your Web server’s memory.
  • You can only use the mysql_free_result() function with SQL statements that return results,such as SELECT queries,and only when the SQL statement successfully returned results. If you attempt to use the mysql_free_result() function with SQL statements that do not return results, such as the CREATE DATABASE and CREATE TABLE statements, or on an empty resultset, you will receive an error.

use php and mysql create a page need user name and password

so ,you already set up your databases(in your databases already  had member), there add more then your could let your member log in.

after the form the follow codes use this instead

} else {
// connect to mysql
$mysql = mysqli_connect(“localhost”, “webauth”, “webauth”);
if(!$mysql) {
echo “Cannot connect to database.”;
// select the appropriate database
$selected = mysqli_select_db($mysql, “auth”);
if(!$selected) {
echo “Cannot select database.”;

// query the database to see if there is a record which matches
$query = “select count(*) from authorized_users where
name = ‘”.$name.”‘ and
password = sha1(‘”.$password.”‘)”;

$result = mysqli_query($mysql, $query);
if(!$result) {
echo “Cannot run query.”;
$row = mysqli_fetch_row($result);
$count = $row[0];

if ($count > 0) {
// visitor’s name and password combination are correct
echo “<h1>Here it is!</h1>
<p>I bet you are glad you can see this secret page.</p>”;
} else {
// visitor’s name and password combination are not correct
echo “<h1>Go Away!</h1>
<p>You are not authorized to use this resource.</p>”;