Reputation: 83
and this is my function i used to call the query to update the values in the database:
function updatabout($detailsarr)
{
$query = "UPDATE User_details SET Marital_status='" .
$detailsarr['m_status'] . "', Ethnicity='" .
$detailsarr['ethinicity'] . "', Primary_language='" .
$detailsarr['language'] . "', Education_level='" .
$detailsarr['education'] .
"' WHERE User_id=".$_SESSION['uid'];
$queryresult = mysql_query($query);
echo mysql_error().'<br />'.$query;
}
here all the data are saving into my database except the "hobby" field and the value of the hobby field is showing as "undefined" in my database, as well as after clicking the save button, i'm getting the alerts & query what i used here but the values are displaying on the page only after refreshing the page...can anyone please letme know what the fault i've in this code...thanks in advance..
Upvotes: 0
Views: 106
Reputation: 1966
UPDATE ok, Now I see you have edited and corected the mistake in your code in question. But still <?php =$hobby ?>
doesn't make sense to me. It tells nothing to do to PHP parser. Use echo
there, as explained in my answer.
The only possible explanation of your problem is that the code being used in producing the hobby
input field, specifically this fragment value=<?=$hobby?>
is having problem.
Reason:
PHP processes a <?
and <?
differently. Former is echoed as-it-is, and latter tells PHP that PHP code is started at this point, and process it. Then an un-neccesarry =
and missing ;
.
Solution:
First of all use value="<?php echo $hobby; ?>"
Use of full PHP tags () is always recommended over short tags () Then you need to tell PHP to echo/print the value of $hobby
here by using echo
. Now the output HTML should be value="_Some_Hobby_"
Now, if still the output HTML is value=""
i.e. empty, then you need to check if $hobby
actually holds a value.
As seen at http://codepad.org/dvf9bwSd in Case 3,
value="<?php echo $hobby; ?>"
PHP Parser just chunks out the <php .... ?>
thing as-it-is. So use literal <
& >
.
Now, in Case 1,
value="<?php echo $hobby; ?>"
<?php
var_dump($hobby);
?>
echoing $hobby
variable without assigning it any value prints nothing. And var_dump
also returns NULL
Moving on to case-2,
<?php
$hobby = "Coding";
?>
value="<?php echo $hobby; ?>"
<? var_dump($hobby); ?>
defining/assigning a value to $hobby
and then echoing it gives us the desired result value="Coding"
and var_dump
also says it is a String
of length=6
Upvotes: 1
Reputation: 5302
Maybe the reason why your code is not executing as expected because you didn't escape the data that is being passed on your server side script.
Try using escape
javascript function.
Try this one:
"m_status=" + escape(barr[0]) + "ðinicity=" + escape(barr[1]) + "&language=" + escape(barr[2]) +" &education=" +escape( barr[3]) + "&hobby=" + escape(barr[4])
You might also want to use firebug(firefox) or console(chrome) tool so that you will able to know the value that was being passed on your server side script.
Upvotes: 0