Tag Archives: MySQL

Retrieving Data With PHP & MySQL(while loop)

<?php
mysql_connect(“localhost”, “admin”, “password”) or die(mysql_error());
mysql_select_db(“test”) or die(mysql_error());

// Retrieve all the data from the “example” table
$result = mysql_query(“select * from example”) or die(mysql_error());

//store the record of the “example” table into $row

//Print out the contents of the entry
echo “<table border=’1′>”;
echo “<tr><th>Name</th><th>Age</th></tr>”;
while($row = mysql_fetch_array($result))
{
echo “<tr><td>”.$row[‘name’].”</td><td>”.$row[‘age’];
echo “</td></tr>”;
}
echo “</table>”;
?>

Advertisements

insert data into your working databases

<?php
mysql_connect(“localhost”, “admin”, “password”) or die(mysql_error());
mysql_select_db(“test”) or die(mysql_error());

mysql_query(“insert into example(name,age) values(‘Timmy Smith’,’23’)”) or die(mysql_error());
mysql_query(“insert into example(name,age) values(‘Rachel Wang’,’23’)”) or die(mysql_error());
mysql_query(“insert into example(name,age) values(‘Timmy wallace’,’23’)”) or die(mysql_error());

echo “Data Inserted!”;
?>

use session create member log in wih mysql–continue

then you should create your logout.php

here is the code:

<?php
  session_start();
 
  // store to test if they *were* logged in
  $old_user = $_SESSION[‘valid_user’];  
  unset($_SESSION[‘valid_user’]);
  session_destroy();
?>
<html>
<body>
<h1>Log out</h1>
<?php
  if (!empty($old_user))
  {
    echo ‘Logged out.<br />’;
  }
  else
  {
    // if they weren’t logged in but came to this page somehow
    echo ‘You were not logged in, and so have not been logged out.<br />’;
  }
?>
<a href=”authmain.php”>Back to main page</a>
</body>
</html>

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

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

// 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.”;
exit;
}
$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>”;
}
}
?>