Jump to content

No Error, but MySQL won't Update


unemployment

Recommended Posts

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

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')"); 
?>

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 {

     }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.