Post Reply 
 
Thread Rating:
  • 1 Votes - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP-MYSQL Simple Database Connection
05-19-2009, 07:08 PM
Post: #1
PHP-MYSQL Simple Database Connection
PHP Code:
<?php

mysql_connect 
("localhost","user","password") or die (mysql_error());

mysql_select_db("databasename");

?>

My Main Site
My Forum
Visit this user's website Find all posts by this user
Quote this message in a reply
03-05-2010, 09:02 PM
Post: #2
RE: PHP-MYSQL Simple Database Connection
You had only describe how to connect the Database. I think we should also give some more information for inserting data in the table.

<html>
<head>
<title>Add New MySQL User</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
if(isset($_POST['add']))
{
include 'library/config.php';
include 'library/opendb.php';

$username = $_POST['username'];
$password = $_POST['password'];

$query = "INSERT INTO user (host, user, password, select_priv, insert_priv, update_ priv) VALUES ('localhost', '$username', PASSWORD('$password'), 'Y', 'Y', 'Y')";
mysql_query($query) or die('Error, insert query failed');

$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, insert query failed');

include 'library/closedb.php';
echo "New MySQL user added";
}
else
{
?>
<form method="post">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Username</td>
<td><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td width="100">Password</td>
<td><input name="password" type="text" id="password"></td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td><input name="add" type="submit" id="add" value="Add New User"></td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
<style type="text/css"> .style1 { width: 615px; } .style2 { text-align: right; width: 85px; } </style>

Web Design Kent
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: