Note that there are some explanatory texts on larger screens.

plurals
  1. POOSCommerce tep_db_input vs tep_db_prepare_input
    primarykey
    data
    text
    <p>I am working on a project that uses OSCommerce with MySQL and I'm confused as to when I should use tep_db_input() or tep_db_prepare_input(). I'd assume I should use tep_db_input() around any strings that are being inserted/updated, but then when should the other function be used?</p> <p>For example, if I were to <em>SELECT</em> some data from the database, and use the result to then <em>INSERT</em> a row into another table, do I need to prepare the input at some point? Or just use tep_db_input again?</p> <pre><code>$width = '3"'; // 3 inches $new_height = '3\' 5"'; // 3 feet 5 inches $result = tep_db_query( "SELECT height FROM measurements WHERE width = '".tep_db_input($width)."'" ); while ($row = tep_db_fetch_array($result)) { tep_db_query( "INSERT INTO measurement_history ( field, old_value, new_value ) VALUES ( 'height', '".tep_db_input($row['height'])."', '".tep_db_input($new_height)."' )" ); } </code></pre> <p>Is this correct?</p> <p><strong>Edit::</strong> In case anyone isn't familiar with those functions, here are their definitions:</p> <pre><code>function tep_sanitize_string($string) { $patterns = array ('/ +/','/[&lt;&gt;]/'); $replace = array (' ', '_'); return preg_replace($patterns, $replace, trim($string)); } function tep_db_input($string, $link = 'db_link') { global $$link; if (function_exists('mysql_real_escape_string')) { return mysql_real_escape_string($string, $$link); } elseif (function_exists('mysql_escape_string')) { return mysql_escape_string($string); } return addslashes($string); } function tep_db_prepare_input($string) { if (is_string($string)) { return trim(tep_sanitize_string(stripslashes($string))); } elseif (is_array($string)) { reset($string); while (list($key, $value) = each($string)) { $string[$key] = tep_db_prepare_input($value); } return $string; } else { return $string; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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