1

I am working on a jquery mobile app to allow recruitment agent to interact with job seekers through a mobile app. On the job link I decided to enter different vacant jobs on the app dynamically using json and I am able to enter jobs in json file and it uploads them to the app without any problem.

But I am trying to allow the current logged user to select a job that is where I need to use php to help insert data from the listview to mysql database. I am attaching the files to get any assistance from you.thanks in advance

my json code

[
 {"jobtype":"IT project manager",
  "city":"Johannesburg",
  "message":"We are looking for a manager at go fish company to manage the IT departments",
  "details":"We are looking for a manager at go fish company to manage the IT department and thank you",
  "jobid":"IT1"
  },

  {"jobtype":"Geologist",
  "city":"Captown",
  "message":"We are looking for an experienced Geologist to join a mining comapy established in congo.",
   "details":"We are looking for a manager at go fish company to manage the IT department,but it will be more beneficial for soemone who has done engineering,even those who have not finished yet but have enough experience in the trade they are welcome as long as they can do the job,the position is widely open for you to apply.so for any question contact patrick at 063167888.good luck",
    "jobid":"GE1"
  },
   {"jobtype":"Librarian",
  "city":"Johannesburg",
  "message":"We are looking for an experienced librarian to handle the library in sandton city.",
   "details":"We are looking for a manager at go fish company to manage the IT department",
    "jobid":"LI1"
  }
]

my jquery mobile codes

<div data-role="page" id="page5" data-add-back-btn="true">
    <div data-role="header">
        <h1>Services</h1>
    </div>

    <div data-role="content">
    <h4><span class="glyphicon glyphicon-user"></span>
        <?php  echo 'Welcome '.$_SESSION['name'];

        echo "<br><a href='logout.php' data-ajax='false'>Logout</a>"; ?> ...</h4> 

      <ul data-role="listview" data-inset="true"  data-filter="true" id="jobList">

    </ul>
    </div>   
    <div data-role="footer">
        <h4>&copy;2016 &bull; Genesis M&C Holdings Pty</h4>
    </div>
</div>
<script type="text/javascript">

 $.getJSON("http://localhost:8080//recruitment//jobdetails.json", function(jobs){
   //Start off with an empty list every time to get the latest from server
   $('#jobList').empty();

   //add the job items as list
   $.each(jobs, function(i, job){
     $('#jobList').append(generateJobLink(job));
   });

   //refresh the list view to show the latest changes
  $('#jobList').listview('refresh');

 });

  //creates a job link list item
 function generateJobLink(job){

  //debugger;
  return '<li><a href="javascript:void(0)'
         + '" onclick="goToJobDetailPage(\''
         + job.jobtype 
         + '\',\''
         + job.city 
         + '\',\''
          + job.message 
         + '\',\''
          + job.details 
         + '\',\''
          + job.jobid 
         + '\',\''


         + job.jobid +'\')">' 
         + job.jobtype+"<h3></h3>"
          + job.city +"<p><strong><br>"
           + job.message +"<h4></h4>"

         + '</a></li>';
  }

  function goToJobDetailPage(jobType,jobCity,jobMessage,jobDetails,jobId){

   //create the page html template
   var jobPage = $("<div data-role='page' data-url=dummyUrl> <div data-role='header'><h1>"
                   + 'Job Details' + "</h1></div><div data-role='content'><strong><form style='border:dotted 1px #CCC' action='jobapp.php' method='post' data-ajax='false'>" 
                   + jobType + "</strong><h6>" 
                    + jobId + "</strong><h6>"
                   + jobCity +"</h6><p>"  
                   + jobDetails +"</P> <div class='col-lg-10 text-center'><button type='submit' class='btn btn-warning' id='appbtn' name='appbtn' data-role='none'><span class='glyphicon glyphicon-envelope'></span>&nbsp;Apply</button><span>&nbsp</span><button type='submit' class='btn btn-danger' id='favbtn' name='favbtn' data-role='none'><span class='glyphicon glyphicon-star'></span>&nbsp;Favorite</button></div></div><div data-role='footer'><h4>" 
                   + '&copy;2016 &bull; Genesis M&C Holdings Pty' + "</h4></div></div>");

   //append the new page to the page container
   jobPage.appendTo( $.mobile.pageContainer );

  //go to the newly created page
  $.mobile.changePage( jobPage );
  }  

</script> 

my php codes

<?php //data.php
include_once 'Dbconnect.php'; 
if (isset($_POST['appbtn'])){
    // Get values from form

    $JobsId=json_decode($_post['jobid']);
    $JobTitle=json_decode($_post['jobtype']);
    $JobCity=json_decode($_post['city']);

    // Insert data into mysql

    $sql="INSERT INTO jobs (jobid,jobtitle,jobcity,datetime)
          VALUES ('$JobsId ', '$JobTitle','$JobCity',now()) ";
    $result = mysql_query($sql);

    // if successfully insert data into database, displays message "Successful".
    if($result){
        header("Location: index.php#page4?message=success");
        echo"successfully registered";
    } else {
        echo "ERROR";
    }
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
patrick
  • 11
  • 4
  • Maybe you need to look at this event https://api.jquerymobile.com/pageinit/ for your javascript in the mobile code – RiggsFolly Apr 10 '16 at 16:55
  • could you elaborate more because so far everything is just ok ,except me being able to insert data in mysql database,i manage to but i get some 00 which is wrong. – patrick Apr 10 '16 at 17:04
  • In your PHP-script, can you do `var_dump($_POST);` just to see if the form information has been submitted? – Gjermund Dahl Apr 11 '16 at 19:24
  • Your form seems to be missing vital fields. In order to acquire e.g. jobid on server side, your form needs an input field named `name="jobid"`, e.g. `` – Gjermund Dahl Apr 11 '16 at 19:39
  • Then, at server side, just do `$JobsId = $_POST['jobid'];` Also always filter & sanitize user input: http://stackoverflow.com/questions/129677/whats-the-best-method-for-sanitizing-user-input-with-php – Gjermund Dahl Apr 11 '16 at 19:41
  • Thanks Gjermund Dahl i like your logic makes sense enough but for some reason the form info don't get to my sql,i checked the format of my html page template in the function goToJobDetailPage seems just fine.my php work because i have a date function that insert the date every time i submit. – patrick Apr 12 '16 at 13:14
  • here is what i have added + jobType + "
    " + jobId + "
    " + jobCity +"

    " + jobDetails +"

    – patrick Apr 12 '16 at 14:16
  • Thanks a lot Gjermund Dahl you saved my behind after i sanitized user input i started seeing my mistake it said undefined variable _post and when i made it in capital it started writing in the database _POST.Thanks a million now it is writing to the database – patrick Apr 12 '16 at 16:09
  • I am glad you found a solution :-) – Gjermund Dahl Apr 13 '16 at 12:16

0 Answers0