...

View Full Version : PHP and mysql help



cip6791
02-14-2010, 09:19 AM
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
$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>

abduraooft
02-14-2010, 06:19 PM
Just include your update.php file into the above, like

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 (http://seancoates.com/xss-woes).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum