0

I would like to send data from my mysql database to a PHP page.

The server were I have this script classify the file that has been uploaded just before this php comes into action, then the server enters the data into the database.

The PHP script should show that data (the column where the interesting data is it's called "cond"). My code is the following:

 $uploaddir = '/opt/lampp/htdocs/u';
 $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
 $link = mysql_connect("localhost", "pepito", "dominguez");
 $nombre=basename($_FILES['userfile']['name']);
 $tamany=basename($_FILES['userfile']['size']);
 $sql="INSERT INTO `wordpress`.`uploads` (`autoinc`, `nombre`, `tamany`,`fecha`) VALUES (NULL, '$nombre', '$tamany', CURRENT_TIMESTAMP)";
 $sqls="SELECT `cond` FROM `cm` WHERE `id`='$numero'";


 if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
   //  echo "File is valid and it's fully uploaded";
     mysql_select_db('wordpress');
     mysql_query($sql);
     $numero=mysql_insert_id();
     $condicion=0;
     sleep(3);
     $condicion= mysql_query($sqls);
     $a = $condicion + 1;
     echo "$a";
     echo "$numero";

What I should get in te echo "$a" is a number between 0 to 2, but what I get is a random number that changes everytime a file is uploaded.

I also have tried to get the 'id' column instead the 'cond' column and it does exactly the same.

Extra data: I'm using wordpress, and a plugin which is called "allow-php-in-posts-and-pages". The other echo in the code works properly.

1

1 Answer 1

1

You need to fetch the result after executing the query. You also should have use the $numero once it is set, so move the $sqls into the conditional after the insert.

http://php.net/manual/en/function.mysql-query.php

mysql_select_db('wordpress');
mysql_query($sql);
$numero=mysql_insert_id();
$sqls= "SELECT `cond` FROM `cm` WHERE `id`='$numero'";
$result = mysql_query($sqls);
if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}
$row = mysql_fetch_assoc($result);
$condicion = $row['cond'];

You should switch over from the mysql_ driver to the mysqli_ or PDO, PHP PDO and MySQLi.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.