unemployment Posted April 24, 2011 Share Posted April 24, 2011 Is there any visible error in my code? if (isset($_POST['country'], $_POST['state'], $_POST['city'])) { if ($_POST['state'] = '') { $details = $_POST['city'].', '.$_POST['country']; update_user_location($details); } else { $details = $_POST['city'].', '.$_POST['state']; update_user_location($details); } } function update_user_location($details) { global $user_info; $details = mres($details); mysql_query("INSERT INTO `user_actions` (`user_id`, `action_id`, `time`, `details`) VALUES (${user_info['uid']}, 1, NOW(), {$details})"); } Link to comment https://forums.phpfreaks.com/topic/234584-no-error-but-mysql-wont-update/ Share on other sites More sharing options...
Fadion Posted April 24, 2011 Share Posted April 24, 2011 Are you getting any errors? First I would get rid of the apostrophes (`) in queries as they're not actually needed. Second, add single quotes in the VALUES() part of the query as they are needed. <?php $uid = ${user_info['uid']}; //what you're trying to achieve here? It doesn't make any sense. mysql_query("INSERT INTO user_actions (user_id, action_id, time, details) VALUES ('$uid', '1', NOW(), '$details')"); ?> Link to comment https://forums.phpfreaks.com/topic/234584-no-error-but-mysql-wont-update/#findComment-1205536 Share on other sites More sharing options...
fugix Posted April 24, 2011 Share Posted April 24, 2011 in your if statement..you want it to run the code if all 3 fields are set...then you state that if $_POST['state'] is blank to run more code..how can it be set and empty at the same time? unless you set it to be a blank space..? Link to comment https://forums.phpfreaks.com/topic/234584-no-error-but-mysql-wont-update/#findComment-1205541 Share on other sites More sharing options...
unemployment Posted April 24, 2011 Author Share Posted April 24, 2011 ok so with your recommendation I was able to get mysql to post the data, but for some reason my concatenations are not working. The state or country are not being posted so i'm just left with New York, Any suggestions? Link to comment https://forums.phpfreaks.com/topic/234584-no-error-but-mysql-wont-update/#findComment-1205548 Share on other sites More sharing options...
Fadion Posted April 24, 2011 Share Posted April 24, 2011 You have two problems with your form validation. First, isset() only checks if a variable exists and in the case of POST, the array keys are created even if they are empty and will return true. Second, your second if() doesn't contain a comparison operator (==). I would write it as follows: <?php //only validates if 'country' and one of 'state' or 'city' are set if ($_POST['country'] != '' && ($_POST['state'] != '' || $_POST['city'] != '')) { //comparison (==) if ($_POST['state'] == '') { } else { } } ?> Link to comment https://forums.phpfreaks.com/topic/234584-no-error-but-mysql-wont-update/#findComment-1205556 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.