Skip to main content
Inspiring
June 14, 2007
Question

php question: capturing data in a form for mysql update

  • June 14, 2007
  • 1 reply
  • 253 views
I'm trying to update my database by building a form that links a city with surrounding towns. I want to enter the main town and the surrounding towns and then it updates all records that contain the main town. the code runs without errors, but the data i'm entering is not finding its way into the variables and doesn't update the database . . . all help appreciated.

<form id="form1" name="form1" method="get" action="demograph_updatep2.php">
<label><strong class="innerpageheading">Main town</strong>
<input name="maintown" type="text" id="maintown" />
</label>
<p><label><span class="results_13px">Nearby Town1</span>
<input name="nearbytown1" type="text" id="nearbytown1" />
</label>
</p>
<p>
<label><span class="results_13px">NearbyTown2</span>
<input name="nearbytown2" type="text" id="nearbytown2" />
</label>
</p>
<p>
<label><span class="results_13px">NearbyTown3</span>
<input name="nearbytown3" type="text" id="nearbytown3" />
</label>
</p>
<p>
<label><span class="results_13px">NearbyTown4</span>
<input name="nearbytown4" type="text" id="nearbytown4" />
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="Update" />
</label>
</p>
</form>


<?php

// setting variables

$maincity = $_GET['maintown'];
$nearbycity1 = $_GET['nearbytown1'];
$nearbycity2 = $_GET['nearbytown2'];
$nearbycity3 = $_GET['nearbytown3'];
$nearbycity4 = $_GET['nearbytown4'];


mysql_connect (localhost,"");
mysql_select_db("") or die( "Unable to select database");
mysql_query("UPDATE physician
SET

physician_City2 = $nearbycity1
WHERE physician_City1 IN ($maincity)
");
mysql_close();
?>

<?php
mysql_connect (localhost,"");
mysql_select_db("") or die( "Unable to select database");
mysql_query("UPDATE physician
SET

physician_City2 = 'East Grand Rapids'
WHERE physician_City1 IN ('Grand Rapids')
");
mysql_close();
?>
This topic is closed to new replies. Start a new post to keep the conversation going.

1 reply

hconnorjrAuthor
Inspiring
June 14, 2007
please ignore the last ten lines: ?>

<?php
mysql_connect (localhost,"");
mysql_select_db("") or die( "Unable to select database");
mysql_query("UPDATE physician
SET

physician_City2 = 'East Grand Rapids'
WHERE physician_City1 IN ('Grand Rapids')
");
mysql_close();
?>

i was using those to test the sql code