0

I am trying to submit a form which saves some information in a mysql database, the code below is saved in a php file which is called in the action="addrestaurant.php" The information is not being saved in the database,

//addrestourant.php

<?php
include("config.php");
$rname =  addslashes($_POST['username']);
$add=addslashes($_POST['address']);
$restype=$_POST['restype'];
$postcode=$_POST['zipcode'];
$mobile=$_POST['mobile'];
$email=$_POST['email'];
$latitude=$_POST['latitude'];
$longitude=$_POST['longitude'];
$time=$_POST['time'];
$totime=$_POST['time2'];
$timing=$time." "."To"." ".$totime;
$status=$_POST['status'];
$food=$_POST['browsers'];
$ratting=2;
function cwUpload($field_name = '', $target_folder = '', $file_name = '', $thumb = FALSE, $thumb_folder = '', $thumb_width = '', $thumb_height = ''){
    $target_path = $target_folder;
    $thumb_path = $thumb_folder;
    $filename_err = explode(".",$_FILES[$field_name]['name']);
    $filename_err_count = count($filename_err);
    $file_ext = $filename_err[$filename_err_count-1];
    $r1 = chr(rand(ord('a'), ord('z')));
    $r2 = chr(rand(ord('a'), ord('z')));
    $r3 = chr(rand(ord('a'), ord('z')));
    $id=$r1.$r2.$r3;
    $fileName = $id.$_FILES[$field_name]['name'];
    $upload_image = $target_path.basename($fileName);
    if(move_uploaded_file($_FILES[$field_name]['tmp_name'],$upload_image)) {
        if($thumb == TRUE) {
            $thumbnail = $thumb_path.$fileName;
            list($width,$height) = getimagesize($upload_image);
            $thumb_create = imagecreatetruecolor($thumb_width,$thumb_height);
            switch($file_ext){
                case 'jpg':
                    $source = imagecreatefromjpeg($upload_image);
                    break;
                case 'jpeg':
                    $source = imagecreatefromjpeg($upload_image);
                    break;
                case 'png':
                    $source = imagecreatefrompng($upload_image);
                    break;
                case 'gif':
                    $source = imagecreatefromgif($upload_image);
                    break;
                default:
                    $source = imagecreatefromjpeg($upload_image);
            }
            imagecopyresized($thumb_create,$source,0,0,0,0,$thumb_width,$thumb_height,$width,$height);
            switch($file_ext){
                case 'jpg' || 'jpeg':
                    imagejpeg($thumb_create,$thumbnail,100);
                    break;
                case 'png':
                    imagepng($thumb_create,$thumbnail,100);
                    break;
                case 'gif':
                    imagegif($thumb_create,$thumbnail,100);
                    break;
                default:
                    imagejpeg($thumb_create,$thumbnail,100);
            }
        } return $fileName;
    } else { return false; }
} if(!empty($_FILES['image']['name'])){
    $upload_img = cwUpload('image','../uploads/image/','',TRUE,'../uploads/','200','97');
    $thumb_src = '../uploads/thumbs/'.$upload_img;
    $imagepath =  $upload_img;
} $query=mysqli_query($con,"insert into tbl_restourant (name,address,latitude,longitude,ratting,zipcode,phone_no,time,email,is_active,vegtype,thumimage) VALUES ('$rname','$add','$latitude','$longitude','$ratting','$postcode','$mobile','$timing','$email','$status','$restype','$imagepath')");
if($query){
    $q=mysqli_query($con,"select id from tbl_restourant WHERE name ='$rname' && phone_no='$mobile'");
    $r=mysqli_fetch_array($q);
    foreach($food as $value){
        $qr=mysqli_query($con,"insert into tbl_food (food_id,food_type) VALUES ('".$r['id']."','$value')");
    }
    for($i=0; $i<count($_FILES['photos']['name']); $i++) {
        $tmpFilePath = $_FILES['photos']['tmp_name'][$i];
        if ($tmpFilePath != ""){
            $r1 = chr(rand(ord('a'), ord('z')));
            $r2 = chr(rand(ord('a'), ord('z')));
            $id=$r1.$r2;
            $newFilePath = "../uploads/" .$id. $_FILES['photos']['name'][$i];
            $imagepath= $id.$_FILES['photos']['name'][$i];
            if(move_uploaded_file($tmpFilePath, $newFilePath)) {
                $qry=mysqli_query($con,"insert into tbl_images (image_id,img_url) VALUES ('".$r['id']."','$imagepath')");
            }
        }
    }
    ?><script> window.location='../addrestourant.php';</script><?php
}
?>

