creativkook Posted March 28, 2007 Share Posted March 28, 2007 I've never had this problem before. For some reason (I'm using version 4.1 of PHP I believe) I have some of my variables coming back to me. Not all, just a few. Here are the errors I'm getting: Notice: Undefined index: cofinancer1Amt in C:\Web\Plaid\addNew.php on line 39 Notice: Undefined index: cofinancer2Amt in C:\Web\Plaid\addNew.php on line 40 Notice: Undefined index: cofinancer3Amt in C:\Web\Plaid\addNew.php on line 41 Notice: Undefined index: cofinancer4Amt in C:\Web\Plaid\addNew.php on line 42 Notice: Undefined index: cofinancer5Amt in C:\Web\Plaid\addNew.php on line 43 Notice: Undefined index: cofinancer6Amt in C:\Web\Plaid\addNew.php on line 44 Notice: Undefined index: environAidType in C:\Web\Plaid\addNew.php on line 50 Here's my code. See if you can find anything wrong. I don't know what I'm missing. <?php require("_sessionheader.php"); require("dbheader.php"); $donorNameQueries = mysql_query("SELECT * FROM donorname"); $donorUmbrellaQueries = mysql_query("SELECT * FROM donorumbrella"); $recipientQueries = mysql_query("SELECT * FROM recipient"); $currencyQueries = mysql_query("SELECT * FROM currency"); $aidTypeQueries = mysql_query("SELECT * FROM aidtype"); $environAidTypeQueries = mysql_query("SELECT * FROM environaidtype"); $healthImpactQueries = mysql_query("SELECT * FROM healthimpact"); if(isset($_POST['submit'])) { $year = $_POST['year']; $donorName = $_POST['donorName']; $donorUmbrella = $_POST['donorUmbrella']; $recipient = $_POST['recipient']; $loanAmount = $_POST['loanAmount']; $currency = $_POST['currency']; $cofinancer1 = $_POST['cofinancer1']; $cofinancer2 = $_POST['cofinancer2']; $cofinancer3 = $_POST['cofinancer3']; $cofinancer4 = $_POST['cofinancer4']; $cofinancer5 = $_POST['cofinancer5']; $cofinancer6 = $_POST['cofinancer6']; $cofinancer1Amt = $_POST['cofinancer1Amt']; $cofinancer2Amt = $_POST['cofinancer2Amt']; $cofinancer3Amt = $_POST['cofinancer3Amt']; $cofinancer4Amt = $_POST['cofinancer4Amt']; $cofinancer5Amt = $_POST['cofinancer5Amt']; $cofinancer6Amt = $_POST['cofinancer6Amt']; $projectTitle = $_POST['projectTitle']; $shortDescription = $_POST['shortDescription']; $longDescription = $_POST['longDescription']; $comment = $_POST['comment']; $aidType = $_POST['aidType']; $environAidType = $_POST['environAidType']; $healthImpact = $_POST['healthImpact']; $crsCode1 = $_POST['crsCode1']; $crsCode2 = $_POST['crsCode2']; $crsCode3 = $_POST['crsCode3']; $crsCode4 = $_POST['crsCode4']; $crsCode5 = $_POST['crsCode5']; $crsCode6 = $_POST['crsCode6']; if($longDescription == NULL) { $longDescExists = "no"; } else { $longDescExists = "yes"; } mysql_query("INSERT INTO plaiddata (year, donorName, donorUmbrella, recipientPlaidName, loanAmount, currency, cofinancer1, cofinancer2, cofinancer3, cofinancer4, cofinancer5, cofinancer6, cofinancer1Amt, cofinancer2Amt, cofinancer3Amt, cofinancer4Amt, cofinancer5Amt, cofinancer6Amt, projectTitle, shortDesc, longDescExists, longDesc, comment, aidType, environAidType, healthImpact, crs1Code1, crs1Code2, crs1Code3, crs1Code4, crs1Code5, crs1Code6) VALUES ('$year', '$donorName', '$donorUmbrella', '$recipient', '$loanAmount', '$currency', '$cofinancer1', '$cofinancer2', '$cofinancer3', '$cofinancer4', '$cofinancer5', '$cofinancer6', '$cofinancer1Amt', '$cofinancer2Amt', '$cofinancer3Amt', '$cofinancer4Amt', '$cofinancer5Amt', '$cofinancer6Amt', '$projectTitle', '$shortDescription', '$longDescExists', '$longDescription', '$comment', '$aidType', '$environAidType', '$healthImpact', '$crsCode1', '$crsCode2', '$crsCode3', '$crsCode4', '$crsCode5', '$crsCode6')"); echo(mysql_error()); //header("location: success.php"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Insert Project Information</title> </head> <body> <form method="post" action="<? $_SERVER['PHP_SELF']; ?>"> <p>Year: <input type="text" name="year" /></p> <p>Donor Name: <select name="donorName"> <?php while($donorNameQuery = mysql_fetch_array($donorNameQueries)) { echo("<option value='$donorNameQuery[donorName]'>$donorNameQuery[donorName]</option>"); } ?> </select> </p> <p>Donor Umbrella: <select name="donorUmbrella"> <?php while($donorUmbrellaQuery = mysql_fetch_array($donorUmbrellaQueries)) { echo("<option value='$donorUmbrellaQuery[donorUmbrella]'>$donorUmbrellaQuery[donorUmbrella]</option>"); } ?> </select></p> <p>Recipient: <select name="recipient"> <?php while($recipientQuery = mysql_fetch_array($recipientQueries)) { echo("<option value='$recipientQuery[recipient]'>$recipientQuery[recipient]</option>"); } ?> </select></p> <p>Loan Amount: <input type="text" name="loanAmount" /></p> <p>Currency: <select name="currency"> <?php while($currencyQuery = mysql_fetch_array($currencyQueries)) { echo("<option value='$currencyQuery[currency]'>$currencyQuery[currency]</option>"); } ?> </select></p> <p>Cofinancer 1: <input type="text" name="cofinancer1" /> Cofinancer 1 amount: <input type="text" name="cofinancer1amount" /></p> <p>Cofinancer 2: <input type="text" name="cofinancer2" /> Cofinancer 2 amount: <input type="text" name="cofinancer2amount" /></p> <p>Cofinancer 3: <input type="text" name="cofinancer3" /> Cofinancer 3 amount: <input type="text" name="cofinancer3amount" /></p> <p>Cofinancer 4: <input type="text" name="cofinancer4" /> Cofinancer 4 amount: <input type="text" name="cofinancer4amount" /></p> <p>Cofinancer 5: <input type="text" name="cofinancer5" /> Cofinancer 5 amount: <input type="text" name="cofinancer5amount" /></p> <p>Cofinancer 6: <input type="text" name="cofinancer6" /> Cofinancer 6 amount: <input type="text" name="cofinancer6amount" /></p> <p>Project title: <input type="text" name="projectTitle" /></p> <p>Short description: <textarea name="shortDescription" cols="45" rows="3"></textarea></p> <p>Long description: <textarea name="longDescription" cols="45" rows="5"></textarea></p> <p>Comment: <input type="text" name="comment" /></p> <p>Aid Type: <select name="aidType"> <?php while($aidTypeQuery = mysql_fetch_array($aidTypeQueries)) { echo("<option value='$aidTypeQuery[aidType]'>$aidTypeQuery[aidType]</option>"); } ?> </select></p> <p>Environmental Aid Type: <select name="environmentalAidType"> <?php while($environAidTypeQuery = mysql_fetch_array($environAidTypeQueries)) { echo("<option value='$environAidTypeQuery[environAidType]'>$environAidTypeQuery[environAidType]</option>"); } ?> </select></p> <p>Health Impact: <select name="healthImpact"> <?php while($healthImpactQuery = mysql_fetch_array($healthImpactQueries)) { echo("<option value='$healthImpactQuery[healthImpact]'>$healthImpactQuery[healthImpact]</option>"); } ?> </select></p> <p>CRS Code [1] <input name="crsCode1" maxlength="5" type="text" /></p> <p>CRS Code [2] <input name="crsCode2" maxlength="5" type="text" /></p> <p>CRS Code [3] <input name="crsCode3" maxlength="5" type="text" /></p> <p>CRS Code [4] <input name="crsCode4" type="text" maxlength="5" /></p> <p>CRS Code [5] <input name="crsCode5" type="text" maxlength="5" /></p> <p>CRS Code [6] <input name="crsCode6" type="text" maxlength="5" /></p> <p><input type="submit" name="submit" value="Sumbit" /></p> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
per1os Posted March 28, 2007 Share Posted March 28, 2007 In order to avoid that you need to check if the post variable isset. IE: $crsCode6 = (isset($_POST['crsCode6'])?$_POST['crsCode6']:null; That will get rid of those notices. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.