473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

PHP insert

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

Oct 20 '06 #1
5 2506
Hi,

Maybe mysql_error has some more info?

$result = mysql_query($query) or trigger_error(mysql_error());

Dunno if it's a problem having dbusername and dbpassword blank.
occured while connecting to the database. The following query is

not valid: \''.$query.'\'.</strong>');
}?>

Bonzol wrote:
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
Oct 20 '06 #2
Hmm Bonzol <Bo****@hotmail.comwrote:
<?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
show us your table in db
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl
( ads: www.e6y.eu )

2be || !2be $this =mysql_query();
Oct 20 '06 #3
"Bonzol" <Bo****@hotmail.compíse v diskusním príspevku
news:11*********************@m73g2000cwd.googlegro ups.com...
Hello, PHP n00b here.

<?php $query = "Insert into tbl_category (cat_description) Values
('%{$_REQUEST['name']}%')";
Problem is that you use single quoutes twice ;-) Try this

$name = $_REQUEST['name'];
$query = "Insert into tbl_category (cat_description) Values ('%{$name}%')";

--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
Oct 21 '06 #4
Problem is that you use single quoutes twice ;-) Try this

$name = $_REQUEST['name'];
$query = "Insert into tbl_category (cat_description) Values
('%{$name}%')";
no he isn't he is using single quotes within double quotes which is
perfectly valid.

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
properly.

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.
Oct 21 '06 #5
Bonzol wrote:
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
You haven't told us what the problem actually is: do you get an error
message? Does it apparently succeed but insert no rows? Does it insert
empty rows?

Colin
Oct 21 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Howard Hinnant | last post by:
I recently asked for a survey of multimap insert with hint behavior, in support of a paper I'm writing concerning lwg issue 233. My sincere thanks to Beman Dawes, Raoul Gough, Russell Hind, Bronek...
6
by: Mark P | last post by:
Some time ago I posted here about inserting into a set with a hint: ...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
4
by: Chris Kratz | last post by:
Hello all, We have run into what appears to be a problem with rules and subselects in postgres 7.4.1. We have boiled it down to the following test case. If anyone has any thoughts as to why...
2
by: Geoffrey KRETZ | last post by:
Hello, I'm wondering if the following behaviour is the correct one for PostGreSQL (7.4 on UNIX). I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching the following request :...
3
by: MP | last post by:
Hi Posted this several hours ago to another ng but it never showed up thought i'd try here. using vb6, ado, .mdb, jet4.0, no access given table tblJob with field JobNumber text(10) 'The...
6
by: lenygold via DBMonster.com | last post by:
Hi everybody: What is the best way to I have 10 tables with similar INSERT requiremnts. INSERT INTO ACSB.VAATAFAE WITH AA(AA_TIN, AA_FILE_SOURCE_CD, .AA_TIN_TYP) AS ( SELECT AA_TIN,...
1
by: EJO | last post by:
with sql 2000 enterprise Trying to build a stored procedure that will take the rows of a parent table, insert them into another table as well as the rows from a child table to insert into...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.