473,661 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Databa se 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
($dberrormessag e);
#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($_REQU EST['name']))
{ ?>
<table border="1">
<tr>
<th>Number</th>

</tr>
"Insert into tbl_category (cat_descriptio n)
Values ('%{$_REQUEST['name']}%')
<?php $query = "Insert into tbl_category (cat_descriptio n) Values
('%{$_REQUEST['name']}%')";
@$result = mysql_query($qu ery) or exit('<strong>A n 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($co nn);
}
?>
</body>
</html>
Thanx in advance

Oct 20 '06 #1
5 2518
Hi,

Maybe mysql_error has some more info?

$result = mysql_query($qu ery) or trigger_error(m ysql_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.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Databa se 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
($dberrormessag e);
#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($_REQU EST['name']))
{ ?>
<table border="1">
<tr>
<th>Number</th>

</tr>
"Insert into tbl_category (cat_descriptio n)
Values ('%{$_REQUEST['name']}%')
<?php $query = "Insert into tbl_category (cat_descriptio n) Values
('%{$_REQUEST['name']}%')";
@$result = mysql_query($qu ery) or exit('<strong>A n 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($co nn);
}
?>
</body>
</html>
Thanx in advance
Oct 20 '06 #2
Hmm Bonzol <Bo****@hotmail .comwrote:
<?php $query = "Insert into tbl_category (cat_descriptio n) Values
('%{$_REQUEST['name']}%')";
@$result = mysql_query($qu ery) or exit('<strong>A n 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******** *************@m 73g2000cwd.goog legroups.com...
Hello, PHP n00b here.

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

$name = $_REQUEST['name'];
$query = "Insert into tbl_category (cat_descriptio n) 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_descriptio n) 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.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Databa se 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
($dberrormessag e);
#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($_REQU EST['name']))
{ ?>
<table border="1">
<tr>
<th>Number</th>

</tr>
"Insert into tbl_category (cat_descriptio n)
Values ('%{$_REQUEST['name']}%')
<?php $query = "Insert into tbl_category (cat_descriptio n) Values
('%{$_REQUEST['name']}%')";
@$result = mysql_query($qu ery) or exit('<strong>A n 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($co nn);
}
?>
</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
2510
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 Kozicki, Nicola Musatti, John Potter and Maxim Yegorushkin for helping with that survey. Since I started work on this paper at least two people I respect very much have expressed interest in nailing down the "insert without hint" function a...
6
7000
by: Mark P | last post by:
Some time ago I posted here about inserting into a set with a hint: http://groups-beta.google.com/group/alt.comp.lang.learn.c-c++/browse_thread/thread/fb75b00f73e979db/018b8d0eadb38dbf?q=%22STL+insert+with+hint%22+%22Mark+P%22&rnum=1&hl=en#018b8d0eadb38dbf I quoted the SGI STL docs describing a.insert(p, t), where p is the hint iterator and t is the inserted object: "Insert with hint is logarithmic in general, but it is amortized...
14
4286
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 salvage the records from the many table and without going into detail, one of the reasons I can't do the opposite as there are records in the ONE table that I need to keep even if they don't have any child records in the MANY table. Below I created...
16
17004
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 must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then IF FOUND UPDATE <TABLE> SET .... <Values entered here> ELSE INSERT INTO <TABLE> VALUES <Values...
8
6285
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 one-to-one relationship but on this occasion I must keep username/password details within a seperate table. Here's the basic specs and database schema: -------------------------------------------
4
5475
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 this would be happening, we would appreciate feedback. We have tested on 7.3.4, 7.3.6 and 7.4.1 and all exhibit the same behavior. Test case one tries to populate table2 from table1 with records that are not in table2 already. Table2 gets...
2
3195
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 : INSERT INTO temp_tab VALUES (1,2,3)
3
2305
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 example I had to go by 'INSERT INTO tblCustomers (CustomerID, , )
6
3712
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, AA_FILE_SOURCE_CD, .AA_TIN_TYP FROM VAATAFAA WHERE AB_TP_ACNT_STAT_CD <0),
1
2645
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 another table and be able to maintain the relationships between the parent/child rows of the new records. Something like old_id new_id
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8542
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7362
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1740
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.