-1

I am trying to make an application with a calendar. What I want is that when the user click to a date of the calendar, to have a output form below where the data appears, and a div tag, where i load the result of the php page. In the php file I ask to upload the result from the database where the date is the same with the one that the user has choose.. But it gives me an error after I click the date:

Notice: Undefined index: dataoutput in C:\xampp\htdocs\rai kalendar\insert.php on line 16

My html file is:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
    window.onload = function(){


        g_globalObject = new JsDatePick({
            useMode:1,
            isStripped:true,
            target:"div3_example"

        });     


         g_globalObject.setOnSelectedDelegate(function(){
            var obj = g_globalObject.getSelectedDay();
           document.getElementById("dataoutput").innerHTML = obj.year + "-" + obj.month + "-" +obj.day;
            $('#div3_example_result').load('insert.php');               
        });


        };

</script>
</head>
<body>

    <div id="div3_example" style="margin-left: 500px; margin-top: 100px; border:dashed 1px red; width:205px; height:230px;">

    </div>

    <form id="dataform" method="post" action="insert.php">
    <output name="dataoutput" id="dataoutput" type="submit">

    </output>

    </form>



    <div id="div3_example_result" style="height:20px; line-height:20px; margin:10px 0 0 0; border:dashed 1px #666;"></div>

</body>
</html>

and the part of php file is:

<?php


$result = mysql_query("SELECT * FROM Aktiviteti where Data= '$_POST[dataoutput]'");

if(!empty($result))
{

$row = mysql_fetch_row($result);

echo $row[0]; // 42
echo $row[1]; // the email value
echo $row[2]; // the email value


}
else
echo "Empty"
  ?>

and the line 16 is:

  $result = mysql_query("SELECT * FROM Aktiviteti where Data= '$_POST[dataoutput]'");

Why does this happen? Can i make the form submit in output line:

<output name="dataoutput" id="dataoutput" type="submit">

Please help me? What can I do?

user3272713
  • 167
  • 2
  • 5
  • 15
  • 1
    **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Feb 09 '14 at 13:33

1 Answers1

0

You need to pass the data to the server, the <output> tag doesn't magically do such a thing.

Correct code would be:

var data = obj.year + "-" + obj.month + "-" +obj.day;
$.post("insert.php", { "dataoutput": data }, function(result) {
    $("#div3_example_result").html(result);
});
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
  • Cheers! On a different matter, I strongly advise you to read about SQL Injection Attacks sometime soon, and change your PHP code to protect against those. – Shadow The GPT Wizard Feb 09 '14 at 13:42