Friday, May 15, 2009

Updating database in mysql using php

$Userid = $_POST['User_id'];
$Username = $_POST['User_name'];
$Userpassword = $_POST['User_password'];

mysql_connect("localhost","root","") or die ('Error: ' . mysql_error());
mysql_select_db("it");

$query = "UPDATE users SET User_id='".$Userid."', User_name='".$Username."', User_password='".$Userpassword."' WHERE User_id='".$Userid."'";

mysql_query($query) or die ('Error updating user');

echo "User updated with: " .$Userid. " " .$Username. " " .$Userpassword;


?>

Wednesday, May 13, 2009

Retrieving data from the database and printing it on the screen

mysql_connect("localhost","root","") or die ('Error: ' . mysql_error());
mysql_select_db("it");

$query = "SELECT * FROM users";
$data = mysql_query($query) or die ('Error displaying data');

while($info = mysql_fetch_array($data))
{
print "Id:" .$info['User_id'] . " ";
print "Name:" .$info['User_name']. " ";
print "Password:" .$info['User_password']. "
";

}

Inserting data into mysql database using php



$Userid = $_POST['User_id']; //this is the column of table users
$Username = $_POST['User_name']; //
$Userpassword = $_POST['User_password']; //

mysql_connect("localhost","root","") or die ('Error: ' . mysql_error());
mysql_select_db("it");

$query = "INSERT INTO users (User_id,User_name,User_password) VALUES ('".$Userid."','".$Username."','".$Userpassword."')";

mysql_query($query) or die ('Error creating users');

echo "User Created With: " .$Userid. " " .$Username. " ".$Userpassword;

?>