473,412 Members | 5,385 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,412 software developers and data experts.

HELP: "insert into" problem in PHP

Hi, I need urgent help with a novice problem. I would appreciate any
advice, suggestions... Thanks a lot in advance! Here it is:

I created a sign-up sheet (reg.html) where people fill in their first
name, last name, email, etc. The data are then sent to a PHP script
(reg.php). The data are then inserted into a table (reg) in MS SQL
server. I have declared the variables like this:

if (!(isset($_POST['FirstName']))) {
$FirstName = "" ;
} else {
$FirstName = $_POST['FirstName'] ;
}

Then I said the following to make sure people fill in all the info:

if(empty($FirstName) OR empty($LastName) OR empty($Email))
{
echo "Oops, you must complete the form to register. Please use the
browser back button to go back and complete the form.";
echo "</body></html>";
exit;
}

The statement that insert the data to the table is like this:

$qry = "insert into reg values ('$FirstName','$LastName','$Email')";

However, this doesn't work. I looked into examples online, but none of
the "insert into" statements handle varibles (they all insert actual
values such as "Hanna, Smith, hs@yahoo.com', etc.)

Could you tell me what went wrong with this script? I am pretty sure
the problem originates from the "insert" statement.

Thanks!

A PHP Newbie
Jul 16 '05 #1
2 5605
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Whilst lounging around on 5 Aug 2003 12:50:24 -0700,
kw*****@yahoo.com (newbie_mw) amazingly managed to produce the
following with their Etch-A-Sketch:
Hi, I need urgent help with a novice problem. I would appreciate
any advice, suggestions... Thanks a lot in advance! Here it is:

I created a sign-up sheet (reg.html) where people fill in their
first name, last name, email, etc. The data are then sent to a PHP
script (reg.php). The data are then inserted into a table (reg) in
MS SQL server. I have declared the variables like this:

if (!(isset($_POST['FirstName']))) {
$FirstName = "" ;
} else {
$FirstName = $_POST['FirstName'] ;
}

Then I said the following to make sure people fill in all the info:

if(empty($FirstName) OR empty($LastName) OR empty($Email))
{
echo "Oops, you must complete the form to register. Please use the
browser back button to go back and complete the form.";
echo "</body></html>";
exit;
}

The statement that insert the data to the table is like this:

$qry = "insert into reg values
('$FirstName','$LastName','$Email')";

However, this doesn't work. I looked into examples online, but none
of the "insert into" statements handle varibles (they all insert
actual values such as "Hanna, Smith, hs@yahoo.com', etc.)

Could you tell me what went wrong with this script? I am pretty
sure the problem originates from the "insert" statement.

Thanks!

A PHP Newbie

And the error you received is?

I have an _idea_ what the problem _might_ be, but how can I tell for
sure without knowing what error I'm thinking about assisting you
with?

My initial thought / theory is that you've got more columns than just
those 3 (possibly an ID column amongst other things). Try something
like:
$sql = "
INSERT INTO reg
(
firstname,
lastname,
email
)
VALUES (
$FirstName,
$LastName,
$Email
)
";
I've obviously assumed that you have 'firstname', 'lastname' and
'email' as table columns, you may need to ammend to suit your exact
table structure.
HTH.

Regards,

Ian

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0

iQA/AwUBPzAMGWfqtj251CDhEQIkbgCgo0niSW+WsOlaeRxB/IHiDtFUDtoAoJXp
BhNxNkv9wZcsnp/ce5ukS3ZI
=0C9T
-----END PGP SIGNATURE-----

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
Jul 16 '05 #2
Hi Ian,

Thanks for help! The columns and variables are exactly matched so it shouldn't
be the problem. Actually the original html and php files are pretty long. But
I guess a more detailed script should help you diagnose the problem. The error
message to the below script is:
---------------------------------
call someoneDB Error:
Warning: mssql_num_rows(): supplied argument is not a valid Sybase result
resource ... line 88
----------------------------------

//... is the folder this file is in//

Here is the (almost) full script:

<?php

// some MS SQL server connection thing that I can't show here :-) //
// below is the original script.//

if (!(isset($_POST['NetID']))) {
$NetID = "" ;
} else {
$NetID = $_POST['NetID'] ;
}

if (!(isset($_POST['FirstName']))) {
$FirstName = "" ;
} else {
$FirstName = $_POST['FirstName'] ;
}

if (!(isset($_POST['LastName']))) {
$LastName = "" ;
} else {
$LastName = $_POST['LastName'] ;
}

if (!(isset($_POST['Email']))) {
$Email = "" ;
} else {
$Email = $_POST['Email'] ;
}

if (!(isset($_POST['Major']))) {
$Major = "" ;
} else {
$Major = $_POST['Major'] ;
}

if (!(isset($_POST['Classification']))) {
$Classification = "" ;
} else {
$Classification = $_POST['Classification'] ;
}

if (!(isset($_POST['How']))) {
$How = "" ;
} else {
$How = $_POST['How'] ;
}

if (!(isset($_POST['Description']))) {
$Description = "" ;
} else {
$Description = $_POST['Description'] ;
}

if(empty($NetID) OR empty($FirstName) OR empty($LastName) OR empty($Email) OR
empty($Major) OR empty($Classification) OR empty($How) OR empty($Description))

{
echo "Oops, you must complete the form to register. Please use the browser
back button to go back and complete the form.";
echo "</body></html>";
exit;
}

$qry = "insert into reg values (";
$qry = $qry."'$NetID'";
$qry = $qry.",'$FirstName'";
$qry = $qry.",'$LastName'";
$qry = $qry.",'$Email'";
$qry = $qry.",'$Major'";
$qry = $qry.",'$Classification'";
$qry = $qry.",'$How'";
$qry = $qry.",'$Description'";
$qry = $qry.")";

$rs=$db->query ($qry);
if (DB::iserror($rs)){print"call someone"; print $rs->getMessage();}

$result = mssql_query("SELECT * FROM reg");
$num_rows = mssql_num_rows($result) ;

if ($num_rows > 10)
{
echo "Sorry, our registration is full. Please stay tuned till the next
one.";
}

else
{
echo "Congratulations, $FirstName! Your have registered for --- ";
echo "<p>";
}

?>

Hope it is clearer now. What's most frustrating is that it worked for a while,
but then when I expanded the columns from 3 to 8 and it just messed up. So
what went wrong?

Newbie

"Ian.H [dS]" wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Whilst lounging around on 5 Aug 2003 12:50:24 -0700,
kw*****@yahoo.com (newbie_mw) amazingly managed to produce the
following with their Etch-A-Sketch:
Hi, I need urgent help with a novice problem. I would appreciate
any advice, suggestions... Thanks a lot in advance! Here it is:

I created a sign-up sheet (reg.html) where people fill in their
first name, last name, email, etc. The data are then sent to a PHP
script (reg.php). The data are then inserted into a table (reg) in
MS SQL server. I have declared the variables like this:

if (!(isset($_POST['FirstName']))) {
$FirstName = "" ;
} else {
$FirstName = $_POST['FirstName'] ;
}

Then I said the following to make sure people fill in all the info:

if(empty($FirstName) OR empty($LastName) OR empty($Email))
{
echo "Oops, you must complete the form to register. Please use the
browser back button to go back and complete the form.";
echo "</body></html>";
exit;
}

The statement that insert the data to the table is like this:

$qry = "insert into reg values
('$FirstName','$LastName','$Email')";

However, this doesn't work. I looked into examples online, but none
of the "insert into" statements handle varibles (they all insert
actual values such as "Hanna, Smith, hs@yahoo.com', etc.)

Could you tell me what went wrong with this script? I am pretty
sure the problem originates from the "insert" statement.

Thanks!

A PHP Newbie


And the error you received is?

I have an _idea_ what the problem _might_ be, but how can I tell for
sure without knowing what error I'm thinking about assisting you
with?

My initial thought / theory is that you've got more columns than just
those 3 (possibly an ID column amongst other things). Try something
like:

$sql = "
INSERT INTO reg
(
firstname,
lastname,
email
)
VALUES (
$FirstName,
$LastName,
$Email
)
";

I've obviously assumed that you have 'firstname', 'lastname' and
'email' as table columns, you may need to ammend to suit your exact
table structure.

HTH.

Regards,

Ian

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0

iQA/AwUBPzAMGWfqtj251CDhEQIkbgCgo0niSW+WsOlaeRxB/IHiDtFUDtoAoJXp
BhNxNkv9wZcsnp/ce5ukS3ZI
=0C9T
-----END PGP SIGNATURE-----

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.


Jul 16 '05 #3

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

Similar topics

1
by: newbie_mw | last post by:
Seems my post was buried in more cries for help :-) I will try again. It's probably a very novice question so please take a look! Thanks!...
9
by: Luc Dal | last post by:
Hello, I've serious problem using ASP under WindowsXP sp2. I get the following reply (sorry it's in french) Erreur de compilation Microsoft VBScript error '800a0401' Fin d'instruction...
5
by: Chad Richardson | last post by:
Is there a way in SQL Server 2000 to extract data from a table, such that the result is a text file in the format of "Insert Into..." statements, i.e. if the table has 5 rows, the result would be 5...
2
by: CFW | last post by:
I use the following flawlessly to insert a single field: strSQL = "Insert into (Casket) Values " _ & "(" & conQuote & NewCasket & conQuote & ")" Set db = CurrentDb If MsgBox(NewCasket & " is...
3
by: Ed | last post by:
Hi, I want to load data to a table in Sql Server from a dataset table in my vb.net app using a dataAdapter. I know how to do this as follows (my question is to see if I can reduce the amount...
0
by: MarceloLinero | last post by:
Hi, i`m problem whith it !! help me ! No found way for insert in table directy in database sql express and no undertand why ! steps in general: 1. create coneccion ready 2. declarate a...
4
by: Takeadoe | last post by:
Dear NG - I've got a bunch of SQL statements (Insert Into "Access Table Name") generated from another software program. They look like this: Pasting these lines into the SQL view as they are...
13
by: shankindc | last post by:
Hi, I have a data entry form which opens default values each time the form is open. Requirement is that users can edit existing data in the form. When the form is closed, it shouldnt update the...
6
by: ewpatton | last post by:
Good day, I've been trying to work with SQL and an Access database in order to handle custom user profiles. I haven't had any trouble reading from my database, but inserting new entries into...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.