Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to do a couple of things: </p> <p>1- Make sure you test $tablename[ArtistImage] against a whitelist of tablenames before you inject it into your query.<br> If you don't you are still open to SQL-injection, because escaping only works for values, not for table or column names <em>(or other SQL syntax)</em> that you dynamically inject into your SQL-statements. </p> <pre><code>$tbl_name = ...... $allowed_tables = array('table1', 'table2'); if (in_array($tbl_name, $allowed_tables)) { $query = "...... } else { echo "tablename not allowed"; } </code></pre> <p>2 - Add a space between the tablename and <code>VALUES</code></p> <pre><code>$insertQuery= "INSERT INTO `$tbl_name` VALUES('".$image['name']."')"; </code></pre> <p>See: <a href="https://stackoverflow.com/questions/5811834/how-to-prevent-sql-injection-with-dynamic-tablenames">How to prevent SQL injection with dynamic tablenames?</a></p> <p>A much simpler answer is to <strong>never</strong> let the user specify where a file should be saved, or how it is named (on the filesystem).<br> Follow @Marc B's advice and only store the desciption in the database and use the PK (id) as the filename. </p> <pre><code>$description = mysql_real_escape_string($_POST['description']); $query = "INSERT INTO images (description) VALUES ('$description')" $result = mysql_query($query); $id = mysql_insert_id; //get the id you just inserted. $filename = "../fixed_path/".$id.".jpg"; if (!move_uploaded_file($image['tmp_name'], $filename)) { echo "this should never happen" } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload