Submit form to PHP
Posted: Thu Feb 10, 2011 12:00 am
My senario, please help if you can.
I input two fields(zip and id) to check against a MySql database table and then update the areacode field in the database. The code below works perfect. The problem is if I want to leave the areacode field blank, but still neeed to submit the form. If i leave the areacode field blank, then I DO NOT want it to update the areacode field in the database with white space. I want it to keep its original value as though i was never trying to update in the first place. In other words " IF areacode is NULL or blank on submit, then don't update the MySql database table"
Boy, would I appreciate some help on this one. Thanks in advance to anyone who could help.
Update.html
Update1.php
I input two fields(zip and id) to check against a MySql database table and then update the areacode field in the database. The code below works perfect. The problem is if I want to leave the areacode field blank, but still neeed to submit the form. If i leave the areacode field blank, then I DO NOT want it to update the areacode field in the database with white space. I want it to keep its original value as though i was never trying to update in the first place. In other words " IF areacode is NULL or blank on submit, then don't update the MySql database table"
Boy, would I appreciate some help on this one. Thanks in advance to anyone who could help.
Update.html
Code: Select all
<html>
<body>
<form action="update1.php" method="post">
Zip: <input type="text" name="zip" />
Id: <input type="text" name="id" />
Areacode: <input type="text" name="areacode" />
<input type="submit" />
</form>
</body>
</html>
Code: Select all
<?php
if (isset($_POST['areacode'])) {
echo $_POST['areacode'];
$con = mysql_connect("my_ip,"my_database","my_password");
if (!$con)
{
die('Could not connect to Database Name: ' . mysql_error());
}
mysql_select_db("my_database", $con);
// My Table is ricks_inserts
$result = mysql_query("SELECT * FROM ricks_inserts WHERE zip='$_POST[zip]'");
mysql_query("UPDATE ricks_inserts
SET areacode = '$_POST[areacode]'
WHERE zip = '$_POST[zip]' AND id = '$_POST[id]'");
}
mysql_close($con);
?>