Please i need help on this, i am new with php, please can anyone help me with the code to this scenario...
I will appreciate
this is the case scenario of what i want to achieve
the first textfield would accept the id
and the user would click on the search button,
and a form with 3 textfields is generated with the result of the search in the textfields,
that is textfield 1 would display the id
textfield 2 would display the name
textfield 3 would display the age
and then i can now click on a submit button to take the data into another table in that database
***Textfield SELECT INSERTION HELP
Started by seyz4all, Aug 15 2008 02:18 AM
7 replies to this topic
#1
Posted 15 August 2008 - 02:18 AM
|
|
|
#2
Posted 15 August 2008 - 04:24 AM
Code for the search form:
This file will send the POST data to search.php which will then connect to your database.
Search.php
Then this file selects from the database, the record with the id that was supplied by the previous script. Then a loop through all the results and the values of each field is printed to the text box.
Then you are free to send this data off to another file. :)
<form action="search.php" method="post"> Id <input type="text" name="id" /> <p> <input type="submit" value="Search" /> </p>
This file will send the POST data to search.php which will then connect to your database.
Search.php
<?php
// connect to database here
$sql = "SELECT * FROM age WHERE id='$_POST[id]'";
$result = mysql_query($sql);
?>
<form action="insert.php" method="post">
<?php
while ($row = mysql_fetch_array($result)) {
?>
id <input type="text" name="id" value="<?php echo $row['id'];?>" />
<br />
Name <input type="text" name="name" value="<?php echo $row['name'];?>" />
<br />
Age <input type="text" name="age" value="<?php echo $row['age'];?>" />
<?php
}
?>
<input type="submit" name="Insert" value="Insert" />
</form>
Then this file selects from the database, the record with the id that was supplied by the previous script. Then a loop through all the results and the values of each field is printed to the text box.
Then you are free to send this data off to another file. :)
Edited by chili5, 15 August 2008 - 05:33 AM.
#3
Posted 15 August 2008 - 05:14 AM
thanks alot, i give it a try, it looks really rite and good, i hope it works
#4
Posted 15 August 2008 - 05:17 AM
:D I tried it and it works. :) You might have to modify it to match your database a little. :)
#5
Posted 15 August 2008 - 05:51 AM
thanks man, it works...
on my insert button, what do i do to insert it to another table
is there anywhere one can add reps on this forum, i will definatley add reps for you....
on my insert button, what do i do to insert it to another table
is there anywhere one can add reps on this forum, i will definatley add reps for you....
#6
Posted 15 August 2008 - 06:27 AM
Click
that image in my above post. It's just beside "permalink". :)
As for inserting data, yes. :) The file search.php is set up to send the POST data to insert.php. So insert.php
Edit: ok "history" is the table name, then the things in brackets are the column names. Then the things after values are what you want to insert into the database. This have to be in single quotes for it to work. :)
:) To get a better idea this is the table I used:
You might have to modify it to match your database better but it works. :) Hopefully that is clear, and you can modify the PHP above to match your database. :)
that image in my above post. It's just beside "permalink". :)As for inserting data, yes. :) The file search.php is set up to send the POST data to insert.php. So insert.php
<?php
// database connection stuff
mysql_query("INSERT INTO history (id, name, age) VALUES('$_POST[id]','$_POST[name]','$_POST[age]')");
echo "Database updated.";
?>
Edit: ok "history" is the table name, then the things in brackets are the column names. Then the things after values are what you want to insert into the database. This have to be in single quotes for it to work. :)
:) To get a better idea this is the table I used:
CREATE TABLE IF NOT EXISTS `history` ( `id` int(11) NOT NULL, `name` varchar(100) NOT NULL, `age` int(11) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
You might have to modify it to match your database better but it works. :) Hopefully that is clear, and you can modify the PHP above to match your database. :)
#7
Posted 15 August 2008 - 08:21 AM
dude u did it again...
thanx alot..
i'd give u more reps soon...
to believe this is my first thread and my problem was solved...
Chili5, much respect
thanx alot..
i'd give u more reps soon...
to believe this is my first thread and my problem was solved...
Chili5, much respect
#8
Posted 15 August 2008 - 08:43 AM
Your welcome :D Need anything else just ask. :)


Sign In
Create Account


Back to top









