storing and retrieving data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpjawahar
Forum Newbie
Posts: 19
Joined: Thu Jan 12, 2012 6:06 am
Location: Chennai, India

storing and retrieving data

Post 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
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: storing and retrieving data

Post by social_experiment »

You have to paste the code you use to store the values, it's impossible to assist without it
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
phpjawahar
Forum Newbie
Posts: 19
Joined: Thu Jan 12, 2012 6:06 am
Location: Chennai, India

Re: storing and retrieving data

Post 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
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: storing and retrieving data

Post 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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
phpjawahar
Forum Newbie
Posts: 19
Joined: Thu Jan 12, 2012 6:06 am
Location: Chennai, India

Re: storing and retrieving data

Post 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.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: storing and retrieving data

Post 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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
phpjawahar
Forum Newbie
Posts: 19
Joined: Thu Jan 12, 2012 6:06 am
Location: Chennai, India

Re: storing and retrieving data

Post by phpjawahar »

Ok thanks for replying me patiently.

Jawahar
Post Reply