Code not working

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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.


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

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

    // Include MYSQL info

    // Create the query
    $q = "INSERT INTO MyDB (JobNumber) VALUES ('')";

    // 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

        } 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!" />


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

Thanks in advance

Re: Code not working napisał(a):
Quoted text here. Click to load it

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

Re: Code not working

Quoted text here. Click to load it

I'd assume those are called via this require:


"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)  

Re: Code not working wrote:
Quoted text here. Click to load it
Quoted text here. Click to load it

should be:
        // Close the connection


Re: Code not working

Carved in mystic runes upon the very living rock, the last words of  

Quoted text here. Click to load it

"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?

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

Re: Code not working

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).

Re: Code not working

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.


Site Timeline