SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_GET doesnt work like it should

    I am having a big problem retrieving information with the $_GET variable...
    in the code below the value is sent thru this link

    edit_job.php?jobid=20&tit=tech








    <? $recruiter_id=$_SESSION['recruiter_id'];?>
    <? $profile_name= $_SESSION['fullname'];?>
    <? $jobid=$_GET['jobid']; //the value gets set here
    $title=$_GET['tit'];
    $edit=$_GET['edit'];

    //then i am able to echo the the value of $jobid anywhere here, and it does so accurately...now the problem is sending this value to the sql....the value gets unset once it is called in the sql..look below

    ?>
    <?
    $job_errors=0;

    if($_POST[submit]){

    if(!isset($_POST[job_title])|| empty($_POST[job_title])){
    $emptytitle=1;
    $job_errors+=1;
    }
    if(!isset($_POST[job_cat])|| empty($_POST[job_cat])){
    $emptycat=1;
    $job_errors+=1;
    }

    }?>

    <?php

    //i am able to also call the value of $jobid accurately here..

    if($job_errors!=0 && $_POST[submit]){

    //but once the value is called anywhere here and below, it becomes empty and there is nothing there


    $editjob=("UPDATE jobs SET title='$_POST[job_title]',
    branch='$_POST[branch]',

    WHERE id ={$jobid}");// so my where key is empty, and i am unable to make the update




    $update_result=mysql_query($editjob,$connection);

    if(mysql_query) {

    redirect_to("recruiters_login.php?edited=1" );}
    }




    ?>

    so as u can see i am having a big problem because if the value is empty my update wont be achieved....im kinda just learning all this stuff, so if u can please help!!!

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    add a hidden form input to contain the value of $jobid. this will then be sent through the POST array when the form is submitted. The section of code will only be actioned the form has been sent - so add another field to pass the job id.

    Code:
    <input type="hidden" name="jobid" value="<?php echo $jobid; ?>" />
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Zealot
    Join Date
    May 2006
    Location
    Jhyalipati,Chapagaun-9, Lalitpur, Bagmati, Nepal
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the problem is due to the use of short tags. Is short tag is allowed in your server?

    or simple escape this error replace '<?' to '<?php '
    Simply Sajan

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While debugging or developing, temporarily turn up error reporting so php will show you undefined variable/indices notices.
    PHP Code:
    // top of scripts
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    My guess is your variable has gone out of scope, and the code you posted is not really complete enough to show your problem.
    http://www.php.net/global

  5. #5
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,994
    Mentioned
    100 Post(s)
    Tagged
    0 Thread(s)
    My guess is that the { and } in {$jobid} are the culprit.

    Add an echo so that it reads:

    $editjob=("UPDATE jobs SET title='$_POST[job_title]',
    branch='$_POST[branch]',
    WHERE id ={$jobid}");
    echo $editjob;
    $update_result=mysql_query($editjob,$connection);

    That will tell you what it is trying so send as the SQL query. Also try changing {$jobid} to .$jobid.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •