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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question PHP and mysql help

    Hi,

    I am using the code below to open a new tab with a link that I provide. So if I write books a new tab opens up with http://www.example.com/books. I would like to write that to a database. My <form> already has an action it is "action="<?=$_SERVER['REQUEST_URI']?>" ". In order for the script to write into a database, it would have to point to another file ... an update.php that contains the mysql query, password, database name and so on. So to make things short, how do I change the action without affecting the functionality of the already working script?
    PHP Code:
    <?php
    $sites 
    = array();


    $sites['example'] = "http://www.example.com/%u";


    if(isset(
    $_POST['submit']) && !empty($_POST['page']) && !empty($sites[$_POST['site']])){    
        
    $url str_replace('%u',$_POST['page'],$sites[$_POST['site']]);
        
    header("Location: {$url}");
    }
    ?>
    <html>
    <body>
    <form target="_blank" action="<?=$_SERVER['REQUEST_URI']?>" method="POST">
    <select name="site" id="site">
    <? foreach($sites as $key=>$site){?>
    <option value="<?=$key?>"><?=$key?></option>
    <?}?>
    </select>
    <input type="text" name="page" />
    <input type="submit" name="submit" value="Go" />
    </form>
    </body>
    </html>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Just include your update.php file into the above, like
    PHP Code:
    if(isset($_POST['submit']) && !empty($_POST['page']) && !empty($sites[$_POST['site']])){    
        include 
    "update.php";
        
    $url str_replace('%u',$_POST['page'],$sites[$_POST['site']]);
        
    header("Location: {$url}");

    My <form> already has an action it is "action="<?=$_SERVER['REQUEST_URI']?>" ".
    You form is susceptible to xss attacks.
    Last edited by abduraooft; 02-14-2010 at 06:22 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    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
    •