Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. Can someone help me spot check this form code?

Can someone help me spot check this form code?

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
helpphphtmlmysqlcom
5 Posts 3 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bschm78
    wrote on last edited by
    #1

    I am writing a simple form for a website I am developing and I keep getting parse errors, mostly dealing with quotes around HTML tags. Here is my code - any guidance would be appreciated. The errors I am getting are creeping up between the following 2 comment tags, to make it easier to identify: /////////////////////////////////////////////////////// //check for existence of missing fields/error messages /////////////////////////////////////////////////////// and /* commented this out for testing of first part of script ///////////////////////////// // WRITE DATA TO MYSQL table ///////////////////////////// Here's my code: <HTML> <HEAD> <TITLE>SHIRT SCRIPT</TITLE> </HEAD> <BODY> <?php include ("validation_functions.php4"); function shirtsSetup() { //////////////////////////////////////// //GET VALUES FROM SHIRT PORTION OF FORM //////////////////////////////////////// $name = ($_POST['name']); $address = ($_POST['address']); $city = ($_POST['city']); $state = ($_POST['state']); $zip = ($_POST['zip']); $email = ($_POST['email']); $phone = ($_POST['phone']); $quantity = ($_POST['quantity']); $size = ($_POST['size']); $color = ($_POST['color']); $price = 15; $shirtTotalPrice = $price * $quantity; $instructions = ($_POST['instructions']); $paypal = ($_POST['paypal']); $check = ($_POST['check']); $to = "myemail@yahoo.com"; $subject = "OMN T-Shirt order"; $message= "$name\n$address\n$city\n$state\n$zip\n$phone\n$email\n$phone\nquantity\n$size\n$color\n$instructions"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; ////////////////////////////// //CHECK FOR ERRONEOUS FIELDS. ////////////////////////////// $error_msg = array(); $valid = verifyAlphaNum($name); if(!valid) { $error_msg[] = "Name must be letters, spaces, dashes and ' only"; } $valid = verifyAlphaNum($address); if(!valid) { $error_msg[] = "Address must be letters, numbers, spaces, dashes and ' only"; } $valid = verifyAlphaNum($city); if(!valid) { $error_msg[] = "City must be letters, spaces, dashes and ' only"; } $valid = verifyAlphaNum($state); if(!valid) { $error_msg[] = "State must be two letters only"; } $valid = verifyAlphaNum($zip); if(!valid) { $error_msg[] = "Zip must contain five numbers only"; } $valid = verifyEmail($email); if(!valid) { $error_msg[] = "Email must be a valid format"; } /////////////////////////////////////////////////////// //

    H 1 Reply Last reply
    0
    • B bschm78

      I am writing a simple form for a website I am developing and I keep getting parse errors, mostly dealing with quotes around HTML tags. Here is my code - any guidance would be appreciated. The errors I am getting are creeping up between the following 2 comment tags, to make it easier to identify: /////////////////////////////////////////////////////// //check for existence of missing fields/error messages /////////////////////////////////////////////////////// and /* commented this out for testing of first part of script ///////////////////////////// // WRITE DATA TO MYSQL table ///////////////////////////// Here's my code: <HTML> <HEAD> <TITLE>SHIRT SCRIPT</TITLE> </HEAD> <BODY> <?php include ("validation_functions.php4"); function shirtsSetup() { //////////////////////////////////////// //GET VALUES FROM SHIRT PORTION OF FORM //////////////////////////////////////// $name = ($_POST['name']); $address = ($_POST['address']); $city = ($_POST['city']); $state = ($_POST['state']); $zip = ($_POST['zip']); $email = ($_POST['email']); $phone = ($_POST['phone']); $quantity = ($_POST['quantity']); $size = ($_POST['size']); $color = ($_POST['color']); $price = 15; $shirtTotalPrice = $price * $quantity; $instructions = ($_POST['instructions']); $paypal = ($_POST['paypal']); $check = ($_POST['check']); $to = "myemail@yahoo.com"; $subject = "OMN T-Shirt order"; $message= "$name\n$address\n$city\n$state\n$zip\n$phone\n$email\n$phone\nquantity\n$size\n$color\n$instructions"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; ////////////////////////////// //CHECK FOR ERRONEOUS FIELDS. ////////////////////////////// $error_msg = array(); $valid = verifyAlphaNum($name); if(!valid) { $error_msg[] = "Name must be letters, spaces, dashes and ' only"; } $valid = verifyAlphaNum($address); if(!valid) { $error_msg[] = "Address must be letters, numbers, spaces, dashes and ' only"; } $valid = verifyAlphaNum($city); if(!valid) { $error_msg[] = "City must be letters, spaces, dashes and ' only"; } $valid = verifyAlphaNum($state); if(!valid) { $error_msg[] = "State must be two letters only"; } $valid = verifyAlphaNum($zip); if(!valid) { $error_msg[] = "Zip must contain five numbers only"; } $valid = verifyEmail($email); if(!valid) { $error_msg[] = "Email must be a valid format"; } /////////////////////////////////////////////////////// //

      H Offline
      H Offline
      help as an alias
      wrote on last edited by
      #2

      can u give me validation_functions.php4 so i can check it :laugh: :rolleyes: :-O

      help as a alias. Be happy and make others happy.Cheer up...........

      B 1 Reply Last reply
      0
      • H help as an alias

        can u give me validation_functions.php4 so i can check it :laugh: :rolleyes: :-O

        help as a alias. Be happy and make others happy.Cheer up...........

        B Offline
        B Offline
        bschm78
        wrote on last edited by
        #3

        That probably would help, eh? :). Here ya go.... Also, just to clarify my program, this is a t-shirt order form and the $paypal and $check variables ccorrespond to checkboxes asking if the user wants to pay by check or with paypal. <html> <head> <title>Validations functions</title> </head> <body> <?php // print "included ok"; function verifyAlphaNum($testString) { if (eregi ("^([[:alnum:]]|-|\.||')+$", $testString)) { return 1; } else { return 0; } } function verifyEmail($testString) { if (eregi ("^([[:alnum:]]|-|\.||')+@([[:alnum:]]|\.|- )+(\.)([a-z]{2, 4})$", $testString)) { return 1; } else { return 0; } } function verifyText($testString) { if (eregi("^([[:alnum:]]|-|\.||\n|\r|\?|\!|\"|\' ')+$", $testString)) { return 1; } else { return 0; } } function verifyPhone($testString) { if(eregi('^([[:digit:]]||-)+$', $testString)) { return 1; } else { return 0; } } ?> </body> </html>

        A 1 Reply Last reply
        0
        • B bschm78

          That probably would help, eh? :). Here ya go.... Also, just to clarify my program, this is a t-shirt order form and the $paypal and $check variables ccorrespond to checkboxes asking if the user wants to pay by check or with paypal. <html> <head> <title>Validations functions</title> </head> <body> <?php // print "included ok"; function verifyAlphaNum($testString) { if (eregi ("^([[:alnum:]]|-|\.||')+$", $testString)) { return 1; } else { return 0; } } function verifyEmail($testString) { if (eregi ("^([[:alnum:]]|-|\.||')+@([[:alnum:]]|\.|- )+(\.)([a-z]{2, 4})$", $testString)) { return 1; } else { return 0; } } function verifyText($testString) { if (eregi("^([[:alnum:]]|-|\.||\n|\r|\?|\!|\"|\' ')+$", $testString)) { return 1; } else { return 0; } } function verifyPhone($testString) { if(eregi('^([[:digit:]]||-)+$', $testString)) { return 1; } else { return 0; } } ?> </body> </html>

          A Offline
          A Offline
          alex barylski
          wrote on last edited by
          #4

          Here is my corrected version: 1. You are/were including a full HTML document into an already existing defined HTML document. I removed the extraneous HTML from validation_functions.php4 incase they snuck in there by accident somehow. 2. You are testing a variable without the leading '$' which PHP uses to indicate a variable. Although it won't cause a parse error (syntactically it's acceptable) you won't get expected results because there is no constant named 'valid' $valid = verifyAlphaNum($name); if(!**valid**) { $error_msg[] = "Name must be letters, spaces, dashes and ' only"; } You should change these instances to: $valid = verifyAlphaNum($name); if(!**$valid**) { $error_msg[] = "Name must be letters, spaces, dashes and ' only"; } When I run your code I get the following error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /var/www/test.php on line 87 Here is a tip: Always include the error information like above when asking for help with source code, and always wrap the source code in a [code] bracket so it's nicely formatted. It saves people from having to copy/psate and run your code like I had to do. Anyways, with that error message in hand I can quickly jump to line 87 in my editor and immediately spot the problem(s):

          echo "

          • " .$err. "

          ";

          You using double quotes for the HTML attribute when it's already wrapped in double quotes Change that code to this:

          echo '

          • '.$err.'

          Notice how I use double quotes for the HTML attribute and single quotes for the PHP string? That was intentional and should be considered a best practice. Why? PHP parser supports interpolated strings, meaning you can use a PHP variable in a double quoted string, like this:

          $test = 'Some Value';
          echo "Hello world this is a variable: $test";

          The above would output something like: Hello world this is a variable: Some Value While this might seem cool (and it is handy in some circumstances) it should be a practice avoided like the plague. 1. It can lead to difficult to find bugs as it's not very explicit. 2. You incur a performance hit because PHP tokenizer needs to process double quoted strings By using single quoted strings instead od double inside PHP you save yourself from the above problems. Use concatenation, like you already do:

          echo 'This is a '.$test.' string';

          Or

          B 1 Reply Last reply
          0
          • A alex barylski

            Here is my corrected version: 1. You are/were including a full HTML document into an already existing defined HTML document. I removed the extraneous HTML from validation_functions.php4 incase they snuck in there by accident somehow. 2. You are testing a variable without the leading '$' which PHP uses to indicate a variable. Although it won't cause a parse error (syntactically it's acceptable) you won't get expected results because there is no constant named 'valid' $valid = verifyAlphaNum($name); if(!**valid**) { $error_msg[] = "Name must be letters, spaces, dashes and ' only"; } You should change these instances to: $valid = verifyAlphaNum($name); if(!**$valid**) { $error_msg[] = "Name must be letters, spaces, dashes and ' only"; } When I run your code I get the following error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /var/www/test.php on line 87 Here is a tip: Always include the error information like above when asking for help with source code, and always wrap the source code in a [code] bracket so it's nicely formatted. It saves people from having to copy/psate and run your code like I had to do. Anyways, with that error message in hand I can quickly jump to line 87 in my editor and immediately spot the problem(s):

            echo "

            • " .$err. "

            ";

            You using double quotes for the HTML attribute when it's already wrapped in double quotes Change that code to this:

            echo '

            • '.$err.'

            Notice how I use double quotes for the HTML attribute and single quotes for the PHP string? That was intentional and should be considered a best practice. Why? PHP parser supports interpolated strings, meaning you can use a PHP variable in a double quoted string, like this:

            $test = 'Some Value';
            echo "Hello world this is a variable: $test";

            The above would output something like: Hello world this is a variable: Some Value While this might seem cool (and it is handy in some circumstances) it should be a practice avoided like the plague. 1. It can lead to difficult to find bugs as it's not very explicit. 2. You incur a performance hit because PHP tokenizer needs to process double quoted strings By using single quoted strings instead od double inside PHP you save yourself from the above problems. Use concatenation, like you already do:

            echo 'This is a '.$test.' string';

            Or

            B Offline
            B Offline
            bschm78
            wrote on last edited by
            #5

            Thanks Hockey! Yes, I noticed after posting my php4 function that my 'valids' were missing the $s. Also, the help on the concatenation helped a lot. This was throwing me off more than anything. Thanks again! The form (up to the rest of my commented-out code) works great! :) Ben

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups