Forum Moderators: coopster

Message Too Old, No Replies

Simplest download script need help

         

expert_21

7:20 pm on Dec 8, 2003 (gmt 0)

10+ Year Member



I want to update the database using php, but i am not sure where to put the line. here's my php:

<html>
<head>
<title></title>
</head>

<?
$host = "localhost";
$user = "user";
$pass = "password";
$dbname = "database";

$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);

$query= "select * from 4images_images where image_id='" . $_POST['image'] . "'";
$result= mysql_query($query);
$row = mysql_fetch_array($result);
$filename=$row['image_media_file'];
$category=$row['cat_id'];

$file="http://www.url.com/4images/data/media"."/".$category."/".$filename;

echo "<p><a href=\"$file\">Download File</a></p>";
echo "<p><a href=\"http://url.com\">Back</a></p>";
echo" </body>";
echo" </html>";
?>

I want to update my database, by increasing the value by one from table 4images_images on field image_hits. The line should be:

UPDATE 4images_Images SET 4images_Hit=4Images_Hit + 1 WHERE Image_ID="Blah blah";

but where do i put it? Thanks for helping.

jatar_k

7:34 pm on Dec 8, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could put it anywhere after your select_db function call, it doesn't really matter. I might put it after the echo for the closing html tag but there isn't really any rhyme or reason to the choice.

expert_21

12:35 am on Dec 9, 2003 (gmt 0)

10+ Year Member




<html>
<head>
<title></title>
</head>

<?
$host = "localhost";
$user = "user";
$pass = "password";
$dbname = "database";

$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);

$query= "select * from 4images_images where image_id='" . $_POST['image'] . "'";
$result= mysql_query($query);
$row = mysql_fetch_array($result);
$filename=$row['image_media_file'];
$category=$row['cat_id'];

UPDATE 4images_Images SET 4images_Hit=4Images_Hit + 1 WHERE Image_ID="Blah blah";

$file="http://www.url.com/4images/data/media"."/".$category."/".$filename;

echo "<p><a href=\"$file\">Download File</a></p>";
echo "<p><a href=\"http://url.com\">Back</a></p>";
echo" </body>";
echo" </html>";
?>

Is this right then? Thank you.

jatar_k

12:48 am on Dec 9, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



sorry expert, let me be a little more explicit.

$query1 = "UPDATE 4images_Images SET 4images_Hit=4Images_Hit + 1 WHERE Image_ID='Blah blah'";
$uptest = mysql_query($query1);

same as usual, you put the query into a variable and then use the mysql_query function to send the query to mysql.

now $uptest would be true if the query succeeded and false if it didn't. You can handle this as well if you need to. It will at least help while debugging during development.

if ($uptest) {
echo "<p>update query successful!";
} else {
echo "<p>update failed";
}