08-05-2009, 01:54 PM
|
#9 (permalink)
|
|
The Contributor
Join Date: Mar 2009
Location: US
Posts: 76
Thanks: 0
|
php Code:
$filename = $_POST[ 'imageq']; $filename = mysql_real_escape_string($filename); if (! $bonushsystemconnect) { die('Could not connect: ' . mysql_error()); }mysql_select_db("bonush_sy6", $bonushsystemconnect); // I can inject anything i want here$imageresult = mysql_query('SELECT id FROM isearch WHERE imageurl="'. $filename. '"'); if(mysql_num_rows($imageresult) > 0) {print "Already In DB"; end; }else{ //congrats! you added an apple to the basket. $ran = md5(uniqid(mt_rand(), true)); $size = getimagesize($filename); switch ($size[ 'mime'] ) { case "image/gif": $type= ".gif"; break; case "image/jpeg": $type= ".jpg"; break; case "image/png": $type= ".png"; break; case "image/bmp": $type= ".bmp"; break; } $test = $ran; $test = $test. ''. $type; $fh = fopen("$test", 'w') or die("can't open file"); if($fh== false) die("unable to create file"); if(!@ copy ($filename, $test)){ $errors= error_get_last (); echo "COPY ERROR: ". $errors[ 'type']; echo "<br />\n". $errors[ 'message']; } else { echo "File copied from remote!"; // AND HERE$sql= 'INSERT INTO isearch (site, imageurl, oururl, keywords) VALUES ("Peter", "'. $filename. '", ".$test.'", "lol ")';
if (!mysql_query($sql, $bonushsystemconnect)) { die('Error: ' . mysql_error()) } echo "1 record added "; } }
Updated your code to include mysql injection prevention and your SQL queries to run without causing errors.
If you ran the code as you posted the SQL fails because it does not properly parse the query. When you are performing SQL queries it is always easier to use single quotes for the string.
@See
; http://us.php.net/manual/en/language....syntax.single
For more information
AND
http://us2.php.net/manual/en/functio...ape-string.php
For information on SQL injection
|
|
|
|