473,399 Members | 3,603 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,399 software developers and data experts.

Code not working

Hi could anyone please help me. I am a newbie to php. I am using php4
and trying to put together some code to update a db but I am not having
much luck. This is the code I have come up with so far.

<?php

if (isset($_POST['submitted'])) { // if the form has been submitted
handle it

// check the required form fields.
if (!empty($_POST['JobNumber'])) {

// Include MYSQL info
require_once
'/home/e-smith/files/ibays/mct/cgi-bin/mysql_connect.inc.php';

// Create the query
$q = "INSERT INTO MyDB (JobNumber) VALUES ('{$_POST['JobNumber']}')";

// Execute the query
$r = mysql_query ($dbc, $q);

//print a message indicating success
if (mysql_affected_rows($dbc) == 1) {
echo '<b><font color="green">It Has Been entered!</font></b>';
} else {
echo '<b><font color="red">Sorry it has failed!</font></b>';
}

Close the connection
mysql_close($dbc)

} else { //print a message if they failed to enter a catagory
echo '<b><font color="red">You forgot to enter a value</font></b>';
}

} else {
?>

Add a new category to the Job Number:<br />
<form action="add_expense_category.php" method="post">
<input type="text" name="JobNumber" size="30" maxlength="30" /><br />
<input type="hidden" name="submitted" value="true" />
<input type="submit" name="submit" value="Submit!" />
</form>

<?php
}
?>

but for some reason it doesn't work. Am I missing something I have
looked over it 100 times but everything seems fine. Can anyone help me
out.

Thanks in advance
Paul

Jun 6 '06 #1
6 1326
pa**@sunnyland.com.au napisał(a):
Hi could anyone please help me. I am a newbie to php. I am using php4
and trying to put together some code to update a db but I am not having
much luck. This is the code I have come up with so far.

<?php

if (isset($_POST['submitted'])) { // if the form has been submitted
handle it

// check the required form fields.
if (!empty($_POST['JobNumber'])) {

// Include MYSQL info
require_once
'/home/e-smith/files/ibays/mct/cgi-bin/mysql_connect.inc.php';

// Create the query
$q = "INSERT INTO MyDB (JobNumber) VALUES ('{$_POST['JobNumber']}')";

// Execute the query
$r = mysql_query ($dbc, $q);

//print a message indicating success
if (mysql_affected_rows($dbc) == 1) {
echo '<b><font color="green">It Has Been entered!</font></b>';
} else {
echo '<b><font color="red">Sorry it has failed!</font></b>';
}

Close the connection
mysql_close($dbc)

} else { //print a message if they failed to enter a catagory
echo '<b><font color="red">You forgot to enter a value</font></b>';
}

} else {
?>

Add a new category to the Job Number:<br />
<form action="add_expense_category.php" method="post">
<input type="text" name="JobNumber" size="30" maxlength="30" /><br />
<input type="hidden" name="submitted" value="true" />
<input type="submit" name="submit" value="Submit!" />
</form>

<?php
}
?>

but for some reason it doesn't work. Am I missing something I have
looked over it 100 times but everything seems fine. Can anyone help me
out.

Thanks in advance
Paul


Is it the whole code? I can't see where you connect to database
(mysql_connect(), mysql_select_database()).
Anyway try to be more precise. What is the real problem?
There is nothing in $_POST after submit or database returns an error?
If there is database error then what it is? Try putting
error_reporting(E_ALL) in the beginning of your script it could help
to diagnose your problem.
greetz Emil
Jun 6 '06 #2

"Emil" <em**************@podczta.onet.pl> wrote in message
news:e6**********@news.onet.pl...
Is it the whole code? I can't see where you connect to database
(mysql_connect(), mysql_select_database()).


I'd assume those are called via this require:

require_once
'/home/e-smith/files/ibays/mct/cgi-bin/mysql_connect.inc.php';

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Jun 6 '06 #3
pa**@sunnyland.com.au wrote:
Hi could anyone please help me. I am a newbie to php. I am using php4
and trying to put together some code to update a db but I am not having
much luck. This is the code I have come up with so far. [snip]
Close the connection
mysql_close($dbc)


should be:
// Close the connection
mysql_close($dbc);
-david-

Jun 6 '06 #4
Carved in mystic runes upon the very living rock, the last words of
<pa**@sunnyland.com.au> of comp.lang.php make plain:
but for some reason it doesn't work.


"It doesn't work" isn't much to go on. Can you provide more detail? What
are you expecting to happen, that doesn't, or not expecting, that does?

http://www.catb.org/~esr/faqs/smart-...html#beprecise

Try outputting the query to be sure it's being properly formed. If there's
a db error, check mysql_error().

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Jun 6 '06 #5
Usually when I'm debugging I 'echo' program flow (eg. "Attempting DB
connection" so I can see at which point my logic has gone astray) and
as many variable values as I think could be causing issues (often
things like the actual query being run are a good place to start, as
others have already suggested).

Jun 7 '06 #6
Thanks for all your help.

I have put into action your suggestions and I have found the problem
(turns out I missed a ; bugger!)

anyway it was great to find out the ways to debug.

Thanks again.

Paul

Jun 7 '06 #7

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

Similar topics

171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
0
by: George2 | last post by:
Hello everyone, From the definition of working set, it is a subset of virtual pages resident in physical memory -- from book Windows Internals. It means working set could not be larger than...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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,...
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...

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.