Update Image against URL ID

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!

Moderator: General Moderators

Post Reply
sardar_sajjad
Forum Newbie
Posts: 2
Joined: Sat Jan 15, 2011 11:18 pm

Update Image against URL ID

Post by sardar_sajjad »

[text]Dear
I am not good in PHP but I try following code to insert or update image against URL ID but when I check in database no updation or insertion found. Kindly check the code my be coding error is it.I have two pages. add.html and inert.php

URL script is <a href="insert.php?property_id=$property_id" class="txt_content03_bold">Add Photos</a>&nbsp;&nbsp;&nbsp;</td>

URL code is http://www.mysite.com/insert.php?property_id=6

add.html is as follow

<html>
<form enctype="multipart/form-data" action="insert.php" method="post" name="changer">
<input name="MAX_FILE_SIZE" value="102400" type="hidden">
<input name="image" accept="image/jpeg" type="file">
<input value="Submit" type="submit">

</html>


insert.php is follow


<?php

include_once("add.html");
$id = $_POST['property_id'];
$username = "okokok";
$password = "okokok";
$host = "localhost";
$database = "okokok";

// Make the connect to MySQL or die
// and display an error.
$link = mysql_connect($host, $username, $password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}

// Select your database
mysql_select_db ($database);


//$ordercode = $_POST['ordercode'];
//$property_id=getVal(property_id);

if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {


// Temporary file name stored on the server
$tmpName = $_FILES['image']['tmp_name'];

// Read the file
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);


// Create the query and insert
// into our database.

$query = "update qatproperty_mst set image ='$data' WHERE property_id ='$id'";

//in URL code property_id is 6 so when I enter property_id=6 (manually) it works fine in above $query updation but when if it is like this property_id ='$id' its not getting property_id from URL and no record //was updated.property_id is primary key in the table and also auto increase.

$results = mysql_query($query, $link);

// Print results
print "Thank you, your file has been uploaded.";

}
else {
print "No image selected/uploaded";
}

// Close our MySQL Link
mysql_close($link);

?>

Kindly help be and thanks in advance.
[/text]
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: Update Image against URL ID

Post by Neilos »

I see that you get $id from here;
sardar_sajjad wrote:

Code: Select all

$id = $_POST['property_id'];
But you aren't setting it here;
sardar_sajjad wrote:

Code: Select all

<form enctype="multipart/form-data" action="insert.php" method="post" name="changer">
<input name="MAX_FILE_SIZE" value="102400" type="hidden">
<input name="image" accept="image/jpeg" type="file">
<input value="Submit" type="submit">
So it would seem that $_POST['property_id'] doesn't exist. Could you include it in the form in another hidden input?

I don't know what these bits are, why have you included them in the post?
sardar_sajjad wrote:

Code: Select all

<span style="font-weight: bold">URL script is</span> <a href="insert.php?property_id=$property_id" class="txt_content03_bold">Add Photos</a>&nbsp;&nbsp;&nbsp;</td>

<span style="font-weight: bold">URL code is http://www.mysite.com/insert.php?property_id=6</span>
sardar_sajjad
Forum Newbie
Posts: 2
Joined: Sat Jan 15, 2011 11:18 pm

Re: Update Image against URL ID

Post by sardar_sajjad »

<html>

<form enctype="multipart/form-data" action="insert.php" method="post" name="changer">
<input name="MAX_FILE_SIZE" value="102400" type="hidden">

<input type="hidden" name="property_id" value="$_POST['property_id']" >

<input name="image" accept="image/jpeg" type="file">
<input value="Submit" type="submit">

</html>

is it like that.

can you edit add.html for me
Post Reply