Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- PHP insert
October 20, 2006, 5:55 pm
rate this thread
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"
<html xmlns="http://www.w3.org/1999/xhtml ">
#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';
@$conn = mysql_connect($dbserver, $dbusername, $dbpassword) or exit
#Selects which database is to be used on server.
<h1>Sample Database Connection</h1>
<form action="db-conn2.php" method="get">
<input type="text" id="name" name="name" />
<input type="submit" value="Search" />
"Insert into tbl_category (cat_description)
<?php $query = "Insert into tbl_category (cat_description) Values
@$result = mysql_query($query) or exit('<strong>An error has
occured while connecting to the database. The following query is
not valid: ''.$query.''.</strong>');
#Check if connection is still open
#Close the connection
Thanx in advance
Re: PHP insert
Problem is that you use single quoutes twice ;-) Try this
$name = $_REQUEST['name'];
$query = "Insert into tbl_category (cat_description) Values ('%%')";
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
Re: PHP insert
no he isn't he is using single quotes within double quotes which is
Just a note to the op however. You are currently using $_REQUEST I would
advise that you use either $_GET or $_POST although this is not cuasing the
error it is something that is frowned upon unless you really HAVE too. The
problem with using $_REQUEST is that you do not know where it has come from
As mentioned by another poster try using mysql_error to see what error
message mysql is outputting. it might also help as also mentioned to infact
show us the structure of your table.