You are here: PHP insert « PHP Programming Language « IT news, forums, messages
PHP insert

Posted by Bonzol on 10/20/06 17:55

Hello, PHP n00b here.

Using SQL just working off some examples, I have no problem selecting
data, but I cant seem to be able to insert. If someone could see where
im going wrong


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Database Connection</title>
</head>
<body>
<?php
#Server Name - e.g. localhost:3309
$dbserver = 'localhost';
#Username used to log into MySQL database server.
$dbusername = '';
#Password used to log into MySQL database server.
$dbpassword = '';
#Error message shown if an error whilst attempt to establish a
connection with the server.
$dberrormessage = '<strong>Error connecting to database...</strong>';
#Name of database on server.
$dbdatabase = 'bonzollibrary';
#Establish Connection
@$conn = mysql_connect($dbserver, $dbusername, $dbpassword) or exit
($dberrormessage);
#Selects which database is to be used on server.
mysql_select_db($dbdatabase);
?>
<h1>Sample Database Connection</h1>

<form action="db-conn2.php" method="get">
<input type="text" id="name" name="name" />&nbsp;
<input type="submit" value="Search" />
</form>

<?php if(isset($_REQUEST['name']))
{ ?>
<table border="1">
<tr>
<th>Number</th>

</tr>
"Insert into tbl_category (cat_description)
Values ('%{$_REQUEST['name']}%')


<?php $query = "Insert into tbl_category (cat_description) Values
('%{$_REQUEST['name']}%')";
@$result = mysql_query($query) or exit('<strong>An error has
occured while connecting to the database. The following query is

not valid: \''.$query.'\'.</strong>');
}?>
</table>
<?php
#Check if connection is still open
if($conn)
{
#Close the connection
mysql_close($conn);
}
?>
</body>
</html>


Thanx in advance

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация