GeekPolice
Welcome to GeekPolice.net!

GeekPolice is a website which provides free Computer Technical Support & Virus/Spyware Removal to our members.

You are currently viewing the forum as "Guest" which doesn't give you the same privilege as members to ask questions or post comments.

Click the Register button below to unlock the limitations of this website and start asking questions to discover new computer knowledge!

form problems

Post new topic   Reply to topic

View previous topic View next topic Go down

form problems

Post by charvie on Mon 05 Oct 2009, 3:41 am

im trying to make something like phpmyadmin.

how to create database in phpmyadmin

my problem lies on the 3rd step. when the button "save" is clicked, all data will be sent to "another php page", and that page will be responsible for placing all data into the database.

when i'm on the "another php page" i can access all the data by using POST right?
but then the number of fields depend on the input of the user, so each "text area" "text box" "drop down" should have different name so i can access them, and place them on the database.


when the user inputs 3 in the number of fields, i use a for loop to create 3 rows with 8 columns.

so how can i validate all the data and send them to the database?

i know my explanation is not good im sorry, any help would really be appreciated.

______________________________


THIS SIGNATURE IS BY::: AGENT COSMIC ----------QUOTE BY:::TECHY

charvie

Advanced Surfer
Advanced Surfer

Posts: 446
Joined: 2008-04-13
Operating System: Windows XP

View user profile

Back to top Go down

Re: form problems

Post by darkagn on Wed 07 Oct 2009, 6:50 pm

Yes, you need to give each input field a different name, so for example one of your text boxes for someone to enter their last name might look like this:
Code:

echo "<input type='text' name='surname' value='$surname' />";

Then when you retrieve the data from the form, you validate it like so:
Code:

if(isset($_POST['surname']))
  $surname = trim($_POST['surname']); // trim removes leading and trailing whitespace
else
  $surname = "";
if(strlen($surname) < 2)
{
  echo "Please enter a valid surname";
  die;
}
// if you get to here you have a valid surname, so it can be entered into the database using $surname

______________________________


There are no stupid questions, only those too stupid to ask for help.

darkagn
Pioneer
Pioneer

Posts: 85
Joined: 2007-12-28
Operating System: Windows XP SP3 at home, Vista Ultimate 64-bit at work

View user profile

Back to top Go down

Re: form problems

Post by charvie on Wed 07 Oct 2009, 9:11 pm

thank you for your help, but i still don't know how to change the name of each textbox after the loop....

______________________________


THIS SIGNATURE IS BY::: AGENT COSMIC ----------QUOTE BY:::TECHY

charvie

Advanced Surfer
Advanced Surfer

Posts: 446
Joined: 2008-04-13
Operating System: Windows XP

View user profile

Back to top Go down

Re: form problems

Post by darkagn on Wed 07 Oct 2009, 9:46 pm

So if your for loop look like this:
Code:

for($i=0; $i<$number; $i++)

where $number is the number entered by the user, you can do this for your text boxes:
Code:

echo "<input type='text' name='first_field_name_$i' value='$somevalue' />";

This way, on each iteration, each field will have the suffix 0, 1, 2 etc. $i is evaluated because it is inside the double quotes in php. Does this help?

______________________________


There are no stupid questions, only those too stupid to ask for help.

darkagn
Pioneer
Pioneer

Posts: 85
Joined: 2007-12-28
Operating System: Windows XP SP3 at home, Vista Ultimate 64-bit at work

View user profile

Back to top Go down

View previous topic View next topic Back to top


Permissions of this forum:
You cannot reply to topics in this forum