-3

I have 2 to 3 tables in MYSQL and otherthing is working fine but one issue is creating the problem.

When I'm closing the request from select row its showing database not selected.

Here is the code:

    <a href="viewRequest.php?reqId=<?=$row_rsRequests['reqId'];?>&action=4" onclick="return confirm('Are you sure you want to close ?')">Close</a>

in Action code is:

if($_GET['reqId'] && $_GET['action']==4)
{
    $sqlClose="update vnd_requests set status=4,updateBy='".$_SESSION['MM_Username']."',updateOn='".time()."',updateByIP='".getRealIpAddr()
        ."' where reqId=".$_GET['reqId'];
 mysql_query($sqlClose, $myB2b) or die(mysql_error());
}
Junaid
  • 1
  • 3
  • 1
    So are you selecting database? If php says you something - I don't see a reason to not trust it. – zerkms Jul 06 '14 at 08:11
  • So `mysql_select_db()` the database ! And please search for the answer yourself before asking a question. Just google on your error message. – nl-x Jul 06 '14 at 08:11
  • So I can basically type `reqId=anything` in my browser location bar and you will run custom SQL for me? – Álvaro González Jul 06 '14 at 08:14

1 Answers1

0

A few hints.

  1. The mysql extension has been deprecated in PHP 5.5.0 and it will be discontinued in the future versions of PHP. I recommend you to use mysqli (or PDO MySQL) instead;
  2. You should really sanitize your input in order to avoid SQL injection. mysqli supports prepared statements that can be helpful to achieve this goal;
  3. The error message is self-explaining. You probably forgot to select the MySQL database. To do so with the mysql extension (the one you are using), just add mysql_select_db("<YOUR_DATABASE_NAME>"); before the query.
Emanuele Casadio
  • 585
  • 5
  • 13