Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: PHP Form help

  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post

    PHP Form help

    Im having difficulty with a form i am looking to add to a database. I have a table called employers in my database that lists the contact details of the an employer that is registrated on my site including, email address, tel no etc. The site is a job recruitment site and I need the employer to be able to add a job to the system. I want the form to post the contact details of the employer in the add job form and then add the details to a table called jobs. I wondering do i use the fetch array to get the contact details of the employer from the employer table and then use an insert statement to add the contact information and the job details to the job table? An advice would be much appreciated

    Phil

  • #2
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Hi there,

    You'll need to use mysql_query() in both instances (i.e. you'll need to use SELECT to get the details and INSERT or UPDATE to add the contact information). In the case of the SELECT query you can use mysql_fetch_array().

  • #3
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    Quote Originally Posted by mlse View Post
    Hi there,

    You'll need to use mysql_query() in both instances (i.e. you'll need to use SELECT to get the details and INSERT or UPDATE to add the contact information). In the case of the SELECT query you can use mysql_fetch_array().
    Hi, thanks for the reply, im working on the form atm, i have the contact details posting in the form from the database table "employers" which is the fields company name down to website. Then i have the field below that the employer fills in about the job which are the fields job title down to description. I then need all the fields then sent to the job table once the submit button is clicked. I have the contact fields as readonly, dont what the employer to be able to edit the contact details in this form.

    here is what i have

    PHP Code:
    <?php  
     
       $account 
    mysql_fetch_array(mysql_query("SELECT * FROM employers WHERE username='" $_SESSION["username"] . "'"));  
    ?>  
    <form method="post" class="addform" action="">  
    <fieldset>  
    <label for="username">Company Account details</label><fieldset> 
    </p>
    <p align="right">&nbsp;<a href="editemployerdetails.php">Edit Company Account</a></p>
    </fieldset> 
    <label for="username">Company Name:</label>  
    <input readonly name="username" type="text" id="username" value="<?php echo $account["username"]; ?>" /><br />  
    </fieldset> 

    <fieldset>  
    <label for="address1">Address1:</label>  
    <input readonly name="address1" type="text" id="address1" value="<?php echo $account["address1"]; ?>" /><br />   
    </fieldset>  

    <fieldset>  
    <label for="address2">Address2:</label>  
    <input readonly name="address2" type="text" id="address2" value="<?php echo $account["address2"]; ?>" /><br />   
    </fieldset>  

      
    <fieldset>  
    <label for="location">Location:</label>  
    <input readonly name="location" type="text" id="location" value="<?php echo $account["location"]; ?>" /><br />  
    </fieldset>  


    <fieldset>  
    <label for="tel">Tel No:</label>  
    <input readonly name="tel" type="text" id="tel" value="<?php echo $account["tel"]; ?>" /><br />   
    </fieldset>  

    <fieldset>  
    <label for="fax">fax:</label>  
    <input readonly name="fax" type="text" id="fax" value="<?php echo $account["fax"]; ?>" /><br />   
    </fieldset>  


    <fieldset>  
    <label for="email">Email Address:</label>  
    <input readonly name="email" type="text" id="email" value="<?php echo $account["email"]; ?>" /><br />   
    </fieldset> 

    <fieldset>  
    <label for="website">Website:</label>  
    <input readonly name="website" type="text" id="website" value="<?php echo $account["website"]; ?>" /><br />   

    <p></p>
    <fieldset>  
    <label for="title">Job Title:</label>  
    <input name="title" type="text" id="title" value="<?php echo $account["title"]; ?>" /><br />   
    </fieldset>


    <fieldset>  
    <label for="salary">Salary:</label>  
    <input name="salary" type="text" id="salary" value="<?php echo $account["salary"]; ?>" /><br />   
    </fieldset>

    <fieldset>  
    <label for="joblocation">Job Location:</label><p></p>   
    <select name="joblocation"> 
    <option value="Please Select">Please Select</option> 
    <?php 
      $jobcatergory_opts 
    = array( 
        
    "Accountancy and Finance"
        
    "Banking and Insurance"
        
    "Construction"
        
    "Customer Service"
        
    "Engineering"
        
    "Management",
        
    "Hotel and Catering"
        
    "Information Technology",
        
    "Legal",
        
    "Marketing"
        
    "Medical",
        
    "Retail",
        
    "Sales",
        
    "Secretarial",
        
    "Transport and Distribution",
        
    "Working from home",        
      ); 
      foreach(
    $jobcatergory_opts as $opt){ 
        
    $selected = ($account["jobcatergory"]) == $opt " selected=true":""
        echo 
    "<option value=\"" $opt "\"" $selected ">" $opt "</option>"
      } 
    ?> 
    </select>
    <?php echo "$joblocation_message";?> 
    </fieldset>

    <fieldset>  
    <label for="date">Closing Date:</label>  
    <input name="date" type="text" id="date" value="<?php echo $account["date"]; ?>" /><br />   
    </fieldset>


    <fieldset> 
    <label for="about">About the Company</label> 
    <textarea rows="2" name="about" cols="20"><?php echo $account["about"]; ?></textarea><p></p>
    </fieldset> 
     
    <p class="submit">
    <input type="submit" name="submit" value="Add/Update CV" /> 

    </form>  
    <?php    
    ?>

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    I have the contact fields as readonly, dont what the employer to be able to edit the contact details in this form.
    If you really want to get the real data, you have to query it again or have to store in session during the first fetch. readonly can be easily removed by firebug or some simple JS !
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Hi there,

    I have a few observations!

    Firstly, if you want a field to be read-only your should do what abduraooft said and if you want to display it, simply put the field data into a div or p or someother non-input.

    Secondly, you could shorten your code using a loop (read/write example here):

    PHP Code:
    <form method="POST" class="addform" action="callback.php">
      <?php
        $fieldsets 
    = array("Job Title" => "title""Salary" => "salary", ... etc);
        foreach (
    $fieldsets as $label => $column_name)
            echo 
    "<fieldset><label for=\"$column_name\">$label:</label><input  name=\"$column_name\" type=\"text\" id=\"$column_name\" value=\"".$account[$column_name]."\" /><br /></fieldset>";
       
    ?>
    </form>
    Thirdly, you need to obtain the values submitted in the form from $_REQUEST or $_POST in callback.php (referred to in the form) and use mysql_query('UPDATE employers SET <blah> WHERE username="<blah>"'); [or whatever].

    Fourthly, you'll need some security in there - for example putting the names of the columns into the form HTML code represents a security risk (because you're disclosing info about your DB - you'll need to modify the code I posted) and I would use mysql_real_escape_string() on the contents of $_POST to avoid SQL injection attacks.

    I hope that helps!
    Last edited by mlse; 02-16-2008 at 03:32 PM.


  •  

    Posting Permissions

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