Jump to content

error meaning


mindapolis

Recommended Posts

What does this error mean? 

 

Notice: Undefined index: fname in /web/html/mediaservicesunlimited.com/contactUs.php on line 26

 

Should the php code go after the html ? 

<?php
require_once('functions.php');
databaseConnection();
error_reporting(-1);
ini_set('display_errors', 1);

if ($_POST)
    {
    $error = array();

    if (empty($_POST['fname']))
        {
        $error['fname'] = "<span class='error'>Please enter your first name.</span>";
        }
    if (empty($_POST['lname']))
        {
        $error['lname'] = "<span class='error'>Please enter your last name.</span>";
        }

    if (!count($error))

        {        //Do something
        die("Do Something here");
        }
    }
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$orgName = $_POST['orgName'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$confirmEmail = $_POST['confirmEmail'];
$projectOptions = $_POST['projectOptions'];
$projectOverview = $_POST['projectOverview'];
$year = $_POST['year'];
$services=array('social media', 'web content management', 'marketing material creation', 'SEO', 'video editing' , 'web design');
mysql_select_db("www_mediaservicesunlimited_com");
mysql_query("INSERT INTO clients (fname, lname, orgName, address, city, state, zipcode, phone, fax, email, confirmEmail, projectOptions, projectOverview, year)", 
		"VALUES  ('$fname', '$lname', '$orgName', '$address', '$city', '$state', $zipcode', '$phone', '$fax', '$email', '$confirmEmail', '$projectOptions', '$projectOverview', '$year' )" ); 

?>
<!doctype html>
<html>
<head>
      <meta charset="utf-8">
      <style type="text/css">
		#contactForm label, #contactForm input {
			margin-bottom:20px;
		  }
      </style>
      <title>Untitled Document</title>
   </head>
   <body>
   		<div id="contactForm">  
         <form method="post">
         <label>  
           <label for "fname"> First Name:</label>
                  <input id = "fname" type="text" name="fname" size="15" value ="<?php echo !empty($_POST['fname']) ? $_POST['fname'] : '';?>" >	<?php echo !empty($error['fname']) ? $error['fname'] : '';?>
			<label for "lname">Last Name:</label>
                  <input type="text" name="lname" size="20"><?php echo !empty($error['lname']) ? $error['lname'] : '';?>
			<label for="orgName">Organization's Name:</label>
			<input type="text" name="orgName" maxlength="50">
			</label><br />
			<label> <!--new row -->   
				<label for "address">Street Address: </label>
                  <input id = "address" type="text" name="address" size="15" maxlength="50">
				<label id="city">City: </label>
                  <input id = "city" type="text" name="city" size="10" maxlength="25">
                <label  for "state"> State:	</label>
                  <select id  = "state" name = "state"  value="">
                     <option value ="Please choose a state">
                        Please choose a state
                     </option>
                     <?php states($state); ?>
                  </select>
         		<label for "zipcode">Zipcode:</label>
                  <input id = "zipcode" type="number" name="zipcode" size="5" maxlength="5">
             </label><br />
		 	<label> <!--new row -->
              <label for "phone">  Phone Number:(including area code)  <br /> </label>
                  <input type="text" name="phone" size="10" maxlength="10">  
            <label for="fax">Fax Number: (including area code)
</label>    	
                  <input type="text" name="fax" size="10" maxlength="10">
			</label><br />
			<label> <!--new row-->
            	<label for="email">Email: </label> 
                  <input type="text" id = "email" name="email" />
				<label for="confirmEmail"> Confirm Email:</label>
                  <input type="text" id = "confirmEmail" name="ConfirmEmail" />
</label><br />
			<label> <!--new row -->
            <label for "projectChoices"> What would you like help with?  <br /></label>
             <table id="projectOptions">
                     <tr span=2>
                        <td><input type="checkbox" name="SocialMedia">Social Media </td>
                        <td><input type="checkbox" name="WebContentManagement">Web Content Management 	</td>
                     </tr>
                     <tr>
                        <td><input type="checkbox" name="MarketingMaterials">Marketing Material Creation  </td>
                        <td><input type="checkbox" name="SEO">SEO (Search Engine Optimization) 	</td>
                     </tr>
                     <tr>
                        <td><input type="checkbox" name="VideoEditing"> Video Editing  </td>
                        <td><input type="checkbox" name="WebDesign">Web Design  	</td>
                     </tr>
                  </table>
			<label for="projectOverview"> Overview about the project:</label><textarea rows="5" cols="10"></textarea>  <br />
 If you are not a robot, what year is it? <input type="text" name="year" size="4" maxlength="4"><br />
<input type="submit" name="submit" value="Contact Me!">
<input type="reset">
         </form>
		</div>
   </body>
</html> 
Link to comment
Share on other sites

Are trying to use a variable that isn't set.

 

php logic first and html display later

check for if the $_POST['submit'] is set

do mysql queries within the check for $_POST['submit'] and only if meets your requirements

check if particular POST values are set, filter/sanitize/escape as needed

never trust user input directly into queries, escape them first

define variables outside the check for $_POST['submit'] if to reuse them back into form

 

mysql_* functions are deprecated, should use mysqli_* and mysqli_real_escape_string or pdo and prepared statements

Edited by QuickOldCar
  • Like 1
Link to comment
Share on other sites

Besides the severe problems already pointed out by QuickOldCar, your $foo = $_POST['foo'] stuff is executed in any case, because it's outside of the if ($_POST) check.

 

Using if (!count($error)) to check for the presence of errors also looks wrong to me. Shouldn't that be if (count($error))? Or better yet: Use a less weird form like if (count($error) > 0).

