croix Posted May 23, 2007 Share Posted May 23, 2007 I have a site that has been running fine on a windows server / access database. I am in the process of moving to a new linux server with mysql. On the site, I have an admin page, that has functions to add / delete / update / edit records from the database. I have already migrated the tables and data, and I have gotten the add record function to work on the new setup. Now I am working on the edit record part, and I am getting this error: Notice: Undefined index: firstname etc listing all of my variables. Google tells me that this problem usually occurs when the code is not calling all of the variables, but I dont think thats the case in my situation. Here is my code: <?php ini_set('error_reporting', E_ALL); ini_set('display_errors', 'On'); include("dbconnection.php"); $id=$_GET['customerID']; $query = "SELECT * FROM customers WHERE customerID= $id "; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { $firstname = $row['firstname']; $lastname = $row['lastname']; $address1 = $row['address1']; $address2 = $row['address2']; $city = $row['city']; $state = $row['state']; $zip = $row['zip']; $email = $row['email']; $referral = $row['referral']; $promo = $row['promo']; $lubricant = $row['lubricant']; $results = " <div id=\"table1\"><center> <form action=\"cust_update.php\" method=\"post\"> <div align=\"left\"><input type=\"hidden\" name=\"customerID\" value=\"$id\"> <table width=349 height=\"91\" border=\"0\"> <tr> <td width=174 height=\"81\"><p>First Name:<br> <input type=\"text\" name=\"firstname\" value=\"$firstname\"> </p> </td> <td width=165><p>Last Name:<br> <input type=\"text\" name=\"lastname\" value=\"$lastname\"> </p> </td> </tr> <tr> <td>Address:<br> <input type=\"text\" name=\"address1\" value=\"$address1\"></td> <td>Address 2:<br> <input type=\"text\" name=\"address2\" value=\"$address2\"></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td><p></p> <p>City:<br> <input type=\"text\" name=\"city\" value=\"$city\"> </p></td> <td><p></p> <p>State:<br> <input type=\"text\" name=\"state\" value=\"$state\"> </p></td> </tr> <tr> <td><p></p> <p>Zip:<br> <input type=\"text\" name=\"zip\" value=\"$zip\"> </p></td> <td></td> </tr> <tr> <td><p></p> <p>Email:<br> <input type=\"text\" name=\"email\" value=\"$email\"> </p></td> <td></td> </tr> <tr> <td><p></p> <p>Referral:<br> <input type=\"text\" name=\"referral\" value=\"$referral\"> </p></td> <td></td> </tr> <tr> <td><p></p> <p>Promo:<br> <input type=\"text\" name=\"promo\" value=\"$promo\"> </p></td> <td><p></p> <p>Lubricant:<br> <input type=\"text\" name=\"lubricant\" value=\"$lubricant\"> </p></td> </tr> <tr> <td></td> <td></td> </tr> </table> <p><br> <input type=\"Submit\" value=\"Update\"> </p></form><br> <form action=\"cust_delete.php\" method=\"post\"> <input type=\"hidden\" name=\"customerID\" value=\"$id\"> <input type=\"submit\" value=\"Delete Record\"> </form> </div> </center> </div> "; } ?> anyone see something that catches thier eye? Quote Link to comment https://forums.phpfreaks.com/topic/52722-notice-undefined-index-problem-access-to-mysql-conversion/ Share on other sites More sharing options...
per1os Posted May 23, 2007 Share Posted May 23, 2007 Remember that PHP is cAsESenSitIvE especially in array calls. Access stores column names generally as uppercase, I would try this instead: <?php ini_set('error_reporting', E_ALL); ini_set('display_errors', 'On'); include("dbconnection.php"); $id=$_GET['customerID']; $query = "SELECT * FROM customers WHERE customerID= $id "; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { // convert all column names from access to lowercase and remove any spaces foreach ($row as $key => $val) { $key = str_replace(" ", "", strtolower($key)); $row[$key] = $val; } $firstname = $row['firstname']; $lastname = $row['lastname']; $address1 = $row['address1']; $address2 = $row['address2']; $city = $row['city']; $state = $row['state']; $zip = $row['zip']; $email = $row['email']; $referral = $row['referral']; $promo = $row['promo']; $lubricant = $row['lubricant']; $results = " <div id=\"table1\"><center> <form action=\"cust_update.php\" method=\"post\"> <div align=\"left\"><input type=\"hidden\" name=\"customerID\" value=\"$id\"> <table width=349 height=\"91\" border=\"0\"> <tr> <td width=174 height=\"81\"><p>First Name:<br> <input type=\"text\" name=\"firstname\" value=\"$firstname\"> </p> </td> <td width=165><p>Last Name:<br> <input type=\"text\" name=\"lastname\" value=\"$lastname\"> </p> </td> </tr> <tr> <td>Address:<br> <input type=\"text\" name=\"address1\" value=\"$address1\"></td> <td>Address 2:<br> <input type=\"text\" name=\"address2\" value=\"$address2\"></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td><p></p> <p>City:<br> <input type=\"text\" name=\"city\" value=\"$city\"> </p></td> <td><p></p> <p>State:<br> <input type=\"text\" name=\"state\" value=\"$state\"> </p></td> </tr> <tr> <td><p></p> <p>Zip:<br> <input type=\"text\" name=\"zip\" value=\"$zip\"> </p></td> <td></td> </tr> <tr> <td><p></p> <p>Email:<br> <input type=\"text\" name=\"email\" value=\"$email\"> </p></td> <td></td> </tr> <tr> <td><p></p> <p>Referral:<br> <input type=\"text\" name=\"referral\" value=\"$referral\"> </p></td> <td></td> </tr> <tr> <td><p></p> <p>Promo:<br> <input type=\"text\" name=\"promo\" value=\"$promo\"> </p></td> <td><p></p> <p>Lubricant:<br> <input type=\"text\" name=\"lubricant\" value=\"$lubricant\"> </p></td> </tr> <tr> <td></td> <td></td> </tr> </table> <p><br> <input type=\"Submit\" value=\"Update\"> </p></form><br> <form action=\"cust_delete.php\" method=\"post\"> <input type=\"hidden\" name=\"customerID\" value=\"$id\"> <input type=\"submit\" value=\"Delete Record\"> </form> </div> </center> </div> "; } ?> If that does not work, do a var_dump on $row and see what the column names are IE: <?php ini_set('error_reporting', E_ALL); ini_set('display_errors', 'On'); include("dbconnection.php"); $id=$_GET['customerID']; $query = "SELECT * FROM customers WHERE customerID= $id "; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { echo var_dump($row), "<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52722-notice-undefined-index-problem-access-to-mysql-conversion/#findComment-260297 Share on other sites More sharing options...
croix Posted May 24, 2007 Author Share Posted May 24, 2007 that did the trick Frost110.... Thanks! However, it leads me to a new issue.... with my header. Record Updated! Warning: Cannot modify header information - headers already sent by (output started at /home/sliquidc/public_html/protected/cust_update.php:9) in /home/sliquidc/public_html/protected/cust_update.php on line 9 I went through pages and pages of google with this error, but everyones problem was related to CMS programs and extra whitespace being sent to the browser... but Line 9 for me is in the middle of a block of text... no whitespace.. <?php ini_set('error_reporting', E_ALL); ini_set('display_errors', 'On'); include("dbconnection.php"); $customerID=$_POST['customerID']; $firstname=$_POST['firstname']; $lastname=$_POST['lastname']; $address1=$_POST['address1']; $address2=$_POST['address2']; $city=$_POST['city']; $state=$_POST['state']; $zip=$_POST['zip']; $email=$_POST['email']; $referral=$_POST['referral']; $promo=$_POST['promo']; $lubricant=$_POST['lubricant']; $query="UPDATE customers SET firstname = '$firstname', lastname = '$lastname', address1 = '$address1', address2 = '$address2', city = '$city', state = '$state', zip = '$zip', email = '$email', referral = '$referral', promo = '$promo', lubricant = '$lubricant' WHERE customerID = $customerID"; $cur = mysql_query($query); if (!$cur) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } else { echo "Record Updated!"; } mysql_close($cnx); header("Refresh: 2; URL=http://69.89.31.71/~sliquidc/protected/cust_search.php"); echo " "; // NN4 requires that we output something... exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52722-notice-undefined-index-problem-access-to-mysql-conversion/#findComment-260811 Share on other sites More sharing options...
croix Posted May 24, 2007 Author Share Posted May 24, 2007 I jjust noticed this is happening on several pages and scripts... my admin login script generates this error, as well as 2 update scripts, and 2 delete scripts.... basically anything that uses a header to redirect. could this be server side? Quote Link to comment https://forums.phpfreaks.com/topic/52722-notice-undefined-index-problem-access-to-mysql-conversion/#findComment-260948 Share on other sites More sharing options...
per1os Posted May 24, 2007 Share Posted May 24, 2007 echo "Record Updated!"; That is the line that is killing you, you cannot have any output BEFORE a header call. Quote Link to comment https://forums.phpfreaks.com/topic/52722-notice-undefined-index-problem-access-to-mysql-conversion/#findComment-261173 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.