Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Banned
    Join Date
    Oct 2007
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Increment Number

    How do I create a link, that when clicked, increments a number value stored in a database?

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Location
    Raleigh, NC
    Posts
    273
    Thanks
    7
    Thanked 59 Times in 52 Posts
    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):

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

  • #3
    Banned
    Join Date
    Oct 2007
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

    Code:
    <?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";
    }
    ?>

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •