php - Undefined index errors -


when run code on browser, error message saying there undefined index. i've spent couple hours trying work don't know why keep getting same exact error.

<?php if ($dbsuccess) { $companyid = $_post['id'];  $prename = $_post['prename']; $companyname = $_post['name']; $regtype = $_post['regtype']; $streeta = $_post['streeta']; $streetb = $_post['streetb']; $streetc = $_post['streetc']; $town = $_post['town']; $county = $_post['county']; $postcode = $_post['postcode']; $country = $_post['country'];  }  $tcompany_sqlupdate = "update tcompany set "; $tcompany_sqlupdate .= "prename = ".$prename.", "; $tcompany_sqlupdate .= "name = ".$companyname.", "; $tcompany_sqlupdate .= "regtype = ".$regtype.", "; $tcompany_sqlupdate .= "streeta = ".$streeta.", "; $tcompany_sqlupdate .= "streetb = ".$streetb.", "; $tcompany_sqlupdate .= "streetc = ".$streetc.", "; $tcompany_sqlupdate .= "town = ".$town.", "; $tcompany_sqlupdate .= "county = ".$county.", "; $tcompany_sqlupdate .= "postcode = ".$postcode.", "; $tcompany_sqlupdate .= "country = ".$country.", "; $tcompany_sqlupdate .= "where id = ".$companyid." ";  if (empty($companyname)) {     echo '<span style="color: red;">cannot make company name empty.</span><br /><br />'; }   else {     echo '<span style="text-decoration: underline;">     sql statement</span>     <br />'.$tcompany_sqlupdate.'<br /><br />';      if (mysql_query($tcompany_sqlupdate)) {         echo 'used update company.<br /><br />';     }   else {         echo '<span style="color: red;">failed update company.</span><br /><br />';     } }  ?> 

error message:

notice: undefined index: id in c:\xampp\htdocs\forms\companyupdate.php on line 40  notice: undefined index: prename in c:\xampp\htdocs\forms\companyupdate.php on line 42  notice: undefined index: name in c:\xampp\htdocs\forms\companyupdate.php on line 43  notice: undefined index: regtype in c:\xampp\htdocs\forms\companyupdate.php on line 44  notice: undefined index: streeta in c:\xampp\htdocs\forms\companyupdate.php on line 45  notice: undefined index: streetb in c:\xampp\htdocs\forms\companyupdate.php on line 46  notice: undefined index: streetc in c:\xampp\htdocs\forms\companyupdate.php on line 47  notice: undefined index: town in c:\xampp\htdocs\forms\companyupdate.php on line 48  notice: undefined index: county in c:\xampp\htdocs\forms\companyupdate.php on line 49  notice: undefined index: postcode in c:\xampp\htdocs\forms\companyupdate.php on line 50  notice: undefined index: country in c:\xampp\htdocs\forms\companyupdate.php on line 51 

form:

<?php if ($dbsuccess) { $companyid = $_post['companyid'];  $tcompany_sqlselect = "select * "; $tcompany_sqlselect .= "from "; $tcompany_sqlselect .= "tcompany "; $tcompany_sqlselect .= "where id = ".$companyid." ";  $tcompany_sqlselect_query = mysql_query($tcompany_sqlselect);  while ($row = mysql_fetch_array($tcompany_sqlselect_query, mysql_assoc)) {     $current_prename = $row['prename'];     $current_name = $row['name'];     $current_regtype = $row['regtype'];     $current_streeta = $row['streeta'];     $current_streetb = $row['streetb'];     $current_streetc = $row['streetc'];     $current_town = $row['town'];     $current_county = $row['county'];     $current_postcode = $row['postcode'];     $current_country = $row['country']; }  echo '<h2 style="font-family: arial, helvetica, sans-serif;">         company edit form         </h2>';  echo '<form name="postcompany" action="companyupdate.php" method="post">';  echo '<input type="hidden" name="companyid" value="'.$companyid.'">'; echo '     <table>         <tr>             <td>pre name</td>             <td><input type="text" name="" value="'.$current_prename.'"></td>         </tr>         <tr>             <td>name</td>             <td><input type="text" name="" value="'.$current_name.'"></td>         </tr>         <tr>             <td>reg type</td>             <td><input type="text" name="" value="'.$current_regtype.'"></td>         </tr>         <tr>             <td>street a</td>             <td><input type="text" name="" value="'.$current_streeta.'"></td>         </tr>         <tr>             <td>street b</td>             <td><input type="text" name="" value="'.$current_streetb.'"></td>         </tr>         <tr>             <td>street c</td>             <td><input type="text" name="" value="'.$current_streetc.'"></td>         </tr>         <tr>             <td>town</td>             <td><input type="text" name="" value="'.$current_town.'"></td>         </tr>         <tr>             <td>county</td>             <td><input type="text" name="" value="'.$current_county.'"></td>         </tr>         <tr>             <td>postcode</td>             <td><input type="text" name="" value="'.$current_postcode.'"></td>         </tr>         <tr>             <td>country</td>             <td><input type="text" name="" value="'.$current_country.'"></td>         </tr>         <tr>             <td></td>             <td align="right"><button type="submit">save</button></td>         </tr>     </table> ';  echo "</form>"; }  ?> 

if need more details, please comment bellow.

your html wrong form fields need name attribute setting, haven't set them numerically indexed in $_post rather indexed name, use print_r($_post) see mean.

you need update html set name="" name="country" etc.

you might have problem column names in database lower case (generally case imo) , you're accessing them in different cases in second code sample.

try checking $row contains inside while loop using print_r. might find need change to:

$current_prename = $row['prename']; $current_name = $row['name']; $current_regtype = $row['regtype']; $current_streeta = $row['streeta']; $current_streetb = $row['streetb']; $current_streetc = $row['streetc']; $current_town = $row['town']; $current_county = $row['county']; $current_postcode = $row['postcode']; $current_country = $row['country'];


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -