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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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.