Whaa? MYSQL DropDownBox

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Whaa? MYSQL DropDownBox

Post by papa »

Ok first you must establish if you send data.

Comment out this and add:

Code: Select all

 
echo $_POST['jobtype'];
 
/*
if(isset($_POST['save']))
//Get my data
...
}
 
*/
Submit your form and see if you get anything. Also add an action to your form header, example:
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Yanayaya
Forum Commoner
Posts: 42
Joined: Tue Dec 02, 2008 7:49 am

Re: Whaa? MYSQL DropDownBox

Post by Yanayaya »

papa wrote:Ok first you must establish if you send data.

Comment out this and add:

Code: Select all

 
echo $_POST['jobtype'];
 
/*
if(isset($_POST['save']))
//Get my data
...
}
 
*/
Submit your form and see if you get anything. Also add an action to your form header, example:
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

Thank you papa, I included what you said and it echo'd the expected value at the top of the page, so I can confirm that it is posting the data. :evil:

I also added the action to the form, however it has made no difference.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Whaa? MYSQL DropDownBox

Post by papa »

Well it's good practise to use the action.

Can we have a look at your mysql table? I can't see any php errors.
Yanayaya
Forum Commoner
Posts: 42
Joined: Tue Dec 02, 2008 7:49 am

Re: Whaa? MYSQL DropDownBox

Post by Yanayaya »

I have got it working, I have just noticed whilst checking the old code that I had not told php to collect the data from the column that is populated from the dropdown box. It never worked originally, however for some reason it did this time.

I would imagine it was due to the original issue I had with my ID. I had to delete that field and reinsert it and it stopped the problem.

However whilst we are on the subject. This form is for the posting of job vacancies. You will see from the form that there is a job description box. I would like people to be able to post more that 225 characters on varchar within mysql, what can I define that field as to allow this to be possible.

I have reposted the code that works for the form for you to review, everything seems to work fine, but I thought it best to show you the finished result. My only outstanding issue now is the job description.

Code: Select all

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Submit a Vacancy</title>
<link href="vacancy_style.css" rel="stylesheet" type="text/css" />
</head>
 
<body>
<?php
 
if(isset($_POST['save']))
 
//Get my data
{
$jobtitle = $_POST['jobtitle'];
[color=#BF0000]$jobtype = $_POST['jobtype'];[/color]
$area   = $_POST['area'];
$salary = $_POST['salary'];
$qualifications = $_POST['qualifications'];
$skills = $_POST['skills'];
$jobdescription = $_POST['jobdescription'];
 
//open my database
include 'library/configiguration.php';
include 'library/opendatabase.php';
 
//punt it in :D
$query = "INSERT INTO jobpost (jobtitle, [color=#BF0000]jobtype[/color], area, salary, qualifications, skills, jobdescription) VALUES ('$jobtitle', '$jobtype', '$area', '$salary', '$qualifications', '$skills', '$jobdescription')";
mysql_query($query) or die('Error ,query failed');
 
//shut it down!!!
include 'library/closedb.php';
    
//Message to say..you rock.
$msg = "<b>Thank you</b> You want cookie?";
        
    }
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> [color=#FF8000]//thank you papa[/color]
  <table width="490" border="0" align="center" cellpadding="1" cellspacing="5" bgcolor="#fafafa" id="VacancyForm">
    <tr>
      <td width="146">&nbsp;</td>
      <td width="321">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2"><h1>Submit a Vacancy</h1></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><p align="right">Job Title:</p></td>
      <td><input name="jobtitle" type="text" class="box" id="jobtitle" /></td>
    </tr>
    <tr>
      <td><p align="right">Job Type:</p></td>
      <td><select name="jobtype" class="box" id="jobtype">
        <option value="yay">yay</option>
        <option value="nay">nay</option>
      </select></td>
    </tr>
    <tr>
      <td><p align="right">Area:</p></td>
      <td><input name="area" type="text" class="box" id="area" /></td>
    </tr>
    <tr>
      <td><p align="right">Salary:</p></td>
      <td><input name="salary" type="text" class="box" id="salary" /></td>
    </tr>
    <tr>
      <td><p align="right">Qualifications:</p></td>
      <td><textarea name="qualifications" cols="30" rows="5" class="box" id="qualifications"></textarea></td>
    </tr>
    <tr>
      <td><p align="right">Skills:</p></td>
      <td><textarea name="skills" cols="30" rows="5" class="box" id="skills"></textarea></td>
    </tr>
    <tr>
      <td><p align="right">Job Description</p></td>
      <td><textarea name="jobdescription" cols="30" rows="5" class="box" id="jobdescription"></textarea></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input name="save" type="submit" id="save" value="Submit" />
      <input name="reset" type="reset" id="reset" value="Reset" /></td>
    </tr>
    <tr>
      <td colspan="2"><?php echo $msg; ?></td>
    </tr>
  </table>
</form>
</body>
</html>
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Whaa? MYSQL DropDownBox

Post by papa »

I would use TEXT for a description column instead of varchar and then something that stops the user from putting in more than x amount of charachters. strlen for example.
Yanayaya
Forum Commoner
Posts: 42
Joined: Tue Dec 02, 2008 7:49 am

Re: Whaa? MYSQL DropDownBox

Post by Yanayaya »

Thanks again papa, all that is now working. Thank you for all your help. Onto the next problem :D
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Whaa? MYSQL DropDownBox

Post by papa »

Exactly :)

Anger management for me. 8)
Post Reply