Jump to content

Update database with a List/menu box


Jouatt

Recommended Posts

I am making a site and need some help. I am trying to put in a list/menu that will have the numbers 1-75 and when selecting a number and clicking on the update button it will add that number into my data base. This first bit of code is my Edit Form. The second is my page that updates the info.

<body bgcolor="white">
<form action="index.php" method="post">
<br /></form><br />
<?php 
$con = mysql_connect("localhost","integrq9_coder","Terry421");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("integrq9_Eurotravel", $con);
$UniqueIdentifier=$_GET['UniqueIdentifier'];

$result = mysql_query("SELECT * FROM Project where UniqueIdentifier= ".(int)$UniqueIdentifier."");


while($row = mysql_fetch_array($result))
{
?>
<form name="form" method="post" action="Saving_Data.php"> 
<!--<form name="form" method="post" action="index.php">-->


<input type="hidden" name="ID" value="<?php echo $row["UniqueIdentifier"]?>">
<table border="1">
<tr>
<td> School: </td>
<td><input type="text" name="School" value="<?php echo $row["School"]?>"></td>
<!-- <td> <input type="hidden" name="ID" value="<?php echo $row["UniqueIdentifier"]?>"></td> -->
</tr>
<tr>
<td> Teacher </td>
<td><input type="text" name="Teacher" value="<?php echo $row["Teacher"]?>"></td>
</tr>
<tr>
<td>First contact   </td>

<td><input type="text" name="dtFirstContactSt" value="<?php echo $row["dtFirstContactSt"]?>"></td>
</tr>
<tr>
<td> Development:  </td>
<td>  <input type="text" name="dtDevelopmentSt" value="<?php echo $row["dtDevelopmentSt"]?>"> </td>
<td>  to  </td>
<td> <input type="text" name="dtDevelopmentEnd" value="<?php echo $row["dtDevelopmentEnd"]?>">  </td>
</tr>

<tr>
<td> Pricing:  </td>
<td> <input type="text" name="dtPricingSt" value="<?php echo $row["dtPricingSt"]?>"> </td>
<td>  to  </td>
<td> <input type="text" name="dtPricingEnd" value="<?php echo $row["dtPricingEnd"]?>">  </td>
</tr>
<tr>
<td> Marketing:  </td>
<td>  <input type="text" name="dtMarketingSt" value="<?php echo $row["dtMarketingSt"]?>"> </td>
</tr>
<tr>
<td> Price Based On:  </td>
<td> </td>
</tr>
<tr>
<td> Trip Made:  </td>
<td> </td>
</tr>
<tr>
<td> Trip Assigned To:  </td>
<td>  <input type="text" name="TripAssignedTo" value="<?php echo $row["TripAssignedTo"]?>" maxlength="2"> </td>
</tr>
<tr> 
<td valign="top">Notes: </td>
<td colspan="3"><textarea name="Notes" rows="5" cols="100"><?php echo $row["Notes"]?></textarea></td>
</tr>


</table>


<!--Notes: <textarea name="Notes" rows="3" cols="40"><?php echo $row["Notes"]?></textarea><BR> -->








<?php
} ?>

<br /><br />
<input type="submit" value="Update" ;/>

<input type="hidden" name"customerid " value="<?php echo UniqueIdentifier?>" ;/>
</form><form action="index.php" method="post">
<br /></form><br />

</body>

 

</head>


<form action="index.php" method="post">

are you sure you want to save the data?
<br /><input type="submit" value="Save" ;/></form><br />
<!-- <body bgcolor="#339999"> -->
<body bgcolor="white">
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL | E_STRICT); 
$con = mysql_connect("localhost","integrq9_coder","Terry421");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("integrq9_Eurotravel", $con);

$School=$_POST['School'];
$Teacher=$_POST['Teacher'];
$dtFirstContactSt=$_POST['dtFirstContactSt'];
$dtDevelopmentSt=$_POST['dtDevelopmentSt'];
$dtDevelopmentEnd=$_POST['dtDevelopmentEnd'];
$dtPricingSt=$_POST['dtPricingSt'];
$dtPricingEnd=$_POST['dtPricingEnd'];
$dtMarketingSt=$_POST['dtMarketingSt'];
$TripAssignedTo=$_POST['TripAssignedTo'];
$Notes=$_POST['Notes'];

$UniqueIdentifier = ($_POST['ID']);
$intUniqueIdentifier = (int)$UniqueIdentifier;


if($UniqueIdentifier= ($_POST['ID']))
{
$sql = "UPDATE Project SET 	School='$School',
				Teacher='$Teacher', 
				dtFirstContactSt='$dtFirstContactSt',  
				dtDevelopmentSt='$dtDevelopmentSt', 
				dtDevelopmentEnd='$dtDevelopmentEnd', 
				dtPricingSt='$dtPricingSt', 
				dtPricingEnd='$dtPricingEnd', 
				dtMarketingSt='$dtMarketingSt',				
				TripAssignedTo='$TripAssignedTo',
				Notes='$Notes' 
	WHERE UniqueIdentifier= '$intUniqueIdentifier'" ; 
//		WHERE UniqueIdentifier= ".(int)$UniqueIdentifier." ")  or die(mysql_error()); 
//		WHERE UniqueIdentifier= '$intUniqueIdentifier'")  or die(mysql_error()); 


mysql_query ( $sql )   or die(mysql_error());
}

else
{
echo "<br />"."1 record updated"."<br />";}

?>

<br />
<form action="Edit_Form.php" method="POST">
<!-- <input type="submit" value="Update Again">-->
</form> <br />
</body>
</html> 

Link to comment
https://forums.phpfreaks.com/topic/206539-update-database-with-a-listmenu-box/
Share on other sites

Need more information. What exactly are you having trouble with? Adding the form field to the form? The INSERT/UPDATE query? Help us help you by asking questions that provide enough information to give you an answer.

OK. I need to add the list/menu box, populate it with the numbers 1-75 and the user will select a number from the box. When the user finishes the edit form they click the submit button it will update the database with that number they selected. If you need anymore info just let me know.

Oh, that's not terribly difficult. To make the select field, you'll use a simple loop. You need to add a field to the database to hold the value submitted from the new field. Since the value is an integer, and less than 256, you can give it a data type of TINYINT. For argument's sake I'll pretend it'll be named `new_field`. If you need more help, just say so.

 

echo "THIS IS THE FIELD'S TEXT: <select name=\"GIVE_FIELD_A_NAME\">\n";
for( $i=1; $i<=75; $i++) {
     echo "<option value=\"$i\">$i</option>\n";
}
echo "</select>";

 

Once the form has been submitted, you get the value of the field from the $_POST array, and you can sanitize it by casting it as an integer (since it SHOULD be an integer), and assign its value to a variable.

$new_field = (int) $_POST['GIVE_FIELD_A_NAME'];

 

Then you just need to add the new field name and value to the query string.

Notes='$Notes', 
new_field = $new_field  // value is an integer, so no single-quotes around $new_field variable
	WHERE UniqueIdentifier= '$intUniqueIdentifier'" ;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.