View Full Version : trouble updating my database

08-10-2011, 11:17 AM
I am trying to update my database and currently two of my fields I am trying to update are not setting, infact they get saved as blank.

I have checked my html form, it is a spot on match for the name="". I am getting the form via Ajax call with the current data loaded in the fields. Ajax is not the problem bc 1 of the fields called via ajax is submitting properly to the database.

Here is my code:

function update_post()
// create new record
//echo 'update submit';
$Database = new mysqli(##########);


$post_title = htmlentities($_POST['post_title'], ENT_QUOTES);
$new_post_image = htmlentities($_POST['new_post_image'], ENT_QUOTES);
$current_post_image = htmlentities($_POST['current_post_image'], ENT_QUOTES);
$post_desc = htmlentities($_POST['post_desc'], ENT_QUOTES);
$post_id = htmlentities($_POST['post_id'], ENT_QUOTES);
$user_name = htmlentities($_SESSION['user_name'], ENT_QUOTES);
$now = date("Y-m-d");

$post_image = $current_post_image;
if($new_post_image != '')
$post_image = $new_post_image;

$post_title = $Database->real_escape_string($user_title);
$post_image = $Database->real_escape_string($post_image);
$post_desc = $Database->real_escape_string($post_desc);
$post_id = $Database->real_escape_string($post_id);
$user_name = $Database->real_escape_string($user_name);
$now = $Database->real_escape_string($now);

if ($Database->query("UPDATE posts SET post_title='".$post_title."', post_image='".$post_image."',
post_content='".$post_desc."', post_user_update='".$user_name."', post_date_update='".$now."'
WHERE post_id='".$post_id."'" ))


echo 'Error: could not prepare SQL statement.<br />';

header("Location: posts.php");
} // end isset($_POST['submit'])

} // end update_post()

I made the update function not return to the same page and here is the error I got:

( ! ) Notice: Undefined index: current_post_image in C:\wamp\www\pentup_games\views\functions\query_post.php on line 21 Call Stack #TimeMemoryFunctionLocation 10.0039690080{main}( )..\posts.php:0 20.1937879224update_post( )..\posts.php:85 post_title: new post
post_desc: Sucessful MySql query
post_id: 1

( ! ) Notice: Undefined variable: user_title in C:\wamp\www\pentup_games\views\functions\query_post.php on line 38
Call Stack
# Time Memory Function Location
1 0.0039 690080 {main}( ) ..\posts.php:0
2 0.1937 879224 update_post( ) ..\posts.php:85
Sucess: prepared SQL statement.
post_desc: Sucessful MySql query
post_id: 1
" method="post" class="get_post_form">

08-10-2011, 11:25 AM
Looks like you just need to do some Basic Debugging 101 (http://www.codingforums.com/showthread.php?p=1083761&highlight=workflow#post1083761) to find and fix the problem