Jump to content

Recommended Posts

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...

                                         

Link to comment
https://forums.phpfreaks.com/topic/53536-solved-from-textarea-to-db/
Share on other sites

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

<?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?

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...

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.