Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2010
    Posts
    3

    Unanswered: Simple Form Problem

    I'm having an issue getting this simple form to work properly. I'm not a PHP guru by any stretch but I thought I had this simple code figured out. Apparently, I'm too stupid to even get this right. Any help?

    Here's the code (I've changed the mysql_connect info for security):
    PHP Code:
    <?php
        $connect 
    mysql_connect('xxx''xxx''xxxx');
        if (!
    $connect) {
            die(
    'Could not connect: ' mysql_error());
        }
        
    mysql_select_db('bestseni_ssw'$connect);

        
        if (isset(
    $_POST['send'])) {
            
    $errors = array();
            if (!
    strlen(@$_POST['name'])) {
                
    $errors['name'] = 'This field is required';
            }
            if (!
    strlen(@$_POST['BusinessName'])) {
                
    $errors['BusinessName'] = 'This field is required';
           
            }
            if (!
    strlen(@$_POST['ContactPref'])) {
                
    $errors['ContactPref'] = 'This field is required';
           
          
           }
            if (!
    strlen(@$_POST['phone'])) {
                
    $errors['phone'] = 'This field is required';
            }
            if (!
    strlen(@$_POST['email'])) {
                
    $errors['email'] = 'This field is required';
            } else if (
    eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", @$_POST['email'])) {
                
    $errors['email'] = 'Email is not valid';
           
            }
            if (!
    count($errors)) {
                
    $fields = array('name''BusinessName''ContactPref''phone''email');

                
    $sqlValuesArr = array();
                
    $sql 'INSERT INTO form (' implode(', '$fields) . ') VALUES ';
                foreach (
    $fields as $field) {
                    
    $sqlValuesArr[] = "'" . (@$_POST[$field]) . "'";
                }
                
    $sql .= '(' implode(', '$sqlValuesArr) . ')';

                
    mysql_query($sql$connect);
                
    mysql_close($connect);
                
                
            }
       
        }

        
    mysql_close($connect);
    ?>

    <form action="" method="post">
        <div class="form-top"></div>
        <input type="hidden" name="send" value="1" />
        <div class="form">
        <div class="text">
        
          
        </div>
        <fieldset>
            <div class="field1">
                <div class="label"><label for="name">Name </label></div>
                <div><input name="first_name" id="first_name" value="" type="text" /></div>
            </div>
            <br/>
            <div class="field1">
                <div class="label"><label for="email">Email </label></div>
                <div><input name="email" id="email" value="" type="text" /></div>
                
            </div><br/>
            <div class="field1">
                <div class="label"><label for="phone">Phone </label></div>
                <div><input name="phone" id="phone" value="" type="text" /></div>
              
            </div><br/>
            <div class="field1">
                <div class="label"><label for="BusinessName">Business Name </label></div>
            <div><input name="BusinessName" id="BusinessName" value="" type="text" /></div>
                
            </div><br/><br/>
            <div class="row">
                <div class="label"><label for="ContactPref">Preferred Method of Contact, Phone or Email?</label></div>
                <div><input name="ContactPref" id="ContactPref" value="" type="text" /></div>
                
            </div><br/>
            
            <div class="wrapper"><a href="http://www.Training4search.com/index-2.html" class="link1" >Submit</a><input type="submit" value="" /></div>
            </fieldset>
        </form>

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    and where is it failing
    what symptoms are you getting
    what steps have you take toi debug the code
    what steps have you taken to make certain the variables have correct values

    whilst debugging the PHP "or die" construct is useful, you can extend its use by writing a production error handler.
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jul 2010
    Posts
    3
    I'm not sure where it is failing. I do know that the info isn't being written to my database. I'm a novice with this. Probably in over my head. Haven't tried any other debugging. I'm not seeing any error notices. Just not seeing it written to the db.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    modern PHP installations are presumed to be for production servers so they have lots of usefull stuff for developers turned off by default

    look at PHP.NET for Set Error Level

    personally I'd suggest you go back to the place you got your script form and ask them whats wrong

    you have multiple sources of error
    1) it could be with the connection to the DB (you are not reading or writing or connecting to the db)
    2) it could be the variables you are getting from the previous instance of the form are incorrect, you dont' set default values
    3) it could be that you are not integrating the PHP with the HTML.. at a brief glance I suspect its likely to be the latter. I don't see anywhere where you set the value for the HTML text boxes in PHP

    I don't recognise that style of PHP & HTML, but that doens't mean its not correct, it may mean my PHP is too rusty.

    so at present you have a script and that isn't working, and you expect us to trawl through your code to find why its not working. theres very few people contributing to the PHP forum on this site, and mostly we deal with db errors not PHP errors.

    I think you need to develop a debugging technique to work out what the errors are
    the you need to go through each line of code to work out what it does, and then make sure your perception is the same as the PHP runtime
    use lots of debug messages
    examine the SQL to make sure its legible and correct
    never do anything to the DB without some form of error reproting or trappin

    make certain your IF's have an else.so you can see where the code path is going, evven if its no more than
    if (condition='blah')
    { //do soemething
    } else
    { print "condition was blah";
    }
    some consider it good practise to put an empty else in trheir code to demonstrate they have considered the else condition but don't need it.. seems silly to me as a comment can help
    use comments in your code if you want help.
    consider using an IDE such as eclipse or netbeans if you want VB.VBA style debugging, but those IDE's are not for the faint hearted

    I don't claim the following is 'good' code however you define that
    PHP Code:
    <?PHP
    include ("./incfiles/cmnvars.php");
    include (
    "./incfiles/cmnmod.php");
    if (isset(
    $pTXID)!=TRUE or (isset($pTXID)==true and $pTXID<=0)) {
      
    //just in case someone has got to here without a txid (in theory impossible)
      
    header("Location: http:/FrameSetShop.php?DM=ListManufacturers");
      exit;
    }
    // script to extract all Manufacturers from DT_Manu
    $cnn=@mysql_connect(HOST,UID1,PWD1) or die(handleerror(EMAILID,"ListManufacturers","E:1035 - Failed to open cn:$cnn ".mysql_errno().": ".mysql_error()));
    $dbr=@mysql_select_db(DBN,$cnn) or die (handleerror(EMAILID,"ListManufacturers","E:1036 - Failed to open db:$dbr ".mysql_errno().": ".mysql_error()));
    $sql "select * from DT_TX where TX_ID=$pTXID;";
    $sqlr=@mysql_query($sql,$cnn) or die (handleerror(EMAILID,"ListManufacturers","E:1037 - Failed to open rs:$sql ".mysql_errno().": ".mysql_error()));
    if (@
    mysql_num_rows($sqlr)==0//if not found then start over
    header("Location: http:/FrameSetShop.php?DM=ListManufacturers");}
    //rest of script follows
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Jul 2010
    Posts
    3
    Sorry. I didn't "expect" anyone to "trawl around" and get answers. I was looking for some help and thought it may be something simple I was missing and/or overlooking.

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    lets start over
    what isn't working
    what are you seeing that you arem't expecting
    what are you not seeign that you expect

    is it the form thats is dying is it the db write
    theres not enough information to decide where you need help
    not telling us what the problem is makes it virtually impossible to diagose the problem

    I don't hink you will veer see values int eh HTML, becuase I can't see where you se t thenm
    I don't know whether the problem is you aren't writing the values to the db

    what is the problem you are trying to fix
    its not working doesn't provide sufficient information to track down the faults, and I dont' have the time to go through line by line to identify what may be a simple problem, or a series of faults.

    contributors try and help, but they can't do for you. you need to do at least some of the footwork.


    what do you think shoild happen with errors
    is theis script re entrant (ie do you expect to display the old values allow the user to edit them till they successfully complete the form
    you need to guard against SQL injection attacks in all alhanumeric data fromt he outside world
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •