jmac2501 Posted May 30, 2007 Share Posted May 30, 2007 I am looking for a way to input date from a textarea into my database. The way i was trying doing it is by using post method and softing the arrey but my arrey dosn't come out right. here is my code: //add.htm <form action="ROinsert.php" method="post"> <p align="center">Input RO numbers</p> <p align="center"> <textarea cols="30" rows="10" name="ronum" style="list-style-type: decimal"></textarea></p> <p align="center"> <input type="submit" value="Get Data"> </p> </form></body> </html> Textarea vaules = 111111 222222 333333 //ROInsert.php <?php $RO = array("'$_POST[ronum]'"); sort($RO); foreach ($RO as $key => $val) { echo "RO[" . $key . "] = " . $val . "\n"; } ?> arrey out put = RO [0] = "11111 22222 33333" I want the arrey to come out like this: RO [0] = "11111" RO [1] = "22222" RO [2] = "33333" and then i need to figure out the rest of the code to INSERT into Database. sorry if this is confusing... Quote Link to comment https://forums.phpfreaks.com/topic/53536-solved-from-textarea-to-db/ Share on other sites More sharing options...
jitesh Posted May 30, 2007 Share Posted May 30, 2007 textarea returns a string Try $con_arr = explode("\n",$_POST['ronum']); Quote Link to comment https://forums.phpfreaks.com/topic/53536-solved-from-textarea-to-db/#findComment-264557 Share on other sites More sharing options...
jmac2501 Posted May 30, 2007 Author Share Posted May 30, 2007 ok so now i am having trouble INSERTING it into my db. I check as meny places as i could and to me it looks like its coded right. Have a look... <?php if(isset($_POST['DOREO']) && $_POST['DOREO'] == "Get Data") { $con_arr = explode("\n",$_POST['reonum']); print_r ($con_arr); foreach($con_arr as $key => &$val) { $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); or die('Could not connect: ' . mysql_error()); mysql_select_db('Localhost') or die('Could not select database'); $sql = "INSERT INTO $_POST[Listings] (`reo`) VALUES ('$val')"; echo ("<br />"); echo("$sql"); if(mysql_query($sql)) { echo "Success!"; } else{ echo("FAILED TO INPUT DATA"); } } } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> </head> <body> <form method="post"> <p align="center">Input MLS numbers</p> <p align="center"> <textarea cols="30" rows="10" name="reonum" style="list-style-type: none"></textarea></p> <p align="center"> Data Base To Enter Data</p> <p align="center"><br> <select size="1" name="Listings"> <option selected>listings</option> <option>listings2</option> <option>listings3</option> <option>listings4</option> <option>listings5</option> </select></p> <p align="center"> <input type="submit" name="DOREO" value="Get Data"> </p> </form></body> </html> </html> output = Array ( [0] => 54 [1] => 54 [2] => 514 [3] => 5 [4] => 51 [5] => 51 [6] => 3615 [7] => 16 [8] => 1 ) INSERT INTO listings5 (`reo`) VALUES ('54 ')FAILED TO INPUT DATA INSERT INTO listings5 (`reo`) VALUES ('54 ')FAILED TO INPUT DATA INSERT INTO listings5 (`reo`) VALUES ('514 ')FAILED TO INPUT DATA INSERT INTO listings5 (`reo`) VALUES ('5 ')FAILED TO INPUT DATA INSERT INTO listings5 (`reo`) VALUES ('51 ')FAILED TO INPUT DATA INSERT INTO listings5 (`reo`) VALUES ('51 ')FAILED TO INPUT DATA INSERT INTO listings5 (`reo`) VALUES ('3615 ')FAILED TO INPUT DATA INSERT INTO listings5 (`reo`) VALUES ('16 ')FAILED TO INPUT DATA INSERT INTO listings5 (`reo`) VALUES ('1')FAILED TO INPUT DATA Quote Link to comment https://forums.phpfreaks.com/topic/53536-solved-from-textarea-to-db/#findComment-264608 Share on other sites More sharing options...
chigley Posted May 30, 2007 Share Posted May 30, 2007 <?php if(isset($_POST['DOREO']) && $_POST['DOREO'] == "Get Data") { $con_arr = explode("\n",$_POST['reonum']); print_r ($con_arr); foreach($con_arr as $key => &$val) { $link = mysql_connect('******', '*****', '******') or die('Could not connect: ' . mysql_error()); mysql_select_db('*****') or die('Could not select database'); $sql = "INSERT INTO $_POST[Listings] (`reo`) VALUES ('$val')"; echo ("<br />"); echo("$sql"); if(mysql_query($sql)) { echo "Success!"; } else{ echo("FAILED TO INPUT DATA - ".mysql_error()); } } } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> </head> <body> <form method="post"> <p align="center">Input MLS numbers</p> <p align="center"> <textarea cols="30" rows="10" name="reonum" style="list-style-type: none"></textarea></p> <p align="center"> Data Base To Enter Data</p> <p align="center"><br> <select size="1" name="Listings"> <option selected>listings</option> <option>listings2</option> <option>listings3</option> <option>listings4</option> <option>listings5</option> </select></p> <p align="center"> <input type="submit" name="DOREO" value="Get Data"> </p> </form></body> </html> </html> What are the errors? Quote Link to comment https://forums.phpfreaks.com/topic/53536-solved-from-textarea-to-db/#findComment-264610 Share on other sites More sharing options...
jmac2501 Posted May 30, 2007 Author Share Posted May 30, 2007 Array ( => 54 [1] => 54 [2] => 514 [3] => 5 [4] => 51 [5] => 51 [6] => 3615 [7] => 16 [8] => 1 ) INSERT INTO listings5 (`reo`) VALUES ('54 ')FAILED TO INPUT DATA INSERT INTO listings5 (`reo`) VALUES ('54 ')FAILED TO INPUT DATA INSERT INTO listings5 (`reo`) VALUES ('514 ')FAILED TO INPUT DATA INSERT INTO listings5 (`reo`) VALUES ('5 ')FAILED TO INPUT DATA INSERT INTO listings5 (`reo`) VALUES ('51 ')FAILED TO INPUT DATA INSERT INTO listings5 (`reo`) VALUES ('51 ')FAILED TO INPUT DATA INSERT INTO listings5 (`reo`) VALUES ('3615 ')FAILED TO INPUT DATA INSERT INTO listings5 (`reo`) VALUES ('16 ')FAILED TO INPUT DATA INSERT INTO listings5 (`reo`) VALUES ('1')FAILED TO INPUT DATA Is all that is displayed there is no error messages... Quote Link to comment https://forums.phpfreaks.com/topic/53536-solved-from-textarea-to-db/#findComment-264613 Share on other sites More sharing options...
chigley Posted May 30, 2007 Share Posted May 30, 2007 Did you use the code I gave you? Quote Link to comment https://forums.phpfreaks.com/topic/53536-solved-from-textarea-to-db/#findComment-264618 Share on other sites More sharing options...
jmac2501 Posted May 30, 2007 Author Share Posted May 30, 2007 Array ( [0] => 54 [1] => 54 [2] => 514 [3] => 5 [4] => 51 [5] => 51 [6] => 3615 [7] => 16 [8] => 1 ) INSERT INTO listings5 (`reo`) VALUES ('54 ')FAILED TO INPUT DATA - Field 'streetaddress' doesn't have a default value INSERT INTO listings5 (`reo`) VALUES ('54 ')FAILED TO INPUT DATA - Field 'streetaddress' doesn't have a default value INSERT INTO listings5 (`reo`) VALUES ('514 ')FAILED TO INPUT DATA - Field 'streetaddress' doesn't have a default value INSERT INTO listings5 (`reo`) VALUES ('5 ')FAILED TO INPUT DATA - Field 'streetaddress' doesn't have a default value INSERT INTO listings5 (`reo`) VALUES ('51 ')FAILED TO INPUT DATA - Field 'streetaddress' doesn't have a default value INSERT INTO listings5 (`reo`) VALUES ('51 ')FAILED TO INPUT DATA - Field 'streetaddress' doesn't have a default value INSERT INTO listings5 (`reo`) VALUES ('3615 ')FAILED TO INPUT DATA - Field 'streetaddress' doesn't have a default value INSERT INTO listings5 (`reo`) VALUES ('16 ')FAILED TO INPUT DATA - Field 'streetaddress' doesn't have a default value INSERT INTO listings5 (`reo`) VALUES ('1')FAILED TO INPUT DATA - Field 'streetaddress' doesn't have a default value sorry didn't know you change anything... So i am going to add default values thanks. OH and could you please edit my username and password out of your post. lol you were to fast for me... Thankls Quote Link to comment https://forums.phpfreaks.com/topic/53536-solved-from-textarea-to-db/#findComment-264628 Share on other sites More sharing options...
chigley Posted May 30, 2007 Share Posted May 30, 2007 Good luck! Was redbullmarky who edited it, not me Quote Link to comment https://forums.phpfreaks.com/topic/53536-solved-from-textarea-to-db/#findComment-264630 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.