Warning: include(Assets/scripts/breadcrumbgen.php) [function.include]: failed to open stream: No such file or directory in /home/cleancar/public_html/index.php on line 4
Warning: include(Assets/scripts/breadcrumbgen.php) [function.include]: failed to open stream: No such file or directory in /home/cleancar/public_html/index.php on line 4
Warning: include() [function.include]: Failed opening 'Assets/scripts/breadcrumbgen.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/cleancar/public_html/index.php on line 4
CREATE TABLE messages (
id int unsigned not null auto_increment primary key,
name varchar(255),
email varchar(255),
message mediumtext
);
This creates a table with four columns:
php code for a feedback form tosave to database
<?php
if (isset($_REQUEST['submit'])) {
mysql_connect('localhost','myuser','mypassword');
mysql_select_db('mydb');
mysql_query("INSERT INTO messages (name,email,message) VALUES ('" .
$_REQUEST['name'] ."','" . $_REQUEST['email'] . "','" .
$_REQUEST['message'] . "')");
print "Thank you for the feedback.";
} else {
print<<<_HTML_
<form method="POST" action="$_SERVER[PHP_SELF]">
<table>
<tr><td>Name:</td><td><input type="text" name="name"></td></tr>
<tr><td>Email:</td><td><input type="text" name="email"></td></tr>
<tr><td>Message:</td><td><textarea name="message"></textarea></td></tr>
<tr><td colspan="2"><input name="submit" type="submit"></td></tr>
</form>
_HTML_;
}
?>
Connect to database by running the mysql command-line utility with the database, username, and password you created earlier:
% mysql mydb -umyuser -pmypassword
general connection string in php code:
$dbh=mysql_connect ("localhost", "username", "<password>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("databasename");
Preferred method:
<?php // database access parameters file dbparams.php $host = 'localhost'; $user = 'username'; $pass = 'password'; ?>
<?php require_once('dbparams.php'); ?> or <? include('dbaccess.php'); ?>
$dbc = mysql_connect ($host, $user, $pass) or die ("unable to connect to database because: " . mysql_error() ) ;
$db = "databasename" ;
mysql_select_db ($db,$dbc) or die ("unable open $db because: ". mysql_error() ) ;