I am trying to upload an image and rename image at the same time. But, it shows an error. I have tried to find a solution, but hard luck. Can anyone help me?
Below is my code.
<?php
include('connection.php');
$sql="select * from upload";
$query=mysql_query($sql) or die("query failed".mysql_error());
if(mysql_num_rows($query)>0) {
$sql="select id from upload";
$query=mysql_query($sql) or die("query failed".mysql_error());
while($row=mysql_fetch_array($query)) {
$id=$row[0];
}
} else {
$id='1';
}
move_uploaded_file($_FILES["file"]["name"],"upload/".$id.$_FILES["file"]["name"]);
$query1 = "insert into upload(image) values('.$id.$_FILES["file"]["name"].')";
mysql_query($query1) or die("query failed1".mysql_error());
?>