Hello Everyone,
I have been working with a piece of code for the past few hours that I
just can't seem to get working. I'm hoping someone here can help me
find the bug. Basically, the code is supposed to take all the data
entered into a forms fields, stripslashes() it then insert it into the
database. Pretty straightforward . The only thing that is unique is
that I am checking if a particular field is blank then allowing the
program to auto-assign a number to the field if it is. Still. pretty
straightforward .
What's happening, however, is that the information is never being
entered into the database. When I echo the sql statement being
constructed back it looks right. But I am sure there is a problem
somewhere. Can anyone help me find it? I will pay you $10 via paypal if
you can help me here. The code is below.
Thanks,
Anthony
if($_POST['fname'] != "" && $_POST['minit'] != "" && $_POST['lname'] !=
"" && $_POST['ssn'] != ""){
$fname = stripslashes($_ POST['fname']);
$minit = stripslashes($_ POST['minit']);
$lname = stripslashes($_ POST['lname']);
$ssn = stripslashes($_ POST['ssn']);
$phone = stripslashes($_ POST['phone']);
$cdate = date("Y-m-j");
if($_POST['cnum'] != ""){
$cnum = stripslashes($_ POST['cnum']);
}
else{
include("db.php ");
$sql = "SELECT MAX(id) FROM clients";
$rs = mysql_query($sq l);
$row = mysql_fetch_arr ay($rs);
$cnum = $row['id'] +1;
}
include_once("d b.php");
$sql = "INSERT INTO clients(' ', '$fname', '$minit', '$lname',
'$ssn', '$phone', '$cdate', '$cnum'";
echo $sql;
//exit;
mysql_query($sq l);
echo "<font size=\"+1\"><b> ACCOUNT CREATED</b></font><br>";
echo "The new account for ".$fname." ".$minit." ".$lname." has been
successfully created.";
exit;
} 2 1124
Anthony wrote: Hello Everyone,
I have been working with a piece of code for the past few hours that I just can't seem to get working. I'm hoping someone here can help me find the bug. Basically, the code is supposed to take all the data entered into a forms fields, stripslashes() it then insert it into the database. Pretty straightforward . The only thing that is unique is that I am checking if a particular field is blank then allowing the program to auto-assign a number to the field if it is. Still. pretty straightforward .
What's happening, however, is that the information is never being entered into the database. When I echo the sql statement being constructed back it looks right. But I am sure there is a problem somewhere. Can anyone help me find it? I will pay you $10 via paypal if you can help me here. The code is below.
$sql = "INSERT INTO clients(' ', '$fname', '$minit', '$lname', '$ssn', '$phone', '$cdate', '$cnum'";
I can't see a matching close bracket on that statement.
Also, you should be doing either
INSERT INTO clients (field1, field2, field3, ...) VALUES (' ', '$fname',
'$minit', ...)
or
INSERT INTO clients VALUES (' ', '$fname', '$minit', ...)
i.e. the values want to go in a list after the VALUES keyword.
echo $sql; //exit; mysql_query($sq l); echo "<font size=\"+1\"><b> ACCOUNT CREATED</b></font><br>"; echo "The new account for ".$fname." ".$minit." ".$lname." has been successfully created."; exit;
Note that you're ignoring the error status here. Check the return value
of mysql_query() to determine whether an error occurred, and if so echo
the result of mysql_error(). Had you done this you'd probably have
realised you had a syntax error in your SQL.
Tim
Thanks Tim,
Looks like ignoring the return code proved to be my downfall. I wasn't
aware that MySQL returned a status code on an insert. You were right,
of course, that my SQL statement was incomplete. After I changed it, it
worked.
Thanks again and please check your inbox for a personal email from me.
Anthony This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jason |
last post by:
Access 2000:
I have a customer-inventory table I need to loop through and compile a list
of all the inventory items the customer is tracking. The problem I am
finding is that a simple loop will pull out the customer details each time
their is an inventory item listed....I need to get the customer out ONCE and
list his items....is there an...
|
by: Scotter |
last post by:
Okay I think my title line was worded misleadingly. So here goes again.
I've got quite 20 identical MDB files running on an IIS5 server.
From time to time I need to go into various tables and add a field or two.
It would be great if there were an application out there that could either:
(a) sync all MDB designs (and/or data) designated to...
|
by: Alex |
last post by:
Hello people,
The following is not a troll but a serious request.
I found myself in a position where I have to present a Pro/Con list to management and architects in our company with regard to developing new products (specifically - desktop products) in C#/.NET instead of the usual C++/COM that we do.
Since I am not an experienced .NET...
|
by: glin |
last post by:
Hi Guys,
I am having problem finding the position of a button that I can set the
div position next to the button.
Can you please help? Thanks in advance.
|
by: dave m |
last post by:
I need to be able to retrieve a unique ID from a users PC. I needs to be
something a user could not easily change, like the computer name. Could
someone point me in the right direction to find the information found in
Windows system information? Or maybe there is a better method.
Thanks in advance for any help or suggestions.
Dave...
| |
by: Richard Lewis Haggard |
last post by:
We are having a lot of trouble with problems relating to failures relating
to 'The located assembly's manifest definition with name 'xxx' does not
match the assembly reference" but none of us here really understand how this
could be an issue. The assemblies that the system is complaining about are
ones that we build here and we're not changing...
|
by: ElkGroveR |
last post by:
Hi there!
I'm using PHP to create a simple, dynamic MySQL SELECT query.
The user chooses a selection from a HTML Form SELECT element's many options
and submits the form via a POST action.
The SELECT query is built as follows:
$itemtype = stripslashes(trim($_POST));
|
by: bsruth |
last post by:
I tried for an hour to find some reference to concrete information on
why this particular inheritance implementation is a bad idea, but
couldn't. So I'm sorry if this has been answered before. Here's the
scenario:
We have a base class with all virtual functions. We'll call this the
Animal class. We then make two classes Fish and Bird...
|
by: U S Contractors Offering Service A Non-profit |
last post by:
Brilliant technology helping those most in need Inbox
Reply
U S Contractors Offering Service A Non-profit
show details
10:37 pm (1 hour ago)
Brilliant technology helping those most in need Inbox
Reply
from Craig Somerford <uscos@2barter.net>
hide details 10:25 pm
(3 minutes ago)
|
by: Earl |
last post by:
Can anyone point me to some good references for coding a Winforms app to
trigger replication (merge preferably) on SQL2005? I'm setting up a scenario
where I want my app to allow multiple laptops to synchronize to the
distribution SQL2005 database and I'd like to do it either automatically or
by having them click on a menu/button. From working...
|
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...
| |
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...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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...
|
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...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |