upload multiple textboxes? |
upload multiple textboxes? |
xxkasperxx |
Jun 27 2012, 11:30 AM
Post
#1
|
Serious Coder Group: Members Posts: 261 Joined: 30-April 11 Member No.: 14,449 |
How can i upload more than 1 text box into my database? i want to have it to where they are seperrate fields..
EX: |--------------------------------------------| | FIELD 1.. so text box 1 goes here | |--------------------------------------------| |--------------------------------------------| | FIELD 2.. so text box 2 goes here | |--------------------------------------------| But the user is going to be able to add more text boxes. It is for an announcements page. So the big question is how do i upload the text-boxes into the correct field? CODE <?php session_start(); include("config.php"); $query = mysql_query("SELECT * FROM home"); $query_row=mysql_fetch_array($query) or die (mysql_error()); if (isset($_SESSION['loggedin'])&&isset($_SESSION['username'])) { echo "Welcome, " . $_SESSION['username'] . "!" . "<a href='logout.php'> Log-out!</a>"; ?> <!-- EDIT FOR CMS --> <!DOCTYPE html> <html> <head> <link href="css/main.css" type="text/css" rel="stylesheet" > <title>ConroeGoAway</title> <script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script> <script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script> </head> <body> <div id="wrapper"> <div id="header"> <ul> <li><a href="index.php" class="active">Home</a></li> <li><a href="articles.php">Articles</a></li> <li><a href="email.php">Email</a></li> <li><a href="suggestions.php">Suggestions</a></li> <li><a href="#">Blog</a></li> </div> <div id="picture"> <img src="images/home.png"width="80%"> </div> <div id="bgAnnouncments"> <form action="" method="POST"> <?php $counter =0; while($row = mysql_fetch_array($query)){ $counter++; echo '<textarea id="text.$counter" name="text" rows="15" cols="80" style="width: 100%">'; echo $row['content']; echo '</textarea>'; } ?> <input type="submit" value="Submit" name="submit"> </form> </div> <footer> <p>Copyright © 2012 ConroeGoAway</p> </footer> </div> </body> </html> <?php }else { ?> <!-- REGULAR --> <!DOCTYPE html> <html> <head> <link href="css/main.css" type="text/css" rel="stylesheet" > <title>ConroeGoAway</title> </head> <body> <div id="wrapper"> <div id="header"> <ul> <li><a href="index.php" class="active">Home</a></li> <li><a href="articles.php">Articles</a></li> <li><a href="email.php">Email</a></li> <li><a href="suggestions.php">Suggestions</a></li> <li><a href="#">Blog</a></li> </div> <div id="picture"> <img src="images/home.png"width="80%"> </div> <div id="bgAnnouncments"> <?php while($row = mysql_fetch_array($query)){ echo $row['content']; } ?> </div> <footer> <p>Copyright © 2012 ConroeGoAway</p> </footer> </div> </body> </html> <?php } if ($_POST) { /* foreach ($text as $text){ $text = $_POST['text']; echo $text; echo "data is posted"; if (isset($text)) { echo 'text is set'; $result = strip_tags(mysql_query("UPDATE home SET content = '$text'")); } }*/ } ?> |
xxkasperxx |
Jul 4 2012, 11:47 AM
Post
#2
|
Serious Coder Group: Members Posts: 261 Joined: 30-April 11 Member No.: 14,449 |
I got it to work!!!!!!!!!!!!!!!!!!!!!
This is my code: CODE <?php session_start(); include("config.php"); $query = mysql_query("SELECT * FROM home"); $query_row=mysql_fetch_array($query) or die (mysql_error()); if($_POST['save']) { $counter = 1; $passorfail = false; foreach ( $_POST['mytext'] as $c=> $k) { while($row = mysql_fetch_array($query)){ $tbNum = $row['id']; echo 'ID: '.$tbNum.'<br>'; //echo 'input text:'.$k.'<br>'; //echo 'exiting while statement<br>'; //echo 'K: '.$k.'<br>'; $counter++; echo 'Counter:'.$counter.'<br>'; } //echo 'input text: '.implode($_POST['mytext']).'<br>'; echo '<br>input text:'.$k.'<br>'; // Outputs all text like it should. //echo '<pre>'; print_r( $row ); echo '</pre>'; //echo "its on<br>"; //execute the sql // set allow = true where id = $c $allow = "false"; //echo "ID: ".$tbNum."<br>"; $text = implode($_POST['mytext']); // ARRAY of text //echo '<br>they are equal<br>'; //$text = $row['id']; //echo "".$text.""; //echo "$c"; $result = strip_tags(mysql_query("UPDATE home SET content = '$k' WHERE id=$counter")); $passorfail = true; if ($passorfail==true) { //echo "passed"; } if ($passorfail=false) { echo "Error: Please contact levi at leviwurtz2622@yahoo.com. Thank you!"; } $counter++; echo 'Counter: '.$counter.'<br>'; //} } } ?> Tell me if there is anything I can fix to increase security, or make it work a little more efficient? |
Lo-Fi Version | Time is now: 28th March 2024 - 08:08 PM |