The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

2 Pages V < 1 2  
Reply to this topicStart new topic
> upload multiple textboxes?
Christian J
post Jul 2 2012, 12:35 PM
Post #21


.
********

Group: WDG Moderators
Posts: 6,292
Joined: 10-August 06
Member No.: 7



QUOTE
CODE
echo "text'.$counter.'";
$text = $_POST["text'.$counter.'"];

You're mixing up single- and double quote syntax again. Because of that, the above code returns e.g.

CODE
text'.1.'

instead of the
CODE
text1

you really want.

If a string begins with double quotes, single quotes inside it will not end the string, only another double quote will (unless it's escaped with a backslash).

With double quote syntax there's no need for the concatenation operator (the period sign), so you can simply write

CODE
"text$counter"

even though it's also correct to write something like

CODE
"text".$counter


--------------------
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
xxkasperxx
post Jul 2 2012, 12:43 PM
Post #22


Serious Coder
*****

Group: Members
Posts: 261
Joined: 30-April 11
Member No.: 14,449



okay. But why does it still only take the last text box, and insert that for every box? I guess i dont know where it is overwriting the first text box. How would i figure that out?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Ephraim F. Moya
post Jul 2 2012, 01:53 PM
Post #23


Advanced Member
****

Group: Members
Posts: 167
Joined: 2-September 07
From: New Mexico
Member No.: 3,702



QUOTE(xxkasperxx @ Jul 2 2012, 11:43 AM) *

okay. But why does it still only take the last text box, and insert that for every box? I guess i dont know where it is overwriting the first text box. How would i figure that out?


Because the names are not understandable.

Make the names text1, text2, text3, ... etc.

Not text.1, text.2, ... etc. or some variant.


BTW, How are you going to use this code multiple times? Your counter starts at 0.

Use the {$var} method in double quotes. Its more understandable.

Instead of "word'.$var2.'" say "word{$var2}" which will cleanly concatenate the two instead of using the .(dot) operator.



--------------------
Ephraim F. Moya
"Los pintos y los pendejos
Se conocen desde lejos."
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
xxkasperxx
post Jul 2 2012, 04:22 PM
Post #24


Serious Coder
*****

Group: Members
Posts: 261
Joined: 30-April 11
Member No.: 14,449



the counter is increased each time it goes through..

CODE

$counter =1;
        while($row = mysql_fetch_array($query)){
        $counter++;

and i can not get it to work out with the text{$counter} method.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Ephraim F. Moya
post Jul 3 2012, 09:58 AM
Post #25


Advanced Member
****

Group: Members
Posts: 167
Joined: 2-September 07
From: New Mexico
Member No.: 3,702



QUOTE(xxkasperxx @ Jul 2 2012, 03:22 PM) *

the counter is increased each time it goes through..

CODE

$counter =1;
        while($row = mysql_fetch_array($query)){
        $counter++;

and i can not get it to work out with the text{$counter} method.


There's something you're not telling us.

Do you have access to phpMyAdmin? If so use it to look at the database just after one use. This is very important to see whether the problem is in writing or reading the database.

Have you dumped $row to see if it is what you expect. use the print_r() instruction. Like this:
CODE

        while( $row = mysql_fetch_array( $query ))
        {
              echo '<pre>'; print_r( $row ); echo '</pre>';
              $counter++;
              ...
        }

The $counter may be incremented during the time the while() is running. But the next time you run the program $counter is set to 1 before the while() routine runs.

The "text{$counter}" construct works! It is your program that does not work.

What version of php are you running?


This post has been edited by Ephraim F. Moya: Jul 3 2012, 10:20 AM


--------------------
Ephraim F. Moya
"Los pintos y los pendejos
Se conocen desde lejos."
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
xxkasperxx
post Jul 3 2012, 11:14 AM
Post #26


Serious Coder
*****

Group: Members
Posts: 261
Joined: 30-April 11
Member No.: 14,449



QUOTE(Ephraim F. Moya @ Jul 3 2012, 09:58 AM) *



There's something you're not telling us.

Do you have access to phpMyAdmin? If so use it to look at the database just after one use. This is very important to see whether the problem is in writing or reading the database.

Yes i do.

QUOTE

Have you dumped $row to see if it is what you expect. use the print_r() instruction. Like this:
CODE

        while( $row = mysql_fetch_array( $query ))
        {
              echo '<pre>'; print_r( $row ); echo '</pre>';
              $counter++;
              ...
        }



I get this when i use what you have posted.

Array
(
[0] => 2
[id] => 2
[1] => Array
[content] => Array
)

Array
(
[0] => 3
[id] => 3
[1] => Array
[content] => Array
)

QUOTE

The $counter may be incremented during the time the while() is running. But the next time you run the program $counter is set to 1 before the while() routine runs.

The "text{$counter}" construct works! It is your program that does not work.

What version of php are you running?

I am running PHP Version 5.3.10

So how do I fix my program? I am so lost... Sorry
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Ephraim F. Moya
post Jul 3 2012, 12:50 PM
Post #27


Advanced Member
****

Group: Members
Posts: 167
Joined: 2-September 07
From: New Mexico
Member No.: 3,702



CODE

I get this when i use what you have posted.

Array
(
    [0] => 2
    [id] => 2
    [1] => Array
    [content] => Array
)

Array
(
    [0] => 3
    [id] => 3
    [1] => Array
    [content] => Array
)
    


Why does the ['id'] start with 2? It should start with 0. This happens in your write routine.

Also, where is the textarea name? The part that identifies what text you're saving in the ['content'] field.

Why is the ['content'] an array? This also happens when you write.

Check these by writing different ways until you get what you want. ['id'] starting with 0 and ['content'] being a text field not an array. Plus add a field for the ['name'].




--------------------
Ephraim F. Moya
"Los pintos y los pendejos
Se conocen desde lejos."
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
xxkasperxx
post Jul 3 2012, 07:04 PM
Post #28


Serious Coder
*****

Group: Members
Posts: 261
Joined: 30-April 11
Member No.: 14,449



id is starting at 2 because thats what it starts at in the DB?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Ephraim F. Moya
post Jul 3 2012, 07:24 PM
Post #29


Advanced Member
****

Group: Members
Posts: 167
Joined: 2-September 07
From: New Mexico
Member No.: 3,702



QUOTE(xxkasperxx @ Jul 3 2012, 06:04 PM) *

id is starting at 2 because thats what it starts at in the DB?


Where in the manual does it say that?


--------------------
Ephraim F. Moya
"Los pintos y los pendejos
Se conocen desde lejos."
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
xxkasperxx
post Jul 3 2012, 08:09 PM
Post #30


Serious Coder
*****

Group: Members
Posts: 261
Joined: 30-April 11
Member No.: 14,449



it said array because tats waht was put in the DB for some reason. i changed the DB to say "12" and "qq" and this is what i got back

Array
(
[0] => 2
[id] => 2
[1] => 12
[content] => 12
)

Array
(
[0] => 3
[id] => 3
[1] => qq
[content] => qq
)
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Ephraim F. Moya
post Jul 3 2012, 09:14 PM
Post #31


Advanced Member
****

Group: Members
Posts: 167
Joined: 2-September 07
From: New Mexico
Member No.: 3,702



QUOTE(xxkasperxx @ Jul 3 2012, 07:09 PM) *

it said array because tats waht was put in the DB for some reason. i changed the DB to say "12" and "qq" and this is what i got back

Array
(
[0] => 2
[id] => 2
[1] => 12
[content] => 12
)

Array
(
[0] => 3
[id] => 3
[1] => qq
[content] => qq
)


QUOTE

it said array because tats waht was put in the DB for some reason.


Good! You've identified one of the problems I posed. Now identify the other two and You'll be a long way into debugging your write routines.

This post has been edited by Ephraim F. Moya: Jul 3 2012, 09:22 PM


--------------------
Ephraim F. Moya
"Los pintos y los pendejos
Se conocen desde lejos."
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
xxkasperxx
post Jul 3 2012, 09:23 PM
Post #32


Serious Coder
*****

Group: Members
Posts: 261
Joined: 30-April 11
Member No.: 14,449



How do i stop it from over writing? i cant figure that out
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Ephraim F. Moya
post Jul 3 2012, 11:13 PM
Post #33


Advanced Member
****

Group: Members
Posts: 167
Joined: 2-September 07
From: New Mexico
Member No.: 3,702



QUOTE(xxkasperxx @ Jul 3 2012, 08:23 PM) *

How do i stop it from over writing? i cant figure that out


You write the code. Write it so it doesn't overwrite.

Besides, how do you know it's overwriting?


--------------------
Ephraim F. Moya
"Los pintos y los pendejos
Se conocen desde lejos."
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
xxkasperxx
post Jul 4 2012, 01:55 AM
Post #34


Serious Coder
*****

Group: Members
Posts: 261
Joined: 30-April 11
Member No.: 14,449



Because it shows the second text box as the same text inputted as the first.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Ephraim F. Moya
post Jul 4 2012, 07:59 AM
Post #35


Advanced Member
****

Group: Members
Posts: 167
Joined: 2-September 07
From: New Mexico
Member No.: 3,702



QUOTE(xxkasperxx @ Jul 4 2012, 12:55 AM) *

Because it shows the second text box as the same text inputted as the first.


No, I meant what in your code is writing twice. hint: you have to RTFM! then debug.

You're assuming that your code is perfect. Even in the face of evidence to the contrary.


--------------------
Ephraim F. Moya
"Los pintos y los pendejos
Se conocen desde lejos."
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
xxkasperxx
post Jul 4 2012, 10:10 AM
Post #36


Serious Coder
*****

Group: Members
Posts: 261
Joined: 30-April 11
Member No.: 14,449



It is not getting the second box's text. Because it shows the first box's text for both. So i have to figure out why and how to fix it. Correct?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
xxkasperxx
post Jul 4 2012, 11:31 AM
Post #37


Serious Coder
*****

Group: Members
Posts: 261
Joined: 30-April 11
Member No.: 14,449



So this is what i have so far. Can you please help? I cant figure out how to get the counter to start at 1, when its outside of the while statement.

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>';
                
                //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']);
            
                //echo '<br>they are equal<br>';
                //$text = $row['id'];
                //echo "".$text."";
                //echo "$c";
                
                echo 'Counter: '.$counter.'<br>';
                $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!";
                }
                
            
                
                
            //}
            }
    }
    
?>

This prints out:

ID: 2
Counter:2
ID: 3
Counter:3
ID: 4
Counter:4
ID: 5
Counter:5

input text:test2

Counter: 5

input text:test1

Counter: 5

input text:test3

Counter: 5

input text:test4

Counter: 5

But if i put everything inside of the while statement it prints out:

ID: 2
Counter:2

input text:test2

Counter: 2
ID: 3
Counter:3

input text:test2

Counter: 3
ID: 4
Counter:4

input text:test2

Counter: 4
ID: 5
Counter:5

input text:test2

Counter: 5


Every text box is filled with text and then the number box it is.. Ex textbox 1 has "test1" textbox 2 = "test2"

I feel like im getting closer. What do i need to finish it off? Or am i way off from what i want to accomplish?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
xxkasperxx
post Jul 4 2012, 11:47 AM
Post #38


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?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

2 Pages V < 1 2
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 18th December 2014 - 06:48 PM