I am developing a small php page.
When I click a submit button no takes any action, just forwards me to a blank page. Why does this happen?
Will can help me please?
Thank you all very much.
<?php
if(isset($_POST['update']))
{
$dbhost = '****';
$dbuser = '****';
$dbpass = '****';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql\_error());
}
$task = $_POST['task'];
$sql = "UPDATE tasks set idTask = '$task' , date = curdate(), hour = curtime(), status = '3' WHERE idTask = '$task'" ;
mysql_select_db('db_Tasks');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Task $task started
";
mysql_close($conn);
}
<form method="post" action="<?php $_PHP_SELF ?> ">
<table width="285px" border="0" cellspacing="1" cellpadding="2" style="background-color:#A4A4A4;">
<tr>
<td width="100">Task</td>
<td><input name="tarefa" type="text" id="tarefa"></td>
</tr>
<td>
<input name="update" type="submit" id="update" value="Start">
When I click a submit button no takes any action, just forwards me to a blank page. Why does this happen?
change $_PHP_SELF to this $_SERVER['PHP_SELF'];
You're using wrong code for redirecting, the good:
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
or you can use the shorter type
<form method="post" action="<?= $_SERVER['PHP_SELF']; ?>">
I have tried executing the code given by you, there seems to be no error but still as you said there is an error with the redirection of page.
Add the below code to check with the errors
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
OR
just check if you have added the path in your code for the variable $_PHP_SELF
OR
just change $_PHP_SELF to $_SERVER['PHP_SELF'];
In your form attributes give the action="Start_Task.php"