Link to comment
Share on other sites

I added the isset function to see if the form was submitted, but that didn't help.  if I could get a little more help that would be much appreciated. 

<?php
require_once('functions.php');
databaseConnection();
error_reporting(-1);
ini_set('display_errors', 1);

if ($_POST)
    {
    $error = array();

    if (empty($_POST['fname']))
        {
        $error['fname'] = "<span class='error'>Please enter your first name.</span>";
        }
    if (empty($_POST['lname']))
        {
        $error['lname'] = "<span class='error'>Please enter your last name.</span>";
        }

    if (!count($error))

        {        //Do something
        die("Do Something here");
        }
    }
	if(isset($_POST['submit'])) {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$orgName = $_POST['orgName'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$confirmEmail = $_POST['confirmEmail'];
$projectOptions = $_POST['projectOptions'];
$projectOverview = $_POST['projectOverview'];
$year = $_POST['year'];
$services=array('social media', 'web content management', 'marketing material creation', 'SEO', 'video editing' , 'web design');
	}
mysql_select_db("www_mediaservicesunlimited_com");
mysql_query("INSERT INTO clients (fname, lname, orgName, address, city, state, zipcode, phone, fax, email, confirmEmail, projectOptions, projectOverview, year)", 
		"VALUES  ('$fname', '$lname', '$orgName', '$address', '$city', '$state', $zipcode', '$phone', '$fax', '$email', '$confirmEmail', '$projectOptions', '$projectOverview', '$year' )" ); 

?>
<!doctype html>
<html>
<head>
      <meta charset="utf-8">
      <style type="text/css">
		#contactForm label, #contactForm input {
			margin-bottom:20px;
		  }
      </style>
      <title>Untitled Document</title>
   </head>
   <body>
   	
    	<div id="contactForm">  
         <form method="post">
         <label>  
           <label for "fname"> First Name:</label>
                  <input id = "fname" type="text" name="fname" size="15" value ="<?php echo !empty($_POST['fname']) ? $_POST['fname'] : '';?>" >	<?php echo !empty($error['fname']) ? $error['fname'] : '';?>
			<label for "lname">Last Name:</label>
                  <input type="text" name="lname" size="20"><?php echo !empty($error['lname']) ? $error['lname'] : '';?>
			<label for="orgName">Organization's Name:</label>
			<input type="text" name="orgName" maxlength="50">
			</label><br />
			<label> <!--new row -->   
				<label for "address">Street Address: </label>
                  <input id = "address" type="text" name="address" size="15" maxlength="50">
				<label id="city">City: </label>
                  <input id = "city" type="text" name="city" size="10" maxlength="25">
                <label  for "state"> State:	</label>
                  <select id  = "state" name = "state"  value="">
                     <option value ="Please choose a state">
                        Please choose a state
                     </option>
                     <?php states($state); ?>
                  </select>
         		<label for "zipcode">Zipcode:</label>
                  <input id = "zipcode" type="number" name="zipcode" size="5" maxlength="5">
             </label><br />
		 	<label> <!--new row -->
              <label for "phone">  Phone Number:(including area code)  <br /> </label>
                  <input type="text" name="phone" size="10" maxlength="10">  
            <label for="fax">Fax Number: (including area code)
</label>    	
                  <input type="text" name="fax" size="10" maxlength="10">
			</label><br />
			<label> <!--new row-->
            	<label for="email">Email: </label> 
                  <input type="text" id = "email" name="email" />
				<label for="confirmEmail"> Confirm Email:</label>
                  <input type="text" id = "confirmEmail" name="ConfirmEmail" />
</label><br />
			<label> <!--new row -->
            <label for "projectChoices"> What would you like help with?  <br /></label>
             <table id="projectOptions">
                     <tr span=2>
                        <td><input type="checkbox" name="SocialMedia">Social Media </td>
                        <td><input type="checkbox" name="WebContentManagement">Web Content Management 	</td>
                     </tr>
                     <tr>
                        <td><input type="checkbox" name="MarketingMaterials">Marketing Material Creation  </td>
                        <td><input type="checkbox" name="SEO">SEO (Search Engine Optimization) 	</td>
                     </tr>
                     <tr>
                        <td><input type="checkbox" name="VideoEditing"> Video Editing  </td>
                        <td><input type="checkbox" name="WebDesign">Web Design  	</td>
                     </tr>
                  </table>
			<label for="projectOverview"> Overview about the project:</label><textarea rows="5" cols="10"></textarea>  <br />
 If you are not a robot, what year is it? <input type="text" name="year" size="4" maxlength="4"><br />
<input type="submit" name="submit" value="Contact Me!">
<input type="reset">
         </form>
		</div>
   </body>
</html> 
Link to comment
Share on other sites

Okayyyy... the error is line 26 which is    $fname = $_POST['fname'];

 

The error is telling you that the variable  $_POST['fname'] does not exist by the time you get down to this line

 

Your curly brackets around the     if($_POST) { ...}  section of code end before line 26, so perhaps you need the closing bracket around the whole section of code like this

 

 

if ($_POST)
{
... ALL your PHP in here, because otherwise it will get executed anyway regardless of POST data or not
}

 

 

If that doesn't work, try changing the line to   if (!empty($_POST))

Link to comment
Share on other sites

To add to it, your call to mysql_query() - which you shouldn't be using anyway; see QuickOldCar's note about Mysqli or PDO - is malformed. You're sending the second half of your query as the second parameter to the function. The second parameter of mysql_query() is an optional connection identifier. Also, don't use mysql_*.

  • Like 1
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.