PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 307,160 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,504 people online right now. Registration is fast and FREE... Join Now!




Dynamic Textfield on the form, how to retreive all data and implode

 

Dynamic Textfield on the form, how to retreive all data and implode

arshem

4 Mar, 2009 - 07:56 PM
Post #1

New D.I.C Head
*

Joined: 2 Mar, 2009
Posts: 7

Hey everyone,

I have a quick question.

What method would be best to use to retreive information from a form that has dynamic textfields [you can add more and more textfields. The names would be textfield0,textfield1,textfield2,etc.

I'm not asking for the code, just asking what would be the best way to retreive all the textfields + the count. I was thinking a foreach, but then i couldn't think of a way to retrieve them all..unless i use [] in the textfield name param..


Thanks in advance

here is my code for the function thus far:

CODE


function cars_addspecs() {
    $info = auth_member();
    $car_id = $GLOBALS["Get"]->val("car_id");

    if(!$car_id){
        load_page(URL."/p/cars/s/manage");
    }//if

    $sql_query = "SELECT count(*) FROM cars WHERE car_id='".$car_id."' AND mem_id='".$info["mem_id"]."'";
    $exist = $GLOBALS["DB2"]->single($sql_query);

    if($exist) {
        build_error(100141,"cars","manage");
    }//if

    $sql_query = "INSERT INTO cars_specifications & #40;engine_mods,suspension_mods,electronic_mods,wheel_mods,chasis_mods,interior_
mods,brief_description,402m,0_100kmh,0_300kmh,0_1000m,car_value,modify_budget,sp
onsor_company,sponsor_url,':car_id:')  VALUES (
    ':engine_mods:',':suspension_mods:',':electronic_mods:',':wheel_mods:',':chasis_mods:',':interior_mods:',':brief_description:',':402m:',':0_100kmh:',':0_300kmh:',':0_1000m:',':car_value:',':modify_budget:',':sponsor_company:',':sponsor_url:',':car_id:')";



as you can see i'm stuck at the point of making the values of dynamic "sponsor_company" and "sponsor URL"


Thanks again smile.gif

User is offlineProfile CardPM
+Quote Post

 
Reply to this topicStart new topic
Replies(1 - 3)

CTphpnwb

RE: Dynamic Textfield On The Form, How To Retreive All Data And Implode

4 Mar, 2009 - 08:57 PM
Post #2

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 2,101



Thanked: 155 times
Dream Kudos: 100
Expert In: PHP

My Contributions
1) This isn't defined:
$GLOBALS["Get"]->val("car_id")

2) Your function has no end brace.

3) Your function isn't called.

4) I see no form.

User is online!Profile CardPM
+Quote Post

arshem

RE: Dynamic Textfield On The Form, How To Retreive All Data And Implode

4 Mar, 2009 - 09:03 PM
Post #3

New D.I.C Head
*

Joined: 2 Mar, 2009
Posts: 7

1. Its defined in another part of the script
2. I know..its not supposed to because the function isn't finished
3. the function is called elsewhere
4. The only part of the form you would even need is the names, and again as i described above i could do it a couple ways.

I'm asking for the best way to do it, not actual code. something like "if i were doing it i would use a foreach statement and check the number of "textfield" [which is what it is named "textfield#"] by using [insert function name here].
User is offlineProfile CardPM
+Quote Post

CTphpnwb

RE: Dynamic Textfield On The Form, How To Retreive All Data And Implode

4 Mar, 2009 - 09:12 PM
Post #4

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 2,101



Thanked: 155 times
Dream Kudos: 100
Expert In: PHP

My Contributions
QUOTE(arshem @ 5 Mar, 2009 - 12:03 AM) *

I'm asking for the best way to do it, not actual code. something like "if i were doing it i would use a foreach statement and check the number of "textfield" [which is what it is named "textfield#"] by using [insert function name here].

Ok, then I would do something like this:
CODE
<?php
class general {
    var    $id;
    var    $row;
    var    $table = array("some","tables");
    var    $dblink;
    var    $servername='localhost';
    var    $dbusername='root';
    var    $dbpassword='root';
    var    $dbname='somdatabase';

function __construct() {
    $this->dblink = mysql_connect ($this->servername, $this->dbusername,$this->dbpassword) or die('CONNECTION ERROR: Could not connect to MySQL');
    mysql_select_db($this->dbname,$this->dblink) or die ('Could not open database '.mysql_error());
    }

function read_table($x) {
    $query = "SELECT * FROM ".$this->table[$x]." where id = '".$this->id."'";
    $dbdata = mysql_query($query,$this->dblink) or die('Error reading from '.$this->table[$x]." ".mysql_error());
    $this->row = mysql_fetch_array($dbdata);
    }
    
function update_table($x) {
    $query = "update ".$this->table[$x]." set ";
    foreach($this->row as $key => $value) {
        if(!is_numeric($key) && $key != "id") {
            $query .= $key." = '".$value."', ";
            }
        }
    $query = substr($query,0,-2)." where id ='".$this->id."'";
    mysql_query($query,$this->dblink) or die("Error updating ".$this->table[$x]." ".mysql_error());
    }

}    
?>

I'd add an insert function that would be similar to the update function.

This post has been edited by CTphpnwb: 4 Mar, 2009 - 09:13 PM
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 05:59PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month