Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP JSON data build and form submission redirect on one page
    primarykey
    data
    text
    <p>I am trying to build some graphs using PHP and Google Charts. I have a PHP page that contains a form where the user chooses the information that they want to see displayed on a graph. The form contains data such as date range, total sales, net, etc. The form submits to GraphData.php. Here I want to generate the MySql query based on data received from the form submission. I use that data to build a JSON object for the Google Charts. Then submit a form containing the userid and session variables to the Graphs.php page. Here we use Ajax to grab the JSON data and create the Google Chart. I am having trouble with the redirect/form submission to Graphs.php. Is this possible? Here is my code for GraphData.php:</p> <pre><code>// mysql stuff here .... $result = mysql_query($sql, $myconn) or die(mysql_error()); //start the json data in the format Google Chart js/API expects to recieve it $data = array('cols' =&gt; array(array('label' =&gt; 'Month', 'type' =&gt; 'string'), array('label' =&gt; 'Ticket Sales', 'type' =&gt; 'number'), array('label' =&gt; 'Amount Bet', 'type' =&gt; 'number'), array('label' =&gt; 'Amount Won', 'type' =&gt; 'number'), array('label' =&gt; 'Total Net', 'type' =&gt; 'number')), 'rows' =&gt; array()); // loop through the results and add them to the json object while($row = mysql_fetch_row($result)) { $data['rows'][] = array('c' =&gt; array(array('v' =&gt; $row[0]), array('v' =&gt; $row[1]), array('v' =&gt; $row[2]), array('v' =&gt; $row[3]), array('v' =&gt; $row[4]))); } echo json_encode($data); echo("&lt;FORM id='redirect' name='redirect' method='POST' action='Graphs.php'&gt; &lt;INPUT type='hidden' name='userid' value='$userid'&gt; &lt;INPUT type='hidden' name='session' value='$session'&gt;' &lt;/form&gt;"); ?&gt; &lt;script type="text/javascript"&gt; function submit () { var frm = document.getElementById("redirect"); frm.submit(); } window.onload = submit; &lt;/script&gt; </code></pre> <p>The page successfully redirects to Graphs.php, but the form is not being submitted and I get an error saying that the JSON string is invalid. Is what I am trying to do indeed possible? Am I just doing it wrong? Or is there another way? Sorry if this is confusing. Let me know if you would like more information. Any help is appreciated! Thanks in advance!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload