Jump to content

PHP error when when using echo


boblan66

Recommended Posts

Well, when you get one thing solved, another pops up its ugly head. Here's the latest error.

 

Parse error: syntax error, unexpected T_STRING in /home/taft65/public_html/memProtest.php on line 205

 

Code:


<?php
// if $errors is not empty, the form must have failed one or more validation
// tests. Loop through each and display them on the page for the user

  if (!empty($errors))
  {

line 205-->   echo "<div style='width:100%;'>Please fix the following errors:\n<ul>";
   
    foreach ($errors as $error)
    echo "<li>$error</li>\n";
    echo "</ul></div>";
   }
   
   if (!empty($message))
   {
     echo "<div class='notify'>$success_message</div>";
    }
?>

 

I know my eyes aren't great and I'm typing with one finger, but I'll be darn if I see an error.

 

 

Link to comment
Share on other sites

Here is the code you requested. This is another concern - I have created a rester table from which I grab data to populate some areas of this page. My concern is, do I have the open db in the correct place?

 


<?php
                                                        
// Place the results in the proper locations.
		   $firstname=$_POST['firstname'];
                            $lastname=$_POST['lastname'];
                            $email=$_POST['email'];
                            
		   $dbhost = 'localhost';
                           $dbuser = 'taft_boblan';
                           $dbpass = 'taft65_8e83bed3';
		   $dbname = 'taft65_members';

                           $conn = mysql_connect($dbhost, $dbuser, $dbpass) 
			or die ('Unable to connect with Alumni Database. Try again later.);
                                                        
                            mysql_select_db($dbname);

                            //create a SQL statement to obtain data from table register 
		   // populate fields id, email, firstname, and lastname from table register


    			  // if $errors is not empty, the form must have failed one or more validation
		  // tests. Loop through each and display them on the page for the user
			if (!empty($errors))
			{

    Error--->     echo "<div style='width:100%;'>Please fix the following errors:\n<ul>";
                                foreach ($errors as $error)
                                echo "<li>$error</li>\n";
                                echo "</ul></div>";
                               }
                               if (!empty($message))
                              {
                               echo "<div class='notify'>$success_message</div>";
                              }

Link to comment
Share on other sites

Look at your code now that it's highlighted.  The error is quite literally as plain as day.

 

I recommend downloading Eclipse with the PHP editing plugin, it will highlight your code for you.

 

Also, the curl braces for your foreach statement aren't required, but they're recommended.

 

-Dan

Link to comment
Share on other sites

Thank you for the assist. I should have spotted that. No excuse but at 68, my eyes arn't what they use to be. I'm going to enlarge the test with shift +.

 

I'll check Eclipse out and see if that helps. NuSphere cost $200, I hope this is less.

 

Thanks again for putting up with an old guy, but young at heart.

Link to comment
Share on other sites

ManiacDan;

 

I pasted the code on my form and made mods to the referencing the form name etc. However I came up with some interesting problems, when I ran the form. I attached the form to this reply for your review. Here are my questions:

 

1. I noticed that the script was placed directly after the  closing form tag, so that's where I placed it in my form. Correct?

 

2. The radio buttons will not change state. If I select male and decide to change it to female, both buttons are selected. You can't select one. This is the same for any input field that has a radio button, not just the sex buttons.

 

I tried renaming the test file that I'm using to madian_name.html and it changes to: madian_name.html.txt. is this something to do with javascript?

 

I really appreciate your assistance. Believe it or not, I'm learning something.

 

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

1)  I have no idea what you mean.  Generally the PHP code is the beginning of the file, and the HTML is the end.  It's not a rule per se, but it allows your PHP script to generate errors and default values for your HTML.

 

2)  Name the radio buttons the same NAME and they will be grouped together.  You have no named for your inputs (any of them) so your form will never work.

 

Spelling:  Maiden, Personal.

 

3)  I don't know what you're trying to do with renaming things, but this is a breakdown of the technology you're using:

HTML - A completely client-side markup system, it makes things look pretty and formats text.  It also generates "dumb" forms and inputs for the user to type into.  HTML can perform NO actions.

CSS - An offshoot of HTML, CSS handles stying HTML elements.  CSS has "rules" that allow you to make fake dynamics on your site, mouseover actions and the like.  Not a programming language.  No actual actions.

JavaScript - A client-side programming language, JavaScript executes on the USER'S computer, not on your server.  Javascript interacts with the current page as it appears on the user's computer. JavaScript has access to what the user types as they type it, but is insecure because the user can modify it.  JavaScript should be used to improve the user experience but not replace your server.  AJAX, which you're not using, is a subset of javascript that allows you to make asynchronous calls from JavaScript to your webserver to retrieve live information without reloading the page.

PHP - PHP is a server-side language.  It runs on your server,  NOT the user's computer.  The user must make an individual request for every PHP page you run.  PHP pages start, run, output, then die before the user sees anything.  PHP pages are ignorant of each other and have no idea if the user is visiting for the first time or the millionth time.  You must build session tracking into your site if you wish to maintain state.

 

As for your file itself, you're using a custom rules-based validation parser (and you appear to be doing it wrong, the include might go after the rules), so I can't help much there. 

 

-Dan

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.