php unidentified index error message -


since added $city=$_post['city'];

i've been getting error message.

undefined index: city in c:\wamp\www\assignment\html\img_upload.php on line 39.

city select field in form.

this code

<?php     require 'login.php';          $path = 'img/';         if (isset($_post['submit'])) {         // grab image post array         $fn=$_post['fname'];         $ln=$_post['lname'];         $sex=$_post['sex'];         $city=$_post['city'];         $em=$_post['email'];         $pass=$_post['pword'];         $confirm=$_post['cword'];         //$gend = $_post['gender']; not using         $pic = $_files['pic']['name'];         if (!empty($fn) && !empty($ln) && !empty($pic)) {         // move file target upload folder         $target = $path.$pic;//create image source (src)         if (move_uploaded_file($_files['pic']['tmp_name'], $target)) {           // // connect database         $dbase = mysqli_connect('localhost', 'root', '', 'flowers');         // write data database         $my_query = "insert members values ('$fn', '$ln', '$sex','$city','$em','$pass', '$pic');";           mysqli_query($dbase, $my_query);           $result = mysqli_query($dbc, $query);           if ($result){         // // confirm success user         // echo '<p>thank registering us!</p>';         // echo '<p><strong>name:</strong> ' . $fn .' '.$ln .'<br />';         // echo '<img src="' . $path . $pic . '" alt="profile image" /></p>';         // echo '<p><a href="index.html">&lt;&lt; return home page</a></p>';         }         else echo "sorry have error:  ".$mysqli_error($dbc);          }         }         }      ?> 

it seems have not posted variable $_post['city'].

whenever have dynamic fields in form, unsure fields posted.

in case, use isset().

$city = isset($_post['city']) ? $_post['city'] : ''; 

this ensures not notice error.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -