nysmenu Posted August 20, 2009 Share Posted August 20, 2009 Guys, I have this scrip to send images into a db. the problem is that it won't post into the db. Can someone please show me what I'm doing wrong. Thanks <?php $cn = mysql_connect("localhost","pass","pass"); mysql_select_db("db_image",$cn); if ($act=='view'){ $sql="SELECT * FROM tbl_image where id=$id"; $rst=mysql_query($sql) or die('sorry'); $data=mysql_fetch_array($rst); $type=$data[type]; Header("Content-type: $type"); echo $data[image]; } if ($act=='del'){ $sql="DELETE FROM tbl_image where id=$id"; $rst=mysql_query($sql) or die('sorry'); } if($submit) { $type = $_FILES['file']['type']; copy ($_FILES['file']['tmp_name'], "tmp/tmp.jpg") or die ("Could not copy"); $filer="tmp/tmp.jpg"; $handle = fopen($filer, "r"); $pure = addslashes(fread($handle, filesize($filer))); $sql = "insert into tbl_image(image,type) values('$pure','$type')"; $result = mysql_query($sql,$cn)or die(mysql_error()); } $sql="SELECT * FROM tbl_image"; $rst=mysql_query($sql) or die('sorry'); while ($data=mysql_fetch_array($rst)){ $id=$data[id]; echo "picture no $id <a href='./image.php?act=del&id=$id'>delete</a><br><img src='./image.php?act=view&id=$id'><br><br>"; } ?> Link to comment https://forums.phpfreaks.com/topic/171175-help-with-image-sending-script/ Share on other sites More sharing options...
play_ Posted August 20, 2009 Share Posted August 20, 2009 Debug. echo $sql, what does it output? Link to comment https://forums.phpfreaks.com/topic/171175-help-with-image-sending-script/#findComment-902669 Share on other sites More sharing options...
ignace Posted August 20, 2009 Share Posted August 20, 2009 if($submit)?? $submit isn't even defined. Use if (!empty($_POST)) Link to comment https://forums.phpfreaks.com/topic/171175-help-with-image-sending-script/#findComment-902671 Share on other sites More sharing options...
nysmenu Posted August 20, 2009 Author Share Posted August 20, 2009 if($submit)?? $submit isn't even defined. Use if (!empty($_POST)) This seems to be working and now I'm getting this: Warning: copy(tmp/tmp.jpg) [function.copy]: failed to open stream: No such file or directory in C:\wamp\www\websites\test\image.php on line 22 Could not copy This is not my script, therefore, I do not know what "(tmp/tmp.jpg)" this is. Link to comment https://forums.phpfreaks.com/topic/171175-help-with-image-sending-script/#findComment-902694 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.