Updates Image doesnt work
Hi Guys,
I got a problem with updating images in mysql database wih php form.
It succesfully inserted the images into the database, but it can't do any updates/changes on the existing image record.
Thanks
PHP Code:
<?
session_start ();
include( "database.php" );
include( "login.php" );
$pro_id = $_POST [ 'pro_id' ];
$pro_name = $_POST [ 'pro_name' ];
$pro_cat = $_POST [ 'pro_cat' ];
$pro_desc = $_POST [ 'pro_desc' ];
$pro_price = $_POST [ 'pro_price' ];
if (isset( $_POST [ 'edit' ]))
{
$name = $_FILES [ 'myfile' ][ 'name' ];
$tmp_name = $_FILES [ 'myfile' ][ 'tmp_name' ];
if( $name )
{
$location = "image/ $name " ;
move_uploaded_file ( $tmp_name , $location );
$sql = "UPDATE product SET pro_name =' $pro_name ', pro_cat =' $pro_cat ', pro_desc =' $pro_desc ', pro_price =' $pro_price ', location =' $location ' WHERE pro_id =' $pro_id '" ;
$result = mysql_query ( $sql );
echo "<br>Product has been Edited.<br><br><br>" ;
die();
}
}
$sql = mysql_query ( "SELECT * FROM product where user_id = ' $_SESSION [ user_id ] 'and pro_cat = ' $pro_cat ' ORDER by pro_id ASC" )or die( mysql_error ());
while( $row = mysql_fetch_array ( $sql ))
{
$location = $row [ imagelocation ];
?>
bla...bla...bla....bla
bla...bla...bla....bla
<td>
<? echo "<img src=' $location ' width ='250' height='250'>"
</ td >
< TD > Image :</ TD >
< TD >< input name = 'myfile' type = 'file' ></ TD >
</ TR >< br >
< input type = 'hidden' name = 'pro_id' maxlength = '60' value = '<?php echo $row[' pro_id ']; ?>' >
< tr >< td colspan = '2' align = 'right' >
< input type = 'submit' name = 'edit' value = 'Edit Product' >
</ td ></ tr >
</ table >
</ form >
<?
}
?>
Maybe try adding parentheses around the items your updating like this...
PHP Code:
$sql = "UPDATE product SET (pro_name=' $pro_name ', pro_cat=' $pro_cat ', pro_desc=' $pro_desc ', pro_price=' $pro_price ', location=' $location ') WHERE pro_id=' $pro_id '" ;
It may seem odd that it would fix it, but I've gotten results from it with my own experiences in the past using similar syntax.
Hope this helps.
- Josh
Website Coder and Pixel Artist
If you will add else part as mentioned below. This may work.
if($name)
{
$location = "image/$name";
move_uploaded_file($tmp_name, $location);
$sql = "UPDATE product SET pro_name ='$pro_name', pro_cat ='$pro_cat', pro_desc ='$pro_desc', pro_price ='$pro_price', location ='$location' WHERE pro_id ='$pro_id'";
$result = mysql_query($sql);
echo "<br>Product has been Edited.<br><br><br>";
die();
} else {
$sql = "UPDATE product SET pro_name ='$pro_name', pro_cat ='$pro_cat', pro_desc ='$pro_desc', pro_price ='$pro_price', location='' WHERE pro_id ='$pro_id'";
$result = mysql_query($sql);
echo "<br>Product has been Edited.<br><br><br>";
die();
}
Are you checking if $name is true or if it has a value?
versus
PHP Code:
if(isset( $name ))
Or perhaps you are checking that the contents of $name are set and have some value?
PHP Code:
if(isset( $name ) && strlen ( $name )> 0 )
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks