gamercross Posted December 17, 2007 Share Posted December 17, 2007 I wanted to create a field that when someone enters a word such as hello, its goes to a page called: http://www.myurl.com/hello Although it seems complicated it is not, because i would of previously created these values in the database. For example: i add a new table to my database. Add an ID, and keyword which will be hello and then add a url which will be http://www.myurl.com/hello If someone enters helloeveryone, it will say please search or enter again, this is because that has not been entered yet in my database. Once i have entered all the keywords and urls i want in my database, i will need a php form and a connection script, which i believe is a CMS? Content Management System? I am a total newbie to php, i know some stuff like i have mentioned above but not with creating scripts so would be extremely grateful if anyone could help me and would be happy to add their url on my site. Thanks, Gamercross Gamercross.co.uk Quote Link to comment Share on other sites More sharing options...
kts Posted December 17, 2007 Share Posted December 17, 2007 I'd highly suggest you start reading some books on php basics, get familiar with how it works. Do some tutorials and run some practices and then get involved in databases. You really should understand the basics and then you will be able to make a script like that no problem. Quote Link to comment Share on other sites More sharing options...
p2grace Posted December 17, 2007 Share Posted December 17, 2007 I would try something like this: <? if(isset($_POST['url'])){ $url = $_POST['url']; $query = "SELECT `id`,`url` FROM `tbl` WHERE `keyword` = '$url'"; $run = mysql_query($query); $num = mysql_num_rows($run); if($num > 0){ $arr = mysql_fetch_assoc($run); extract($arr); header("Location: $url"); }else{ echo "<script type=\"text/javascript\">alert('Unable to find url!');</script>"; } } ?> <form name="redirectForm" id="redirectForm" action="index.php" method="post" enctype="multipart/form-data"> URL: <input type="text" size="20" id="url" name="url" /> <br /><br /> <input type="submit" value="Submit" /> </form> This is obviously a very simple example, but it should demonstrate what you have to do. Quote Link to comment Share on other sites More sharing options...
ahzulfi Posted December 17, 2007 Share Posted December 17, 2007 Create Table in Databse CREATE TABLE `keywords` ( `id` int(225) NOT NULL auto_increment, `keywords` text NOT NULL, `url` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; It has Keywords table in which you will be able to save URL + Keywords Now Create Page add_url.php and add <?php $dbhost = 'localhost'; $dbname = 'dbname'; $dbuser = 'root'; $dbpass = ''; $connect = mysql_connect($dbhost,$dbuser,$dbpass); if (!mysql_select_db($dbname)) die(mysql_error()); if(isset($_POST['button']){ $keywords = $_POST['keyoword']; $url = $_POST['url']; mysql_query('INSERT INTO keywords(keywords,url)VALUES("'.$keywords.'","'.$url.'")'); echo 'Url has been Added'; } ?> <form id="form1" name="form1" method="post" action=""> <label> Url: <input type="text" name="url" id="url" /> </label> <br /> Keywords : <label> <input type="text" name="keywords" id="keywords" /> </label> <br> <label> <input type="submit" name="button" id="button" value="Submit"> </label> <br /> <label></label> </form> Now Create another Page show_urls.php and add following code <?php $dbhost = 'localhost'; $dbname = 'dbname'; $dbuser = 'root'; $dbpass = ''; $connect = mysql_connect($dbhost,$dbuser,$dbpass); if (!mysql_select_db($dbname)) die(mysql_error()); $query = mysql_query('SELECT * FROM keywords'); while($row = mysql_fetch_array($query)){ echo '<a href='.$row['url'].'>'.$row['url'].'</a>'; } ?> This will show all that links you have added now we gonna add a form through which only relavant urls shown, Npw modify the code as given below <?php $dbhost = 'localhost'; $dbname = 'dbname'; $dbuser = 'root'; $dbpass = ''; $connect = mysql_connect($dbhost,$dbuser,$dbpass); if (!mysql_select_db($dbname)) die(mysql_error()); if(isset($_POST['button']){ $keyword = $_POST['keyoword']; $query = mysql_query('SELECT * FROM keywords WHERE keywords like "$keyword"'); while($row = mysql_fetch_array($query)){ echo '<a href='.$row['url'].'>'.$row['url'].'</a>'; } } ?> <form name="form1" method="post" action=""> <label>Enter Keyword:<br> <input type="text" name="keyword" id="keyword"> <br> <input type="submit" name="button" id="button" value="Submit"> <br> </label> </form> now thats it, hope this helps you alot, reply if you found any problem , i havent tested it yet Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.