help php mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Portnumbay
Forum Newbie
Posts: 14
Joined: Mon Jul 05, 2010 1:22 am

help php mysql

Post by Portnumbay »

Hi again..

If i have about 10 textfields just say like
txtDesc1
txtDesc2
txtDesc3
txtDesc4
txtDesc5
...
txtDesc10

and i want to inser it into mysql.. how to do it use while or for ? whats the best..
thanks
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: help php mysql

Post by requinix »

What you do is change your HTML to something more reasonable:

Code: Select all

<input type="text" name="txtDesc[]" />
Repeat that as many times as you want - doesn't matter. $_POST["txtDesc"] will be an array of everything.
Portnumbay
Forum Newbie
Posts: 14
Joined: Mon Jul 05, 2010 1:22 am

Re: help php mysql

Post by Portnumbay »

for example i have something like this

Code: Select all

<form action="insert.php" method="post">
  <label>
  <input type="text" name="date[]" id="date[]">
  </label>
  <br>
  <label>
  <input type="text" name="date[]" id="date[]">
  </label>
  <br>
  <label>
  <input type="text" name="date[]" id="date[]">
  </label>
  <br>
  <label>
  <input type="submit" name="submit" id="submit" value="Submit">
  </label>
</form>
how to get it in post

is it like

Code: Select all

$tanggal = $_Post['date'];
or what ?
I tried but error..

thanks
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: help php mysql

Post by requinix »

IDs in HTML are supposed to be unique. Yours are not. I'm guessing you don't need them, but if you do then that's one place it's appropriate to use numbers.

Code: Select all

<form action="insert.php" method="post">
  <label>
  <input type="text" name="date[]" id="date1">
  </label>
  <br>
  <label>
  <input type="text" name="date[]" id="date2">
  </label>
  <br>
  <label>
  <input type="text" name="date[]" id="date3">
  </label>
  <br>
  <label>
  <input type="submit" name="submit" id="submit" value="Submit">
  </label>
</form>
Portnumbay wrote:is it like

Code: Select all

$tanggal = $_Post['date'];
or what ?
It's like that, yeah, except you're using the wrong variable. Variable names are case-sensitive in PHP.
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: help php mysql

Post by DigitalMind »

following the previous post, $_Post != $_POST
Post Reply