473,769 Members | 5,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($First Name) 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','$Em ail')";

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 5648
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Whilst lounging around on 5 Aug 2003 12:50:24 -0700,
kw*****@yahoo.c om (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($First Name) 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','$Em ail')";

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/AwUBPzAMGWfqtj2 51CDhEQIkbgCgo0 niSW+WsOlaeRxB/IHiDtFUDtoAoJXp
BhNxNkv9wZcsnp/ce5ukS3ZI
=0C9T
-----END PGP SIGNATURE-----

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.ne t | 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($FirstNam e) OR empty($LastName ) OR empty($Email) OR
empty($Major) OR empty($Classifi cation) OR empty($How) OR empty($Descript ion))

{
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.",'$FirstN ame'";
$qry = $qry.",'$LastNa me'";
$qry = $qry.",'$Email' ";
$qry = $qry.",'$Major' ";
$qry = $qry.",'$Classi fication'";
$qry = $qry.",'$How'";
$qry = $qry.",'$Descri ption'";
$qry = $qry.")";

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

$result = mssql_query("SE LECT * 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 "Congratulation s, $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.c om (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($First Name) 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','$Em ail')";

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/AwUBPzAMGWfqtj2 51CDhEQIkbgCgo0 niSW+WsOlaeRxB/IHiDtFUDtoAoJXp
BhNxNkv9wZcsnp/ce5ukS3ZI
=0C9T
-----END PGP SIGNATURE-----

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.ne t | 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
4539
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! ----------------------------------------------------------------- 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...
9
2438
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 attendue /iisHelp/common/500-100.asp, line 11
5
3098
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 lines of : insert into Table (, , .... VALUES a,b,c) insert into Table (, , .... VALUES d, e, f) insert into Table (, , .... VALUES g, h, i) insert into Table (, , .... VALUES j, k, l) insert into Table (, , .... VALUES m, n, o)
2
9889
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 not in the list. Do you want to add " & NewCasket & _ " as a new Casket/Container in the list?", vbYesNo, _ "Add a Casket/Container") = vbYes Then
3
37813
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 of code below): .... Dim DA As SqlDataAdapter = New SqlDataAdapter Dim Parm As New SqlParameter ....
0
2421
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 sqlcomand (insert into "table" values "values") etc 3. see database and no do nothing !
4
2543
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 generates a couple of different errors (missing semicolon being one of them). They work fine if I paste 1 line at a time. Can someone tell me what I need to do to remedy the situation? I can't hardly paste 1 at a time! Your help is very much...
13
3188
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 existing record but rather insert a new record. On the Form-Beforeupdate function, I first check if the record already exists (Primary keys exist). Then I wrote a "Insert into" SQL that picks all values from the form and inserts into the backend...
6
6003
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 it has been troublesome to say the least. My ASP.NET script is supposed to execute an INSERT INTO statement in order to add a user to the database. Here is a sample:
0
9423
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,...
0
10210
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9860
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
8869
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
7406
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
6668
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3955
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
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.