Jump to content

Recommended Posts

hey
im trying to add selection from a php form into a mysql database but it i am not sure how to.
ive got drop down lists to make the selection from and ive given them values and i know i need to use the POST method but i just cant seem to get it to work.

my options look like this:

Type:
<select name="select">
<option value='Villa'>Villa</option>
<option value='Caravan'>Caravan</option>
<option value='Lodge'>Lodge</option>
</select>
&nbsp;
Board:
<select name="select">
<option value='Full Board'>Full Board</option>
<option value='Half Board'>Half Board</option>
<option value='B & B'>B & B</option>
<option value='Self-Catering'>Self-Catering</option>
</select> &nbsp;

hope someone can help
Link to comment
https://forums.phpfreaks.com/topic/8247-adding-problem/
Share on other sites

Type:
<select name="select_accom">
<option value='Villa'>Villa</option>
<option value='Caravan'>Caravan</option>
<option value='Lodge'>Lodge</option>
</select>
&nbsp;
Board:
<select name="select_board">
<option value='Full Board'>Full Board</option>
<option value='Half Board'>Half Board</option>
<option value='B & B'>B & B</option>
<option value='Self-Catering'>Self-Catering</option>
</select> &nbsp;



using this will ensure your options are passed properly... otherwise the board would have over-written the type. If you want your code fixed properly, you'll have to give us the whole code.
Link to comment
https://forums.phpfreaks.com/topic/8247-adding-problem/#findComment-30062
Share on other sites

ok so at the moment i just have a normal add implemented as if a user was entering the values themselves.
i need it to insert them according to the values chosen
thanks 4 the help


<html>
<head>
<title><?php echo "Accommodation" ?></title>
<link rel="stylesheet" type="text/css" href="template2.css">
<script language="JavaScript" src="gen_validatorv2.js" type="text/javascript"></script>
</head>

<body>

<?php

require_once("config.php");
$connection = @mysql_connect($db_host, $db_user, $db_password) or die("oops! error connecting");
mysql_select_db($db_name, $connection);


$self = $_SERVER['PHP_SELF'];
$accommID = $_POST ["accommID"];

$len = strlen($accommID);
if ($len > 0)
{



$accommID = $_POST["accommID"];
$type = $_POST["type"];
$sleeps = $_POST["sleeps"];
$board = $_POST["board"];
$description = $_POST["description"];
$pets_allowed = $_POST["pets_allowed"];

$query = "INSERT INTO accommodation (accommID, type, sleeps, board, description, pets_allowed) VALUES ('$accommID', '$type', '$sleeps', '$board', '$description', '$pets_allowed')";
mysql_query($query, $connection) or die (mysql_error());

}


?>

<table border="1" width="100%" height="226">
<tr>
<td width="22%" height="91" bgcolor="#0099FF">&nbsp;
<img alt ="[Company Logo]"
src="file:///C:/Documents%20and%20Settings/Puja/My%20Documents/My%20Pictures/puj2.gif" width="100" height="100">
<p>
</td>
<td width="78%" height="91" bgcolor="#66CCFF" ALIGN=CENTER>&nbsp;

<H1> Accommodation </H1>

</td>
</tr>

<td width="22%" height="123" bgcolor="#6699FF">&nbsp;
<div class="buttonscontainer">
<div class="buttons">
<a href="manage_accomm.php">Manage Accommodation</a>
<a href="ownerhomepage.php">Owner Homepage</a>
<a href="logout.php">Logout</a>
</div>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</td>
<td width="78%" height="123" bgcolor="#99CCFF" ALIGN=CENTER>
&nbsp;
&nbsp;
&nbsp;
<center>
<form name="add_accomm.php" action="<?php echo $_SERVER[PHP_SELF]; ?>" method="POST">
<font face="arial" size ="1">

Accommodation ID: <input type="text" name ="accommID"> &nbsp;
Type:
<select name="select_type">
<option value='Villa'>Villa</option>
<option value='Caravan'>Caravan</option>
<option value='Lodge'>Lodge</option>
</select>
&nbsp;
Sleeps:
<select name="select_sleeps">
<option value='2'>Up to 2</option>
<option value='4'>Up to 4</option>
<option value='6'>Up to 6</option>
<option value='8'>Up to 8</option>
<option value='10'>Up to 10</option>
</select> &nbsp; <br> <br>
Board:
<select name="select_board">
<option value='Full Board'>Full Board</option>
<option value='Half Board'>Half Board</option>
<option value='B & B'>B & B</option>
<option value='Self-Catering'>Self-Catering</option>
</select> &nbsp;
Pets Allowed:
<select name="select_pets">
<option value='Y'>Yes</option>
<option value='N'>No</option>
</select> &nbsp;
<br> <br>
Description:<br>
<textarea style ="width: 75%" rows="10" name="description" cols="20"></textarea> <br> <br>&nbsp;
<center> <input type="submit" value="Add"></center>
</font>


