...

View Full Version : Increment Number



Cerby
11-14-2007, 06:32 PM
How do I create a link, that when clicked, increments a number value stored in a database?

vtjustinb
11-14-2007, 06:37 PM
You could just point the link to a php page that queries the database and increments the value.

<a href="increment.php">Click here to make that number large by one for some reason</a>

increment.php (assuming a mysql imp):



mysql_connect(...);
mysql_select_db(...);
mysql_query('UPDATE table SET number=number+1 WHERE id=theID');
header("Location: oldpage.html");
exit;

Cerby
11-14-2007, 06:54 PM
The following code, is what I developed in order to upload the files and store the path in the database.

How do I display all the uploaded file paths contained in the database, for each record?


<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die(mysql_error());
}

mysql_select_db("MP3s", $con);

if (($_FILES["file"]["type"] == "audio/mpeg"))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
$file = ("upload/" . $_FILES["file"]["name"]);
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];

mysql_query("INSERT INTO Music (Path)
VALUES('$file')");
}
}
}
else
{
echo "Invalid file";
}
?>

aedrin
11-14-2007, 09:01 PM
Please make only 1 topic per question. And the opposite also applies. Only 1 question per topic.

You already asked about this here:

http://www.codingforums.com/showthread.php?t=127794



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum