1

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 \n";
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">

enter image description here

When I click a submit button no takes any action, just forwards me to a blank page. Why does this happen?

enter image description here

Cœur
  • 37,241
  • 25
  • 195
  • 267
rpirez
  • 431
  • 2
  • 8
  • 20
  • 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 Sep 12 '14 at 09:31
  • 1
    Presumably it gives you a blank page because it is hitting your `die` statement. – Quentin Sep 12 '14 at 09:32
  • 1
  • 1
    Just leave your action blank, it should return to the same page. It's `$PHP_SELF` btw, not `$_PHP_SELF` as far as I know. – Dorvalla Sep 12 '14 at 09:33
  • Thanks everyone for the advice and the warnings. I started now programming php and I intend to improve. Thank you all for help, were incredible. @Quentin thanks for your advice, i will study more php and improve my code. – rpirez Sep 12 '14 at 09:43

4 Answers4

4

change $_PHP_SELF to this $_SERVER['PHP_SELF'];

Miks
  • 114
  • 8
1

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']; ?>">
0

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'];

Sarang
  • 754
  • 3
  • 9
  • 24
0

In your form attributes give the action="Start_Task.php"