OhThanks, I have a form now that works pretty well. However sometimes not all the fields have information to be inputted. For example 123:456:789 text1 text2 text3 text4 is split just the way I want but if there is no data for the last text2 text3 or text4 I get this:
Notice: Undefined offset: 3 in c:\inetpub\wwwroot\swarm\insert2.php on line 25
That error only occurs when I don't have data for the last few text data that was split.
Is there a way to avoid this error when only a part of the data is inputted?
ANother thing I get is that there are 4 blank rows added before the data is added.
Again thanks for all your help.
Here is the code:
PHP Code:
<form method="POST"> <textarea name="textareaname" rows="2" cols="20" accesskey="" tabindex=""
></textarea> <br><input type="Submit"> </form> <? $username="root"; $database="coords"; mysql_connect("localhost",$username); mysql_select_db($database) or die( "Unable to select database"); $mydata = (isset($_POST['textareaname']))?$_POST['textareaname']:'';
$targettemp = split('/\n/', $mydata); foreach($targettemp as $d ) { $d1 = split(" ", $d); $coords = $d1[0]; $name = $d1[1]; $owner = $d1[2]; $defense = $d1[3]; $comments = $d1[4]; $query = "INSERT INTO planets VALUES
('','$coords','$name','$owner','$defense','$comments')"; mysql_query($query); } mysql_close();
?>
THis is on my machine at home so no security risks using root and no password. I have a host that I make sure to use a password and the directory that has access is password protected.
|