Jump to content

Recommended Posts

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.

 

 

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

Link to comment
https://forums.phpfreaks.com/topic/201412-problem-submitting-data-to-database/
Share on other sites

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.