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
Yanayaya
Forum Commoner
Posts: 42 Joined: Tue Dec 02, 2008 7:49 am
Post
by Yanayaya » Wed Dec 17, 2008 5:32 am
I have made a php form that posts data to mysql database...easy enough. However I get errors if I use drop down boxes and or radio buttons. What type of field should these be listed as in mysql? I have defined the name and id of said drop down boxes but I am sure it could be related to mysql field type.
Sorry if this seems more like a mysql error, but with it being a php form I want to cover both possabilities.
Currently the field type is set to text within mysql. I am not sure what it should be.
<?php
if(isset($_POST['save']))
//Get my data
{
$jobtitle = $_POST['jobtitle'];
$area = $_POST['area'];
$jobdescription = $_POST['jobdescription'];
$jobtype = $_POST['jobtype']; //this is the dropwdown box within the form.
//open my database
include 'libraryver/configuration.php';
include 'libraryver/opendatabase.php';
//put it in
$query = "INSERT INTO jobpost (jobtitle, area, jobdescription, jobtype) VALUES ('$jobtitle','$area','$jobdescription','$jobtype')";
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?";
}
?>
Many thanks in advance. Sorry to mix php / mysql error on here.
papa
Forum Regular
Posts: 958 Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm
Post
by papa » Wed Dec 17, 2008 6:01 am
What kind of error do you get?
Sounds like you are having trouble with your html though.
Try
on your query
Yanayaya
Forum Commoner
Posts: 42 Joined: Tue Dec 02, 2008 7:49 am
Post
by Yanayaya » Wed Dec 17, 2008 6:46 am
papa wrote: What kind of error do you get?
Sounds like you are having trouble with your html though.
Try
on your query
The error doesnt say much. It only appeared when I put in my drop down box, if you take it out, the data insert to the table works fine.
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
if(isset($_POST['save']))
//Get my data
{
$jobtitle = $_POST['jobtitle'];
$area = $_POST['area'];
$jobdescription = $_POST['jobdescription'];
$jobtype = $_POST['jobtype'];
//open my database
include 'libraryver/configuration.php';
include 'libraryver/opendatabase.php';
//punt it in :D
$query = "INSERT INTO jobpost (jobtitle, area, jobdescription, jobtype) VALUES ('$jobtitle','$area','$jobdescription','$jobtype')";
mysql_query($query) or 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">
<input type="text" name="jobtitle" id="jobtitle"><br />
<input type="text" name="area" id="area">
<br />
<select name="jobtype" id="jobtype">
<option value="yay">yay</option>
<option value="nay">nay</option>
</select>
<br />
<textarea name="jobdescription" id="jobdescription" cols="20" rows="10"></textarea><br />
<input name="save" type="submit" id="save" value="Submit">
<input name="reset" type="reset" id="reset" value="Reset">
</form>
<?php echo $msg; ?>
</body>
</html>
papa
Forum Regular
Posts: 958 Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm
Post
by papa » Wed Dec 17, 2008 8:13 am
Maybe:
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Yanayaya
Forum Commoner
Posts: 42 Joined: Tue Dec 02, 2008 7:49 am
Post
by Yanayaya » Wed Dec 17, 2008 8:32 am
Added that in fella, still returning an error.
papa
Forum Regular
Posts: 958 Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm
Post
by papa » Wed Dec 17, 2008 8:59 am
Exactly what error?
Yanayaya
Forum Commoner
Posts: 42 Joined: Tue Dec 02, 2008 7:49 am
Post
by Yanayaya » Wed Dec 17, 2008 9:25 am
I am just getting the 'die' message that I coded.
Whats the best way to check?
papa
Forum Regular
Posts: 958 Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm
Post
by papa » Wed Dec 17, 2008 9:47 am
Read the mysql_error link i posted.
or die("Error: ", mysql_error($db_link);
Yanayaya
Forum Commoner
Posts: 42 Joined: Tue Dec 02, 2008 7:49 am
Post
by Yanayaya » Wed Dec 17, 2008 10:22 am
papa wrote: Read the mysql_error link i posted.
or die("Error: ", mysql_error($db_link);
I tried that, then got a parse error
papa
Forum Regular
Posts: 958 Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm
Post
by papa » Wed Dec 17, 2008 10:23 am
or die("Error: ", mysql_error($db_link));
Read the link damn it. You also need to change the db_link var to your db connection string
Yanayaya
Forum Commoner
Posts: 42 Joined: Tue Dec 02, 2008 7:49 am
Post
by Yanayaya » Wed Dec 17, 2008 10:34 am
papa wrote: or die("Error: ", mysql_error($db_link));
Read the link damn it. You also need to change the db_link var to your db connection string
My apologies, I am reading your link, and no matter what I do, I get a parse error, even whe I specify my db connection.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Dec 17, 2008 10:36 am
papa wrote: or die("Error: ", mysql_error($db_link));
Read the link damn it. You also need to change the db_link var to your db connection string
A bit harse
Alternatively, you can simply omit the connection link (I usually do), since it will use the last opened connection by default.
papa
Forum Regular
Posts: 958 Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm
Post
by papa » Wed Dec 17, 2008 12:44 pm
Jcart wrote: papa wrote: or die("Error: ", mysql_error($db_link));
Read the link damn it. You also need to change the db_link var to your db connection string
A bit harse
Alternatively, you can simply omit the connection link (I usually do), since it will use the last opened connection by default.
No point of giving directions if you're not willing to learn. But my apologies to you Yanayaya, I had a long day at work.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Dec 17, 2008 1:40 pm
Heh, I know the feeling.
I completely agree with you. However, we still
try to be polite (even when people don't give 100%).
Yanayaya
Forum Commoner
Posts: 42 Joined: Tue Dec 02, 2008 7:49 am
Post
by Yanayaya » Thu Dec 18, 2008 3:21 am
My apologies to you, it is not that I am not giving 100% but possibly I was not following what you meant.
However, I have now got the sql errors to stop. I had to delete my id (auto-increment) colum and reinsert it.
However there is still a problem in that when I select anything from my drop down list, it does not save it into MySql. It just saves a blank entry.
Here is a copy of my form. Which is basic of the basic at the moment while I develop it for my needs.
Code: Select all
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
if(isset($_POST['save']))
//Get my data
{
$jobtitle = $_POST['jobtitle'];
$area = $_POST['area'];
$jobdescription = $_POST['jobdescription'];
//open my database
include 'library/config.php';
include 'library/opendb.php';
//punt it in :D
$query = "INSERT INTO jobpost (jobtitle, area, jobdescription) VALUES ('$jobtitle','$area','$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">
Job Title<br />
<input type="text" name="jobtitle" id="jobtitle">
<br />
Area<br />
<input type="text" name="area" id="area">
<br />
Job Type<br />
[color=#BF0000] <select name="jobtype" id="jobtype">
<option value="yay">yay</option>
<option value="nay">nay</option>
</select>[/color]
<br />
Job Description<br />
<textarea name="jobdescription" id="jobdescription" cols="20" rows="10"></textarea><br />
<input name="save" type="submit" id="save" value="Submit">
<input name="reset" type="reset" id="reset" value="Reset">
</form>
<?php echo $msg; ?>
</body>
</html>