yjim Posted August 11, 2009 Share Posted August 11, 2009 how can i create a form in php that allows me to submit multiple lines of code into an array to have it inserted into an SQL string. Link to comment https://forums.phpfreaks.com/topic/169706-solved-php-form-submit/ Share on other sites More sharing options...
halfman Posted August 11, 2009 Share Posted August 11, 2009 how can i create a form in php that allows me to submit multiple lines of code into an array to have it inserted into an SQL string. What do you mean by "multiple lines of code" ? what kind of code?? Link to comment https://forums.phpfreaks.com/topic/169706-solved-php-form-submit/#findComment-895311 Share on other sites More sharing options...
kratsg Posted August 11, 2009 Share Posted August 11, 2009 Question: Explain what kinds of code you expect to have for you input? "multiple lines of code" Here's a sample form: <form action='handle.php' method='post'> <input type='text' name='code[]'><br> <input type='text' name='code[]'><br> <input type='text' name='code[]'><br> <input type='text' name='code[]'><br> <input type='text' name='code[]'><br> <input type='text' name='code[]'><br> <input type='reset'><input type='submit'> </form> handle.php <?php if(isset($_POST['code']) && !empty($_POST['code'])){ //$code contains an array of all the lines of code $time = timestamp(); $query = "INSERT INTO `users` ('code','time') VALUES ($code,$time)"; echo (mysql_query($query))? "true" : "false"; } else { die('You did not submit any code!'); } ?> Link to comment https://forums.phpfreaks.com/topic/169706-solved-php-form-submit/#findComment-895315 Share on other sites More sharing options...
yjim Posted August 11, 2009 Author Share Posted August 11, 2009 no, by multiple lines of code i mean code thats submitted in a textarea box column all at the same time, not a single text field. Link to comment https://forums.phpfreaks.com/topic/169706-solved-php-form-submit/#findComment-895316 Share on other sites More sharing options...
kratsg Posted August 11, 2009 Share Posted August 11, 2009 Since pressing enter in a textarea adds the \n code, I would suggest the following: form <form action='handle.php' method='post'> <textarea name='code'></textarea><br> <input type='reset'><input type='submit'> </form> handle.php <?php if(isset($_POST['code']) && !empty($_POST['code'])){ //$code contains a string of all the lines of code $code = explode("\n",$_POST['code']); //$code is now an array of lines of code, line by line $time = timestamp(); $query = "INSERT INTO `users` ('code','time') VALUES ($code,$time)"; echo (mysql_query($query))? "true" : "false"; } else { die('You did not submit any code!'); } ?> Link to comment https://forums.phpfreaks.com/topic/169706-solved-php-form-submit/#findComment-895319 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.