surreal5335 Posted May 11, 2010 Share Posted May 11, 2010 I am working on a database that will submit data to it upon a button click then retreive said info and displaying in a particular format. Sounds simple, but there seems to be something I am missing in my code thats stopping it from completing its job. I am using a MVC setup and from the echos I have setup, my controller and my url array routes are working fine. It seems to come down to the calling of the function and the function itself which processes the database query is not working properly. Here is my controller: case "create_profile": if(create_profile($params['profile'])) { flash_notice('Successfully created profile!'); redirect_to(''); } else { flash_notice('Profile creation unsuccessful!'); echo "$params[post] = ".$params['post']."<br />". "$params[profile] = ".$params['profile']."<br />"; print_r($params); } my echo "$params = ".$params['post']."<br />". "$params[profile] = ".$params['profile']."<br />"; isnt producing anything significant. my print_r($params); is giving me this output upon submition. Array ( => Array ( [first_name] => test [last_name] => test2 [born] => 1558 [death] => 1992 [interests] => blah [personality] => yakity schmakity [describe] => I need this to work [profile_id] => 1 ) [0] => posts/create_profile ) This is what I typed into the form, so something must working right. Here is my function that doing the querying and submitting into the database: function create_post($params) { $connection = db_connect(); $query = sprintf("INSERT INTO comtable SET title = '%s', name = '%s', txt = '%s', email = '%s', time = NOW(), user_id = '%s'", mysql_real_escape_string($params['title']), mysql_real_escape_string($params['name']), mysql_real_escape_string($params['txt']), mysql_real_escape_string($params['email']), mysql_real_escape_string($params['time']), mysql_real_escape_string($params['user_id'])); $result = mysql_query($query); if (!$result) return false; else return true; } I appreciate the help Quote Link to comment https://forums.phpfreaks.com/topic/201412-problem-submitting-data-to-database/ Share on other sites More sharing options...
surreal5335 Posted May 12, 2010 Author Share Posted May 12, 2010 I appologize, I realized I copied in the wrong function. Here is the correct one: function create_profile($params) { $connection = db_connect(); $query = sprintf("INSERT INTO profile SET first_name = '%s', last_name = '%s', born = '%s', death = '%s', interests = '%s', personality = '%s', describe = '%s', time = NOW(), profile_id = '%s'", mysql_real_escape_string($params['first_name']), mysql_real_escape_string($params['last_name']), mysql_real_escape_string($params['born']), mysql_real_escape_string($params['death']), mysql_real_escape_string($params['interests']), mysql_real_escape_string($params['personality']), mysql_real_escape_string($params['describe']), mysql_real_escape_string($params['time']), mysql_real_escape_string($params['profile_id'])); $result = mysql_query($query); if (!$result) return false; else return true; } Thanks a lot for your help Quote Link to comment https://forums.phpfreaks.com/topic/201412-problem-submitting-data-to-database/#findComment-1056959 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.