
smithdp1
Members-
Posts
13 -
Joined
-
Last visited
smithdp1's Achievements

Newbie (1/5)
0
Reputation
-
I am pretty new to codeigniter and need help. I have a view that list 3 names with a check box to each name. What i am trying to do is post the items that are checked off to a database.(clientid, camapignid values of only selected). Here are the tables in my database. id - auto increment clientId campaignId creationdate Here is the code for my view: <html> <head> <title>Client View</title> <style type="text/css"> label{ display: block; } </style> </head> <body> <h2>Insert</h2> <?php echo form_open('site/create_client'); ?> <p> <input type="checkbox" name="clientid[]" value="10"> - Fred <input type="checkbox" name="clientid[]" value="20"> - Bob <input type="checkbox" name="clientid[]" value="30"> - Mary <input type="hidden" name="campaignid[]" value="2"> </p> <p> <input type="submit" value="Submit"/> </p> <?php echo form_close(); ?> </body> </html> Here is the code for my controller: <?php class Client extends CI_Controller{ function index(){ $this->load->view('client'); } function create(){ $datetime = date('Y-m-d H:i:s'); $data = array( 'clientid'=> $this->input->post('clientid'), 'campaignid'=> $this->input->post('campaignid'), 'creationdate'=> $datetime ); $this->client->add_record($data); $this->index(); } } Here is the code for my model: <?php class client extends CI_Model{ function add_record($data){ $this->db->insert('campaign_to_client', $data); return; } } I know I am missing some kind of loop somewhere but cant figure it out. Thanks!
-
Post Checked Values To Mysql Jquery Serialize()
smithdp1 replied to smithdp1's topic in PHP Coding Help
so is this close? <?php foreach($_POST['clientId'] as $key => $value) { $clientId = mysql_real_escape_string($value); $campaignId = mysql_real_escape_string($_POST['campaignId'][$key]); $data[] = "('$clientId','$campaignId')"; } $sql = "INSERT INTO `campaign_to_client` (clientId,campaignId) VALUES "; $sql .= implode(",",$data); ?> -
Post Checked Values To Mysql Jquery Serialize()
smithdp1 replied to smithdp1's topic in PHP Coding Help
I have a search results page that gives me a list of clients. If I check off the client they get added to a campaign. That is what I am trying to end up with. -
Post Checked Values To Mysql Jquery Serialize()
smithdp1 replied to smithdp1's topic in PHP Coding Help
should I have a campaignId for each key of the clientId? -
Post Checked Values To Mysql Jquery Serialize()
smithdp1 replied to smithdp1's topic in PHP Coding Help
thanks Xaotique. So now I put this: The forms data<br> <pre> <?php $data = array( 'clientId' => $_POST['clientId'], 'campaignId' => $_POST['campaignId'] ); print_r($data); ?> </pre> And i get this: The forms data Array ( [clientId] => Array ( [0] => 10 [1] => 20 [2] => 30 ) [campaignId] => Array ( [0] => 2 ) ) -
Post Checked Values To Mysql Jquery Serialize()
smithdp1 replied to smithdp1's topic in PHP Coding Help
ok so I put this in my php page and it prints nothing: $data = array( $clientId => $_POST[$clientId], $campaingId => $_POST[$campaignId] ); print_r($data); -
Post Checked Values To Mysql Jquery Serialize()
smithdp1 replied to smithdp1's topic in PHP Coding Help
$data = array( $clientid = $_POST($clientId), $campaignId = $_POST($campaignId) ); -
Post Checked Values To Mysql Jquery Serialize()
smithdp1 replied to smithdp1's topic in PHP Coding Help
so is code correct above: $data = array(){ $clientid = $_POST($clientId), $campaignId = $_POST($campaignId) foreach($clientId as ?){ insert the data to table endforeach; } -
Post Checked Values To Mysql Jquery Serialize()
smithdp1 replied to smithdp1's topic in PHP Coding Help
By the way thanks for taking the time to help...Happy Holidays! -
Post Checked Values To Mysql Jquery Serialize()
smithdp1 replied to smithdp1's topic in PHP Coding Help
right i just fixed the button and it works. So now I have an array of data being submited and I need to insert that into db. so I do something like: $data = array(){ $clientid = $_POST($clientId), $campaignId = $_POST($campaignId) foreach($clientId as ?){ ????now I am lost -
Post Checked Values To Mysql Jquery Serialize()
smithdp1 replied to smithdp1's topic in PHP Coding Help
I just tried what you have posted and it does nothing at all when submited. Is you if statement php or javascript? I have tried putting it in both tags and still does nothing. Inkow that after the form is submited I need to do something like: clientid = $_POST($clientId); campaignId = $_POST($campaignId); $data = array(){ clientId, campaignId } But I am not sure on the javascript and exact syntax. I was just asking for some help. -
Post Checked Values To Mysql Jquery Serialize()
smithdp1 replied to smithdp1's topic in PHP Coding Help
That is why I am asking for help...i am not sure what to do -
Hi, I am trying to post checked off items to a mysql table using php and jQuery serialize(). I have the form made with array as name but I dont know where to go now. Here is my form: <form name="myform"> <input type="checkbox" name="clientId[]" value="10"> - Fred <br /> <input type="checkbox" name="clientId[]" value="20"> - Mary <br /> <input type="checkbox" name="clientId[]" value="30"> - Bob <br /> <input type="hidden" name="campaignId" value="2"> <input name="submit" type="button" value="Submit"> </form> MySql table id - auto increment clientId campaignId If I check off Fred and Mary for instance I want the clientId and campaignId to post to above table for only Fred and Mary.