Page 1 of 1
storing and retrieving data
Posted: Fri Jan 13, 2012 1:40 am
by phpjawahar
Any one help me on this.....
I have a form with two fields. One is STATE NAME(combo box) and the second one is CITY NAME(text box).
The user has to select the STATE NAME(combo box) from the form, then enter the CITY NAME(text box).
My question is how to store the CITY NAME entered by the user corresponding to the STATE NAMES, which was selected from the combo box.
When i try this in php the CITY NAME get stored from the first row of my table.
Jawahar
Re: storing and retrieving data
Posted: Fri Jan 13, 2012 2:26 am
by social_experiment
You have to paste the code you use to store the values, it's impossible to assist without it
Re: storing and retrieving data
Posted: Fri Jan 13, 2012 6:20 am
by phpjawahar
I am submitting my html code, which shows you the form.
<body>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<form action="" method="post">
<td><label>State Name</label></td>
<td><select name="state_name">
<option value="">--- Select State Name ---</option>
<?php while($row=mysql_fetch_array($query)) { ?>
<option>
<?php echo $row['state_name']; ?>
</option>
<?php } ?>
</select>
</td>
<tr>
<td><label>City Name</label></td>
<td><input type="text" name="city_name"/>
</tr>
<tr>
<td><input type="submit" name="add_city" value="Add City" /></td>
<td><input type="submit" name="cancel" value="Cancel" /></td>
</form>
</tr>
</table>
</body>
Jawahar
Re: storing and retrieving data
Posted: Fri Jan 13, 2012 6:30 am
by social_experiment
the code that stores the data is what you have to paste.
Without seeing the code it's difficult to give a proper answer but you could combine the values in a string seperated by a delimiter, lets say : or -. When you retrieve the data from the database use explode() to break the string into parts.
Re: storing and retrieving data
Posted: Fri Jan 13, 2012 7:21 am
by phpjawahar
Hi,
I use a table with three fields as: "STATE_ID", "CITY_NAME", "STATE_NAME"
Here the "STATE_ID" is an auto increment field. In the "STATE_NAME" field, i store the list of state names in my table.
The "CITY_NAME" is left empty in the table, which has to be filled out from the html form by the user.
I tell u one example, as how to get the data stored.
Assume that i choose a "STATE NAME"(which is already available from the database) called 'tamil nadu' from my forms combo box, and enter the "CITY NAME" as 'chennai'.
On clicking the SUBMIT BUTTON the "CITY NAME" 'chennai' must be stored respective to 'tamil nadu'.
please help me on this.
Jawahar.
Re: storing and retrieving data
Posted: Fri Jan 13, 2012 7:34 am
by social_experiment
I cannot help you without seeing the code; by simply reading your reply it's not possible for my to deduce what the problem could be. Clearly $_POST['city_name'] is not being written to the database so you should update the code to include that value when writing to the database, it will most likely go to CITY_NAME in your database.
Re: storing and retrieving data
Posted: Fri Jan 13, 2012 7:46 am
by phpjawahar
Ok thanks for replying me patiently.
Jawahar