Search the Community
Showing results for tags 'errorsundefined index'.
-
hi all ive been trying to do this validation thing for ages now where i want to check if the field is empty and if so ask them to fill it and then once its filled go to the next page but ive been having problems with this i had loads of errors but i got it down to one which im confused to hell about and even once i get this error out the way i still don't no if it does validate please help. <!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") 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 border = "0"> <tr> <td>companyname:</td> <td><input type="text" name="companyname"> <span class="error">* <?php echo $companynameErr;?></span></td> </tr> <tr> <td>FirstName:</td> <td><input type="text" name="firstname"> <span class="error">* <?php echo $FirstNameErr;?></span></td> </tr> <tr> <td>Address 1:</td> <td><input type="text" name="address1"> <span class="error">* <?php echo $Address1Err;?></span></td> </tr> <tr> <td>Address 2:</td><td><input type="text" name="address2"> <span class="error">* <?php echo $Address2Err;?></span></td> </tr> <tr> <td>Area:</td><td><input type="text" name="area"> <span class="error">* <?php echo $AreaErr;?></span></td> </tr> <tr> <td>City:</td> <td><input type="text" name="city"> <span class="error">* <?php echo $CityErr;?></span></td> </tr> <tr> <td><input type="submit" name="submit" value="Submit"></td> </tr> </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 $companyname=>$companyname) { if($fieldValue == '') { print "<div>$companyname is blank</div>"; } } ?> </body> </html> this is the second page <?php $con=mysqli_connect("localhost","root","","nib"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="INSERT INTO tbl_club_contacts (CompanyName, FirstName, Address1, Address2, Area, City) VALUES ('$_POST[test]','$_POST[firstname]','$_POST[address1]','$_POST[address2]','$_POST[area]','$_POST[city]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "record added"; mysqli_close($con); ?> <html> <body> <form action="addleads2.php" method="post"> <input type="submit", value = "go back"> </form> </body> </html> and then the error code ive been getting ( ! ) Notice: Undefined index: companyname in C:\wamp\www\AddLeads\addleads2.php on line 30
- 6 replies
-
- errorsundefined index
- row 30
-
(and 2 more)
Tagged with: