Sign in to follow this  
saghar

Invalid Data Error, String Method

Recommended Posts

I have a form that posts values to a php file which includes a FC graph. When I do not choose any option in the form page, the chart is drawn properly. But when I choose "month" and submit the form, I get the "invalid data" error. I checked everything and seems that data is passed correctly between pages. Here is my code, can you help me on this please?

 

 

<?php

//We have included ../Includes/FusionCharts.php, which contains functions

//to help us easily embed the charts.

include("../Includes/FusionCharts.php");

?>

<html>

<head>

<?php

//You need to include the following JS file, if you intend to embed the chart using JavaScript.

//When you make your own charts, make sure that the path to this JS file is correct. Else, you

//will get JavaScript errors.

?>

<script language="Javascript" src="../FusionCharts/FusionCharts.js"></script>

<title>FusionCharts XT - Simple Column 3D Chart using dataStr method</title>

</head>

<body>

<?php

$strMonth = $_POST['month'];

if ($strMonth=="0")

{

$strMonth="1=1";

}

else

{

$strMonth = "month = '".$strMonth."'";

}

 

$server = "myserver:3306";

$username = "myusername";

$password = "mypassword";

$db_name = "mydb";

$db = mysql_connect($server,$username,$password) or DIE("Connection to database failed, perhaps the service is down!!");

mysql_select_db($db_name,$db) or DIE("Database name not available !!");

 

$strXML = "";

$strXML .= "<chart paletteColors='b0e0e6, 00008b, ffe4c4, d2b4be, 9885d3, 42f1d2, 258998, f4a460, dc143c, d3d3d3, 20b2aa' caption='Cost by Category/Brand' xAxisName='Category' yAxisName='Cost (Million)' showLabels='1' showvalues='1' decimals='2' numberPrefix='$' clustered='0' exeTime='1.5' showPlotBorder='0' zGapPlot='30' zDepth='90' divLineEffect='emboss' startAngX='10' endAngX='18' startAngY='-10' endAngY='-40' showAboutMenuItem='More insightfull data'>";

 

 

$sql="SELECT category, cost FROM mytable WHERE ".$strMonth." GROUP BY category ORDER BY cost DESC";

$result=mysql_query($sql);

 

while($row = mysql_fetch_row($result)){

$strXML .= "<set label='$row[0]' value='$row[1]'/>";

}

$strXML .= "</chart>";

 

echo renderChart("../FusionCharts/Column3D.swf", "", $strXML, "myNext", 600, 300, false, true);

?>

</body>

</html>

Share this post


Link to post
Share on other sites
Guest Sashibhusan

Hi Saghar,

 

Could you please confirm once, whether the SQL query executes correctly for any month value selected, and returns the desired data from the database?

 

You can print the $row[0] and $row[1] values inside the "while" loop to check, if SQL query returns proper value.

 

Hope this helps!

Share this post


Link to post
Share on other sites

Yes, my query returns correct results. Anything else that I need to check?

Hi Saghar,

 

Could you please confirm once, whether the SQL query executes correctly for any month value selected, and returns the desired data from the database?

 

You can print the $row[0] and $row[1] values inside the "while" loop to check, if SQL query returns proper value.

 

Hope this helps!

Share this post


Link to post
Share on other sites
Guest Sashibhusan

Hi Saghar,

 

If your query returns correct results then, it seems there is no issues with the code.

 

Could you please provide the generated XML string (i.e. the output of $strXML, just before passing to FusionCharts PHP function renderChart()), so that we can test it from our end?

 

Awaiting your response!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this