Jump to content

Variables errors


spanner206

Recommended Posts

ive got 3 errors which i have no clue what the problems are all 3 of them are related to near enough the same thing 1 of them is CompanyNameerr variable and the other to is CompanyName its confusing the hell out of me cause im pretty sure ive declared these variable.

( ! ) Notice: Undefined index: CompanyName in C:\wamp\www\AddLeads\addleads2.php on line 37

 

( ! ) Notice: Undefined variable: CompanyNameErr in C:\wamp\www\AddLeads\addleads2.php on line 45

 

 

( ! ) Notice: Undefined variable: CompanyName in C:\wamp\www\AddLeads\addleads2.php on line 68

 

 
and heres the code i used
 
<!DOCTYPE HTML> 
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body> 
<?
$con = mysqli_connect("localhost","root","","nib");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"INSERT INTO tbl_club_contacts (CompanyName, FirstName, Address1, Address2, Area, City);
VALUES ('nelsons', 'luke', '', 'IT', '5 HIGHFIELD ROAD', 'LITTLEOVER', 'DERBY')");
 
 
mysqli_close($con);
 
 
// define variables and set to empty values
$companynameErr = $FirstNameErr = $Address1Err = $Address2Err = $AreaErr = $CityErr = "";
$companyname = $FirstName = $Address1 = $Address2 = $Area = $City = "";
 
if ($_SERVER["REQUEST_METHOD"] == "POST")
 
$allValid = true;
{
$allValid = false;
}
if($allValid) {
// connect to db, create query, execute query
}
 
if($_POST['CompanyName']==null || $_POST['CompanyName']=="") {
$allValid = false;
}
?>
<form action="insertaddleads.php" method="post">
<p><span class="error">* required field.</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 
   CompanyName: <input type="text" name="companyname">
   <span class="error">* <?php echo $CompanyNameErr;?></span>
   <br><br>
   FirstName: <input type="text" name="firstname">
   <span class="error">* <?php echo $FirstNameErr;?></span>
   <br><br>
   Address 1: <input type="text" name="address1">
   <span class="error">* <?php echo $Address1Err;?></span>
   <br><br>
   Address 2: <input type="text" name="address2">
   <span class="error">* <?php echo $Address2Err;?></span>
   <br><br>
   Area: <input type="text" name="area">
   <span class="error">* <?php echo $AreaErr;?></span>
   <br><br>
   City: <input type="text" name="city">
   <span class="error">* <?php echo $CityErr;?></span>
   <br><br>
   
   <input type="submit" name="submit" value="Submit"> 
 
</form>
 
<?
echo $CompanyName;
echo "<br>";
echo $FirstName;
echo "<br>";
echo $Address1;
echo "<br>";
echo $Address2;
echo "<br>";
echo $Area;
echo "<br>";
echo $City;
echo "<br>";
?>
<?php
foreach($_POST as $fieldName=>$fieldValue) {
     if($fieldValue == '') {
          print "<div>$fieldName is blank</div>";
     }
}
?>
</body>
</html>
 
Link to comment
https://forums.phpfreaks.com/topic/283649-variables-errors/
Share on other sites

yh i changed them but its still showing the error

 
<!DOCTYPE HTML> 
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body> 
<?
$con = mysqli_connect("localhost","root","","nib");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"INSERT INTO tbl_club_contacts (CompanyName, FirstName, Address1, Address2, Area, City);
VALUES ('nelsons', 'luke', '', 'IT', '5 HIGHFIELD ROAD', 'LITTLEOVER', 'DERBY')");
 
 
mysqli_close($con);
 
 
// define variables and set to empty values
$companynameErr = $FirstNameErr = $Address1Err = $Address2Err = $AreaErr = $CityErr = "";
$companyname = $FirstName = $Address1 = $Address2 = $Area = $City = "";
 
if ($_SERVER["REQUEST_METHOD"] == "POST")
 
$allValid = true;
{
$allValid = false;
}
if($allValid) {
// connect to db, create query, execute query
}
 
if($_POST['companyname']==null || $_POST['companyname']=="")
{
$allValid = false;
}
?>
<form action="insertaddleads.php" method="post">
<p><span class="error">* required field.</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 
<table>
   <tr>
<td>CompanyName: <input type="text" name="companyname"></td> 
<td><span class="error">* <?php echo $companynameErr;?></span></td>
  </tr>
   <tr>
<td>FirstName: <input type="text" name="firstname"></td>
<td> <span class="error">* <?php echo $FirstNameErr;?></span></td>
   </tr>
   Address 1: <input type="text" name="address1">
   <span class="error">* <?php echo $Address1Err;?></span>
   <br><br>
   Address 2: <input type="text" name="address2">
   <span class="error">* <?php echo $Address2Err;?></span>
   <br><br>
   Area: <input type="text" name="area">
   <span class="error">* <?php echo $AreaErr;?></span>
   <br><br>
   City: <input type="text" name="city">
   <span class="error">* <?php echo $CityErr;?></span>
   <br><br>
   
   <input type="submit" name="submit" value="Submit"> 
 
</form>
 
<?
echo $companyname;
echo "<br>";
echo $FirstName;
echo "<br>";
echo $Address1;
echo "<br>";
echo $Address2;
echo "<br>";
echo $Area;
echo "<br>";
echo $City;
echo "<br>";
?>
<?php
foreach($_POST as $fieldName=>$fieldValue) {
     if($fieldValue == '') {
          print "<div>$fieldName is blank</div>";
     }
}
?>
</body>
</html>
Link to comment
https://forums.phpfreaks.com/topic/283649-variables-errors/#findComment-1457204
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.