PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have a page that finds a db record and passes the id onto an imgage upload page.
The uploading part works fine - i can save images to the server. No problem. What I also need is when I upload the image, the name of the image (eg example.gif) gets copied into a image_name field on my db.
<form name="form1" method="post" action="" enctype="multipart/form-data">
<input type="file" name="imagefile">
<br>
<input type="submit" name="Submit" value="Submit">
<?
if(isset( $Submit ))
{
//If the Submitbutton was pressed do:
if ($_FILES['imagefile']['type'] == "image/gif"){
copy ($_FILES['imagefile']['tmp_name'], "images/classpix/".$_FILES['imagefile']['name'])
or die ("Could not copy");
echo "";
echo "Name: ".$_FILES['imagefile']['name']."";
echo "Size: ".$_FILES['imagefile']['size']."";
echo "Type: ".$_FILES['imagefile']['type']."";
echo "Copy Done....";
}
else {
echo "<br><br>";
echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
}
}
$username="xxxx_xxxx";
$password="xxxx";
$database="xxxx_xxxx";
// saving script
// connect to the server
mysql_connect( 'localhost', $username, $password )
or die( "Error! Could not connect to database: " . mysql_error() );
// select the database
mysql_select_db( $database )
or die( "Error! Could not select the database: " . mysql_error() );
// get the variables from the URL GET string
$id = $_GET['id'];
//set image_name
$image_name = $_FILES['imagefile']['name'].
// if $id is not defined, we have a new entry, otherwise update the old entry
$query = "UPDATE newsstuf_usedcars SET image_name='$image_name' WHERE `id`='$id'";
// save the info to the database
$results = mysql_query( $query );
?> </form>
<form name="form1" method="post" action="" enctype="multipart/form-data">
<input type="file" name="imagefile">
<br>
<input type="submit" name="Submit" value="Submit">
<?
if(isset( $Submit ))
{
//If the Submitbutton was pressed do:
if ($_FILES['imagefile']['type'] == "image/gif"){
copy ($_FILES['imagefile']['tmp_name'], "images/classpix/".$_FILES['imagefile']['name'])
or die ("Could not copy");
echo "";
echo "Name: ".$_FILES['imagefile']['name']."";
echo "Size: ".$_FILES['imagefile']['size']."";
echo "Type: ".$_FILES['imagefile']['type']."";
echo "Copy Done....";
}
else {
echo "<br><br>";
echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
}
}
$username="xxxx_xxxx";
$password="xxxx";
$database="xxxx_xxxx";
// saving script
// connect to the server
mysql_connect( 'localhost', $username, $password )
or die( "Error! Could not connect to database: " . mysql_error() );
// select the database
mysql_select_db( $database )
or die( "Error! Could not select the database: " . mysql_error() );
// get the variables from the URL GET string
$id = $_GET['id'];
//set image_name
$image_name = $_FILES['imagefile']['name'].
// if $id is not defined, we have a new entry, otherwise update the old entry
$query = "UPDATE newsstuf_usedcars SET image_name='$image_name' WHERE `id`='$id'";
// save the info to the database
$results = mysql_query( $query );
?> </form>
just print the query and you will get to know wheather the is correct or not? then you can findout wots the probelm is ?