I use this code. It works correctly before I made minor changes, I mean, make other input fields and the table field name in mysql but I have some problems from line 14 onwards. With this code I Show some data from database table in a form.

can anyone check my code and tell me some tips to solve my problem please?

<?php 
    require("../../headerloggedin.php"); 
?>
<div id="content">
hello
<?php    
    if(!empty($_GET["editid"]) && !empty($_GET["edituserid"]))
    {
        $applyid = $_GET["editid"];
        $idofuser = $_GET["edituserid"];
        $idofjobtype = $_GET["editjobtype"];
        $idoflocality = $_GET["editlocality"];
        $query = "SELECT * FROM applywork, locality, jobtype, seenon WHERE id = $applyid AND userid = $idofuser AND jobtype = $idofjobtype AND applywork.jobtype = jobtype.typeid AND applywork.locality = locality.localityid AND applywork.seenon = seenon.seenid";
        $resultset = $db->query($query);
        while($row = mysql_fetch_array($resultset))
        {
        //draw the user edit form
        ?>
        <table>  
            <form name="vacancies" method="post" action="updateapplication.php">
                <input type="hidden" name="editid" value="<?php echo $applyid;?>"/>
                <input type="hidden" name="idofuser" value="<?php echo $idofuser;?>"/>
                <input type="hidden" name="idofjobtype" value="<?php echo $idofjobtype;?>"/>
                <input type="hidden" name="idoflocality" value="<?php echo $idoflocality;?>"/>
                    <tr>
                        <td>Vacancy:</td> 
                        <td><input type="text" name="applyfor" value="<?php echo $row["applyfor"]; ?>" /></td>
                    </tr>    
                    <tr>
                        <td>Vacancy seen on:</td> 
                        <td>
                            <select name="seenon">                                
                                <option value="<?php echo $row['seenid'];?>" selected="selected"><?php echo $row['seen']?></option>                            
                                <?php                                
                                    $query = "SELECT * FROM seenon";                                
                                    $result = $db->query($query);                          
                                    while ($lrow = mysql_fetch_array($result))                         
                                    {                                
                                        if($lrow['seenid']!=$row['seenid'])                              
                                        {                          
                                ?>                                
                                <option value="<?php echo $lrow['seenid'];?>"><?php echo $lrow['seen']?></option>                               <?php                                 
                                        }                          
                                    }                      
                                ?>                     
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>Reference Number:</td> 
                        <td><input type="text" name="refnumber" value="<?php echo $row["refnumber"]; ?>"  /></td>
                    </tr>
                    <tr>
                        <td>Job type:</td> 
                        <td>
                            <select name="typeid">                                
                                <option value="<?php echo $row['typeid'];?>" selected="selected"><?php echo $row['type']?></option>                            
                                <?php                                
                                    $query = "SELECT * FROM jobtype";                                
                                    $result = $db->query($query);                          
                                    while ($lrow = mysql_fetch_array($result))                         
                                    {                                
                                        if($lrow['typeid']!=$row['typeid'])                              
                                        {                          
                                ?>                                
                                <option value="<?php echo $lrow['typeid'];?>"><?php echo $lrow['type']?></option>                               <?php                                 
                                        }                          
                                    }                      
                                ?>                     
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>Application sent on:</td> 
                        <td><input type="text" name="applicationsent" value="<?php echo $row["applicationsent"]; ?>"  /></td>
                    </tr>
                    <tr>
                        <td>Company Name:</td> 
                        <td><input type="text" name="companyname" value="<?php echo $row["companyname"]; ?>"  /></td>
                    </tr>
                    <tr>
                        <td>Address 1:</td> 
                        <td><input type="text" name="address1" value="<?php echo $row["address1"]; ?>"  /></td>
                    </tr>
                    <tr>
                        <td>Address 2:</td> 
                        <td><input type="text" name="address2" value="<?php echo $row["address2"]; ?>"  /></td>
                    </tr>
                    <tr>
                        <td>Locality:</td> 
                        <td>
                            <select name="localityid">                                
                                <option value="<?php echo $row['localityid'];?>" selected="selected"><?php echo $row['locality']?></option>                            
                                <?php                                
                                    $query = "SELECT * FROM locality";                                
                                    $result = $db->query($query);                          
                                    while ($lrow = mysql_fetch_array($result))                         
                                    {                                
                                        if($lrow['localityid']!=$row['localityid'])                              
                                        {                          
                                ?>                                
                                <option value="<?php echo $lrow['localityid'];?>"><?php echo $lrow['locality']?></option>                               <?php                                 
                                        }                          
                                    }                      
                                ?>                     
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>Postcode:</td> 
                        <td><input type="text" name="postcode" value="<?php echo $row["postcode"]; ?>"  /></td>
                    </tr>
                    <tr>
                        <td>Telephone:</td> 
                        <td><input type="text" name="telephone" value="<?php echo $row["telephone"]; ?>"  /></td>
                    </tr>
                    <tr>
                        <td>Website:</td> 
                        <td><input type="text" name="website" value="<?php echo $row["website"]; ?>" /></td>
                    </tr>
                    <tr>
                        <td>Email:</td> 
                        <td><input type="text" name="email" value="<?php echo $row["email"]; ?>" /></td>
                    </tr>
                    <tr>
                        <td>Notes:</td> 
                        <td><textarea cols="40" rows="5" name="notes" value="<?php echo $row["notes"]; ?>" ><?php echo $row["notes"]; ?>

What is the error message you are getting? Another possible problem is the db class. Are you using a database connection class? If so, what is the name of the class? Look for something like this..

class Something{

// more stuffs here
function someFunction(){

}
}

In my example above, the name of the class is Something, In your case it can be any name, look on your headerloggedin.php file and find ** $db = new Something();** Something is the name of your database connection class.

Make sure the class responsible for connecting, fetching, updating, inserting to your database in included and instantiated..

Hi veedo,

I solved my problem. thanks for your help for this porblem.

I have "another problem". I make a page to select a vacancy and enter in a page to edit the interview details of selected interview and the details of the interview are displayed in text fields. The problem is when I enter on one vacancy without interview details, it didn't shows empty text fields. To solve the problem I make an if statment to echo a message to tell the user "no interviews for selected vacancy" but it not worked. In if statment I try to make if the id of vacancy is not entered in interviews table echo the message esle display the form. Any help to solve this please?

<?php 
    require("../../headerloggedin.php"); 
?>
<div id="content">
<?php
    if(!empty($_POST["idofinterview"]))
    {
        //the user has pressed 'update'
        $applyid = $_POST["idofvacancy"];
        $interviewid = $_POST["idofinterview"];
        $date = mysql_escape_string($_POST["date"]);
        $time = mysql_escape_string($_POST["time"]);
        $interviewin = mysql_escape_string($_POST["heldin"]);
        $askfor = mysql_escape_string($_POST["askfor"]);

        $query = "UPDATE interviews SET vacancyid='$applyid',date='$date',time='$time',interviewin='$interviewin',askfor='$askfor' WHERE interviewid = $interviewid";
        //echo $query;
        $db->query($query);
        echo "Application updated"; 
    }
?>
<?php    
    if(!empty($_GET["editid"]))
    {
        $applyid = $_GET["editid"];
        $query = "SELECT * FROM applywork, locality WHERE applywork.id = $applyid AND applywork.locality = locality.localityid";
        $resultset = $db->query($query);

        while($row = mysql_fetch_array($resultset))
        {
        ?>
            <table>  
                <tr>
                    <td>Vacancy:</td> 
                    <td><?php echo $row["applyfor"]; ?>.</td>
                </tr>    
                <tr>
                    <td>Company Name:</td> 
                    <td><?php echo $row["companyname"]; ?>,</td>
                </tr>
                <?php
                    if($row["address2"] == "")
                    {
                ?>
                <tr>
                    <td>Address:</td> 
                    <td><?php echo $row["address1"]; ?>,</td>
                </tr>
                <?php
                    }
                    else
                    {
                ?>
                <tr>
                    <td>Address 1:</td> 
                    <td><?php echo $row["address1"]; ?>,</td>
                </tr>
                <tr>
                    <td>Address 2:</td> 
                    <td><?php echo $row["address2"]; ?>,</td>
                </tr>
                <?php        
                    }
                ?>
                <tr>
                    <td>Locality:</td> 
                    <td><?php echo $row["locality"]; ?>.</td>
                </tr>
            </table>
        <br />
        <?php
            $query = "SELECT * FROM interviews WHERE vacancyid = $applyid";
            $resultsets = $db->query($query);

            while($row = mysql_fetch_array($resultsets))
            {
                if($row["vacancyid"] != $applyid)
                {
                    echo "no interviews are be held";
                }
                else
                {
        ?>
        <form method="post" name="interviews" action="editinterviewform.php">
            <input type="hidden" name="idofvacancy" value="<?php echo $applyid;?>"/>
            <input type="hidden" name="idofinterview" value="<?php echo $row["interviewid"];?>"/>
            <table>
                <tr>
                    <td>Date:</td>    
                    <td><input type="text" name="date" value="<?php echo $row['date'];?>" /></td>
                </tr>
                <tr>
                    <td>Time:</td>
                    <td><input type="text" name="time" value="<?php echo $row["time"];?>" /></td>
                </tr>
                <tr>
                    <td>Interview will be held in:</td> 
                    <td><input type="text" name="heldin" value="<?php echo $row["interviewin"];?>" /></td>
                </tr>
                <tr>
                    <td>Ask for:</td>
                    <td><input type="text" name="askfor" value="<?php echo $row["askfor"];?>" /></td>
                </tr>
                <tr>
                    <td colspan="2" align="right">
                        <input type="submit" value="Edit Interview" />
                        <input type="reset" value="Clear" />
                    </td>
                </tr>
            </table>
        </form>
        <?php
                    }
                }
            }
        }
        ?>
        <br />   
            <a href="editinterview.php">Go to main menu.</a>
</div>
<?php require("../../footerloggedin.php"); ?>

Hi,

Try changing this

 $query = "SELECT * FROM interviews WHERE vacancyid = $applyid'";

To

 $query = "SELECT * FROM interviews WHERE vacancyid = '$applyid'";

Double check your queries above and do the same..

You can also change your code to this...

 if($row["vacancyid"] == $applyid)
 {
  ## show your form here
  }
  else{
  echo "no interviews are be held";

  }

It is a lot easier for your script to evaluate the $applyid equal to vacancyid, because applyid is your parameter in your query. It could have been an easy query, but since you need to echo the form with values from the same query, we don't have a choice but loop over.

Hi veedoo,

I change my code for your changing proposal but same problem. The message didn't display if not exist an interview for selected vacancy. :(

<?php 
    require("../../headerloggedin.php"); 
?>
<div id="content">
<?php
    if(!empty($_POST["idofinterview"]))
    {
        //the user has pressed 'update'
        $applyid = $_POST["idofvacancy"];
        $interviewid = $_POST["idofinterview"];
        $date = mysql_escape_string($_POST["date"]);
        $time = mysql_escape_string($_POST["time"]);
        $interviewin = mysql_escape_string($_POST["heldin"]);
        $askfor = mysql_escape_string($_POST["askfor"]);

        $query = "UPDATE interviews SET vacancyid='$applyid',date='$date',time='$time',interviewin='$interviewin',askfor='$askfor' WHERE interviewid = '$interviewid'";
        //echo $query;
        $db->query($query);
        echo "Application updated"; 
    }
?>
<?php    
    if(!empty($_GET["editid"]))
    {
        $applyid = $_GET["editid"];
        $query = "SELECT * FROM applywork, locality WHERE applywork.id = '$applyid' AND applywork.locality = locality.localityid";
        $resultset = $db->query($query);

        while($row = mysql_fetch_array($resultset))
        {
        ?>
            <table>  
                <tr>
                    <td>Vacancy:</td> 
                    <td><?php echo $row["applyfor"]; ?>.</td>
                </tr>    
                <tr>
                    <td>Company Name:</td> 
                    <td><?php echo $row["companyname"]; ?>,</td>
                </tr>
                <?php
                    if($row["address2"] == "")
                    {
                ?>
                <tr>
                    <td>Address:</td> 
                    <td><?php echo $row["address1"]; ?>,</td>
                </tr>
                <?php
                    }
                    else
                    {
                ?>
                <tr>
                    <td>Address 1:</td> 
                    <td><?php echo $row["address1"]; ?>,</td>
                </tr>
                <tr>
                    <td>Address 2:</td> 
                    <td><?php echo $row["address2"]; ?>,</td>
                </tr>
                <?php        
                    }
                ?>
                <tr>
                    <td>Locality:</td> 
                    <td><?php echo $row["locality"]; ?>.</td>
                </tr>
            </table>
        <br />
        <?php
            $query = "SELECT * FROM interviews WHERE vacancyid = '$applyid'";
            $resultsets = $db->query($query);

            while($row = mysql_fetch_array($resultsets))
            {
                if($row["vacancyid"] == $applyid)
                {
        ?>
        <form method="post" name="interviews" action="editinterviewform.php">
            <input type="hidden" name="idofvacancy" value="<?php echo $applyid;?>"/>
            <input type="hidden" name="idofinterview" value="<?php echo $row["interviewid"];?>"/>
            <table>
                <tr>
                    <td>Date:</td>    
                    <td><input type="text" name="date" value="<?php echo $row['date'];?>" /></td>
                </tr>
                <tr>
                    <td>Time:</td>
                    <td><input type="text" name="time" value="<?php echo $row["time"];?>" /></td>
                </tr>
                <tr>
                    <td>Interview will be held in:</td> 
                    <td><input type="text" name="heldin" value="<?php echo $row["interviewin"];?>" /></td>
                </tr>
                <tr>
                    <td>Ask for:</td>
                    <td><input type="text" name="askfor" value="<?php echo $row["askfor"];?>" /></td>
                </tr>
                <tr>
                    <td colspan="2" align="right">
                        <input type="submit" value="Edit Interview" />
                        <input type="reset" value="Clear" />
                    </td>
                </tr>
            </table>
        </form>
        <?php
                }
                else
                {
                    echo "no interviews are be held";   
                }
            }
            }
        }
        ?>
        <br />   
            <a href="editinterview.php">Go to main menu.</a>
</div>
<?php require("../../footerloggedin.php"); ?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.