473,397 Members | 2,028 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,397 software developers and data experts.

Need help finding a bug...

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($sql);
$row = mysql_fetch_array($rs);
$cnum = $row['id'] +1;
}
include_once("db.php");

$sql = "INSERT INTO clients(' ', '$fname', '$minit', '$lname',
'$ssn', '$phone', '$cdate', '$cnum'";
echo $sql;
//exit;
mysql_query($sql);
echo "<font size=\"+1\"><b>ACCOUNT CREATED</b></font><br>";
echo "The new account for ".$fname." ".$minit." ".$lname." has been
successfully created.";
exit;
}

Apr 18 '06 #1
2 1117
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($sql);
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
Apr 18 '06 #2
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

Apr 18 '06 #3

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

Similar topics

12
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...
39
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...
55
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...
9
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.
9
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 ...
3
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...
2
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. ...
18
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....
0
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 ...
7
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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
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.