This is the form:

<?php  session_start(); if(isset($_SESSION['uname'])){ ?>
<?php include'include/config.php'; ?>  


<form id="exampleFullForm" method="post" autocomplete="off" enctype="multipart/form-data" action="include/addrestourant.php">
                    <div class="row row-lg">
                        <div class="col-lg-6 form-horizontal">
                            <div class="form-group">
                                <label class="col-lg-12 col-sm-3 control-label">Restaurant Name
                                    <span class="required">*</span>
                                </label>
                                <div class="col-lg-12 col-sm-9">
                                    <div class="input-group" >
                                        <span class="input-group-addon">
                                        <i class="icon wb-user" aria-hidden="true"></i>
                                        </span>
                                        <input type="text" class="form-control boder"   name="username" placeholder="" required="">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-12 col-sm-3 control-label">Restaurant Type
                                    <span class="required">*</span>
                                </label>
                                <div>
                                    <div class="col-lg-4 col-sm-9">
                                        <div class="radio-custom radio-primary">
                                            <input type="radio" class="boder" id="inputAwesome" name="restype" value="Veg"  required="">
                                            <label for="inputAwesome">Veg</label>
                                        </div>
                                    </div>
                                    <div class="col-lg-4 col-sm-9">
                                        <div class="radio-custom radio-primary">
                                            <input type="radio"  class="boder" id="inputVeryAwesome" name="restype" value="Nonveg">
                                            <label for="inputVeryAwesome">Nonveg</label>
                                        </div>
                                    </div>
                                    <div class="col-lg-4 col-sm-9">
                                        <div class="radio-custom radio-primary">
                                            <input type="radio"  class="boder" id="inputVeryAwesome" name="restype" value="Both">
                                            <label for="inputVeryAwesome">Both</label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-12 col-sm-3 control-label">Address
                                    <span class="required">*</span>
                                </label>
                                <div class="col-lg-12 col-sm-9">
                                    <div class="input-group" >
                                        <span class="input-group-addon">
                                            <i class="icon wb-briefcase" aria-hidden="true"></i>
                                         </span>
                                        <textarea class="form-control boder"   name="address" placeholder="Write Address" required=""></textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-12 col-sm-3 control-label">Zipcode
                                    <span class="required">*</span>
                                </label>
                                <div class="col-lg-12 col-sm-9">
                                    <div class="input-group" >
                                        <span class="input-group-addon">
                                                <i class="icon wb-list-numbered" aria-hidden="true"></i>
                                        </span>
                                        <input type="text" class="form-control boder"   name="zipcode" placeholder="" required="">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-12 col-sm-3 control-label">Phone No.<span class="required">*</span></label>
                                <div class="col-lg-12 col-sm-9">
                                    <div class="input-group" >
                                        <span class="input-group-addon"><i class="icon wb-mobile" aria-hidden="true"></i></span>
                                        <input type="text" class="form-control boder"   name="mobile" placeholder="" required="">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-12 col-sm-3 control-label">Email<span class="required">*</span>
                                </label>
                                <div class="col-lg-12 col-sm-9">
                                    <div class="input-group" >
                                        <span class="input-group-addon">
                                            <i class="icon wb-envelope" aria-hidden="true"></i>
                                         </span>
                                        <input type="email" class="form-control boder"   name="email" placeholder="email@email.com"
                                               required="">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-12 col-sm-9 control-label">Thumbnail image</label>
                                <div class="col-lg-12 col-sm-9">
                                    <input class="form-control boder" type="file" name="image" id="file" required="" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-12 col-sm-9 control-label">Select Images</label>
                                <div class="col-lg-12 col-sm-9">
                                    <input class="form-control boder" type="file" name="photos[]" id="file" multiple="true" required="" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-12 col-sm-9 control-label">Status
                                    <span class="required">*</span>
                                </label>
                                <div >
                                    <div class="col-lg-6 col-sm-9">
                                        <div class="radio-custom radio-primary">
                                            <input type="radio" class="boder" id="inputAwesome" name="status" value="1" checked required="">
                                            <label for="inputAwesome">Active</label>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-sm-9">
                                        <div class="radio-custom radio-primary">
                                            <input type="radio"  class="boder" id="inputVeryAwesome" name="status" value="0">
                                            <label for="inputVeryAwesome">Deactive</label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>


                        <script src="http://maps.google.com/maps/api/js?libraries=places&region=uk&language=en&sensor=true"></script>
                        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>





                        <div class="col-lg-6 form-horizontal">
                            <div class="form-group">
                                <div class="col-lg-12 col-sm-9">
                                    <div class="form-group">
                                        <label class="col-lg-12 col-sm-3 control-label">Search Address
                                            <span class="required">*</span>
                                        </label>
                                        <div class="col-lg-12 col-sm-9">
                                            <div class="input-group" >
                                        <span class="input-group-addon">
                                                <i class="icon wb-map" aria-hidden="true"></i>
                                        </span>
                                                <input id="searchTextField" type="text" size="50" class="form-control boder" style="direction: ltr;">  </div>
                                        </div>
                                    </div>
                                    <div id="map_canvas" style="height: 250px;width: 450px;margin: 0.6em;"></div>
                                <div class="form-group">
                                    <label class="col-lg-12 col-sm-3 control-label">Latitude
                                        <span class="required">*</span>
                                    </label>
                                    <div class="col-lg-12 col-sm-9">
                                        <div class="input-group" >
                                        <span class="input-group-addon">
                                                <i class="icon wb-map" aria-hidden="true"></i>
                                        </span>
                                            <input type="text" id="MapLat" class="form-control boder MapLat"   name="latitude" placeholder="latitude" required="">
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-lg-12 col-sm-3 control-label">Longitude<span class="required">*</span></label>
                                    <div class="col-lg-12 col-sm-9">
                                        <div class="input-group" >
                                        <span class="input-group-addon">
                                                <i class="icon wb-map" aria-hidden="true"></i>
                                        </span>
                                            <input type="text" id="MapLon"  class="form-control boder MapLon"   name="longitude" placeholder="Longitude" required="">
                                        </div>
                                    </div>
                                </div>
                            <div class="form-group">
                                <label class="col-lg-12 col-sm-3 control-label">Time
                                    <span class="required">*</span>
                                </label>
                                <div class="col-lg-6 col-sm-9">
                                    <div class="input-group " >
                                        <span class="input-group-addon">
                                                <i class="icon wb-time" aria-hidden="true"></i>
                                        </span>
                                        <input type="text" class="form-control boder" name="time" placeholder="Ex:08:30 AM" required="">
                                    </div>
                                </div>
                                <div class="col-lg-1 col-sm-9">TO</div>
                                <div class="col-lg-5 col-sm-9">
                                    <div class="input-group " >
                                        <input type="text" class="form-control boder" name="time2" placeholder="Ex:09:30 PM" required="">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                             <label class="col-lg-12 col-sm-9 control-label">Food Type</label>
                                <div class="col-lg-12 col-sm-9">
                                    <select class="form-control boder" id="browsers" name="browsers[]" title="Please select at least one browser" size="5" multiple="multiple" required="">
                                        <?php $query = mysqli_query($con,"select * from tbl_foodcategories");
                                        while($res=mysqli_fetch_array($query)){ ?>
                                        <option value="<?php echo $res['name']; ?>"><?php echo $res['name']; ?></option>
                                        <?php } ?>
                                    </select>
                                </div>
                            </div>
                        </div>
                            <?php
                            $rit=$_SESSION['uname'];
                            $qur=mysqli_query($con,"select * from adminlogin WHERE Username='$rit'");
                            $user=mysqli_fetch_array($qur);
                            if($user['right'] == 1 ) { ?>
                                <div class="form-group col-lg-12 text-right padding-top-m">
                                    <button type="submit" class="btn btn-primary" id="validateButton1">Add Restourant</button>
                                </div>
                            <?php }  else { ?>
                                <div class="form-group col-lg-12 text-right padding-top-m">
                                    <button type="button" class="btn btn-primary" onclick="right()"  id="validateButton1">Add Restaurant</button>
                                </div>
                                <?php }  ?>
                    </div>
                </form>

This is the error i am having when submitting the form:

( ! ) Notice: Undefined index: username in C:\wamp64\www\Restourant\include\addrestourant.php on line 3
Call Stack
#   Time    Memory  Function    Location
1   0.0006  276912  {main}( )   ...\addrestourant.php:0

( ! ) Notice: Undefined index: address in C:\wamp64\www\Restourant\include\addrestourant.php on line 4
Call Stack
#   Time    Memory  Function    Location
1   0.0006  276912  {main}( )   ...\addrestourant.php:0

( ! ) Notice: Undefined index: restype in C:\wamp64\www\Restourant\include\addrestourant.php on line 5
Call Stack
#   Time    Memory  Function    Location
1   0.0006  276912  {main}( )   ...\addrestourant.php:0

( ! ) Notice: Undefined index: zipcode in C:\wamp64\www\Restourant\include\addrestourant.php on line 6
Call Stack
#   Time    Memory  Function    Location
1   0.0006  276912  {main}( )   ...\addrestourant.php:0

( ! ) Notice: Undefined index: mobile in C:\wamp64\www\Restourant\include\addrestourant.php on line 7
Call Stack
#   Time    Memory  Function    Location
1   0.0006  276912  {main}( )   ...\addrestourant.php:0

( ! ) Notice: Undefined index: email in C:\wamp64\www\Restourant\include\addrestourant.php on line 8
Call Stack
#   Time    Memory  Function    Location
1   0.0006  276912  {main}( )   ...\addrestourant.php:0

( ! ) Notice: Undefined index: latitude in C:\wamp64\www\Restourant\include\addrestourant.php on line 9
Call Stack
#   Time    Memory  Function    Location
1   0.0006  276912  {main}( )   ...\addrestourant.php:0

( ! ) Notice: Undefined index: longitude in C:\wamp64\www\Restourant\include\addrestourant.php on line 10
Call Stack
#   Time    Memory  Function    Location
1   0.0006  276912  {main}( )   ...\addrestourant.php:0

( ! ) Notice: Undefined index: time in C:\wamp64\www\Restourant\include\addrestourant.php on line 11
Call Stack
#   Time    Memory  Function    Location
1   0.0006  276912  {main}( )   ...\addrestourant.php:0

( ! ) Notice: Undefined index: time2 in C:\wamp64\www\Restourant\include\addrestourant.php on line 12
Call Stack
#   Time    Memory  Function    Location
1   0.0006  276912  {main}( )   ...\addrestourant.php:0

( ! ) Notice: Undefined index: status in C:\wamp64\www\Restourant\include\addrestourant.php on line 14
Call Stack
#   Time    Memory  Function    Location
1   0.0006  276912  {main}( )   ...\addrestourant.php:0

( ! ) Notice: Undefined index: browsers in C:\wamp64\www\Restourant\include\addrestourant.php on line 15
Call Stack
#   Time    Memory  Function    Location
1   0.0006  276912  {main}( )   ...\addrestourant.php:0

( ! ) Notice: Undefined variable: imagepath in C:\wamp64\www\Restourant\include\addrestourant.php on line 70
Call Stack
#   Time    Memory  Function    Location
1   0.0006  276912  {main}( )   ...\addrestourant.php:0
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jaxon
  • 3
  • 4
  • My first thoughts would be to check that register_globals in the PHP.ini is initialized. Otherwise, maybe it's something in your config.php file emptying the $_POST array. – SyntaxLAMP Jan 01 '17 at 21:46
  • 1) You should find a way to replicate the problem with less code, for example, you could simplify the form by only keeping one input field. 2) Wamp docs recommend you to avoid the 64bit version and use the 32 bit – bg17aw Jan 01 '17 at 21:48
  • Do you see any redirect happening? Like a 301 code inside the Chrome dev tools? – Gerrit Luimstra Jan 01 '17 at 21:49

0 Answers0