The isset () function can be used to check if the input button is of type submit , but is there a way to check whether the button of type input is pressed?
In my code, the button does nothing except call the function for the .Onclick () event, which then refreshes the page and records in the database inside PHP ... and I want it to record only after the button is clicked ... and I I canβt use the send type for other reasons ... the following code:
function send() { var events = document.getElementById("event").value; location.href = "calm.php?day=" + xx + "&month=" + yy + "&year=" + zz + "&events=" + events; } <input name="Button" type="button" id="submit" onclick="send(this.form)" value="Button" /> <?php session_start(); include_once "connect_to_mysql.php"; $day = $_GET['day']; $month = $_GET['month']; $year = $_GET['year']; $events = $_GET['events']; $userid = $_SESSION['id']; if (isset($_POST['button'])) { $sql = mysql_query("INSERT INTO events (userid,month,day,year,events) VALUES('$userid','$month','$day', '$year','$events')") or die (mysql_error()); } ?>
source share