<p>&nbsp;</p>
<p>&nbsp;</p>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

</form>



</center>
</td>

<script language="JavaScript" type="text/javascript">
var frmvalidator = new Validator("add_accomm.php");
frmvalidator.addValidation("description","req","Please enter a Description");
</script>

</table>


</body>
</html>
Link to comment
https://forums.phpfreaks.com/topic/8247-adding-problem/#findComment-30109
Share on other sites

TRY THIS:


<html>
<head>
<title><?php echo "Accommodation" ?></title>
<link rel="stylesheet" type="text/css" href="template2.css">
<script language="JavaScript" src="gen_validatorv2.js" type="text/javascript"></script>
</head>

<body>

<?php

require_once("config.php");
$connection = @mysql_connect($db_host, $db_user, $db_password) or die("oops! error connecting");
mysql_select_db($db_name, $connection);


$self = $_SERVER['PHP_SELF'];
$accommID = $_POST ["accommID"];

$len = strlen($accommID);
if ($len > 0)
{



$accommID = $_POST["accommID"];
$type = $_POST["select_type"];
$sleeps = $_POST["select_sleeps"];
$board = $_POST["select_board"];
$description = $_POST["description"];
$pets_allowed = $_POST["pets_allowed"];

$query = "INSERT INTO accommodation (accommID, type, sleeps, board, description, pets_allowed) VALUES ('$accommID', '$type', '$sleeps', '$board', '$description', '$pets_allowed')";
mysql_query($query, $connection) or die (mysql_error());

}


?>

<table border="1" width="100%" height="226">
<tr>
<td width="22%" height="91" bgcolor="#0099FF">&nbsp;
<img alt ="[Company Logo]"
src="file:///C:/Documents%20and%20Settings/Puja/My%20Documents/My%20Pictures/puj2.gif" width="100" height="100">
<p>
</td>
<td width="78%" height="91" bgcolor="#66CCFF" ALIGN=CENTER>&nbsp;

<H1> Accommodation </H1>

</td>
</tr>

<td width="22%" height="123" bgcolor="#6699FF">&nbsp;
<div class="buttonscontainer">
<div class="buttons">
<a href="manage_accomm.php">Manage Accommodation</a>
<a href="ownerhomepage.php">Owner Homepage</a>
<a href="logout.php">Logout</a>
</div>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</td>
<td width="78%" height="123" bgcolor="#99CCFF" ALIGN=CENTER>
&nbsp;
&nbsp;
&nbsp;
<center>
<form name="add_accomm.php" action="<?php echo $_SERVER[PHP_SELF]; ?>" method="POST">
<font face="arial" size ="1">

Accommodation ID: <input type="text" name ="accommID"> &nbsp;
Type:
<select name="select_type">
<option value='Villa'>Villa</option>
<option value='Caravan'>Caravan</option>
<option value='Lodge'>Lodge</option>
</select>
&nbsp;
Sleeps:
<select name="select_sleeps">
<option value='2'>Up to 2</option>
<option value='4'>Up to 4</option>
<option value='6'>Up to 6</option>
<option value='8'>Up to 8</option>
<option value='10'>Up to 10</option>
</select> &nbsp; <br> <br>
Board:
<select name="select_board">
<option value='Full Board'>Full Board</option>
<option value='Half Board'>Half Board</option>
<option value='B & B'>B & B</option>
<option value='Self-Catering'>Self-Catering</option>
</select> &nbsp;
Pets Allowed:
<select name="select_pets">
<option value='Y'>Yes</option>
<option value='N'>No</option>
</select> &nbsp;
<br> <br>
Description:<br>
<textarea style ="width: 75%" rows="10" name="description" cols="20"></textarea> <br> <br>&nbsp;
<center> <input type="submit" value="Add"></center>
</font>


<p>&nbsp;</p>
<p>&nbsp;</p>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

</form>



</center>
</td>

<script language="JavaScript" type="text/javascript">
var frmvalidator = new Validator("add_accomm.php");
frmvalidator.addValidation("description","req","Please enter a Description");
</script>

</table>


</body>
</html>
Link to comment
https://forums.phpfreaks.com/topic/8247-adding-problem/#findComment-30116
Share on other sites

Your $_POST[variable_name] variables should have the same variable name as the name of the form field they're being sent from... so if you had;

<SELECT NAME="cheesey_cheesey_cheddar">
<OPTION VALUE="Cheese">
<OPTION VALUE="Cheddar">
</OPTION>

Your $_POST variable would be $_POST[cheesey_cheesey_cheddar]

[code]
$accommID = $_POST["accommID"];
$type = $_POST["select_type"];
$sleeps = $_POST["select_sleeps"];
$board = $_POST["select_board"];
$description = $_POST["description"];
$pets_allowed = $_POST["select_pets"];
[/code]
Link to comment
https://forums.phpfreaks.com/topic/8247-adding-problem/#findComment-30137
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.