School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,132 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,937 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 Rate Topic: -----

#1 arshem  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 8
  • Joined: 02-March 09


Dream Kudos: 0

Post icon  Posted 04 March 2009 - 07:56 PM

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:


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 (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:')  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 :)
Was This Post Helpful? 0
  • +
  • -


#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • Icon
  • Group: Mentors
  • Posts: 2,238
  • Joined: 08-August 08


Dream Kudos: 100

Expert In: PHP

Posted 04 March 2009 - 08:57 PM

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.
Was This Post Helpful? 0
  • +
  • -

#3 arshem  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 8
  • Joined: 02-March 09


Dream Kudos: 0

Posted 04 March 2009 - 09:03 PM

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].
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is online

  • D.I.C Lover
  • Icon
  • Group: Mentors
  • Posts: 2,238
  • Joined: 08-August 08


Dream Kudos: 100

Expert In: PHP

Posted 04 March 2009 - 09:12 PM

View Postarshem, on 5 Mar, 2009 - 12:03 AM, said:

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:
<?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: 04 March 2009 - 09:13 PM

Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

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

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month