April 20, 200818 yr Hi im in the process of creating a site and was woundering if thier are any basic mysql/php free scripts out thier that allow me to add urls to a database with a brief description and picture, i want this to be a ery basic structure so that i can learn from it to go onto more complex solutions.
April 21, 200818 yr Hi! I think that: http://www.w3schools.com/php/php_mysql_insert.asp should help you out.
April 21, 200818 yr Don't forget that when inserting certain characters into mysql they need to be escaped,you will find examples here Particularly important when dealing with urls as they often contain characters that need to escaped.
April 22, 200818 yr Hi im in the process of creating a site and was woundering if thier are any basic mysql/php free scripts out thier that allow me to add urls to a database with a brief description and picture, i want this to be a ery basic structure so that i can learn from it to go onto more complex solutions. Here are few tutorials, you can have a look at these links too.. http://www.php-mysql-tutorial.com/mysql-insert-php.php http://teamtutorials.com/web-development-t...abase-using-php Few links where you can get your required scripts.. http://www.scriptsbank.com/PHP_Scripts/Ima...ries/more3.html http://www.yourfreescripts.com/detail/3416...-and-mysql.html http://www.hotscripts.com/PHP/Scripts_and_...ries/index.html
April 22, 200818 yr Author Thanks guys for your help i have managed to set up almost what i want. Now i would like advise on a simalar subject, as part of the mysql script i would like to hide the actual link as alot of them will be affiliate links, would it be best to just link this to my .htaccess or is thier away round it i havnt thought of?
April 22, 200818 yr proberbly the easiest way is to use md5() you would then display your links somthing like so: $rs = mysql_query("SELECT url, title FROM links"); while ($row = mysql_fetch_array($rs)) { echo '<a href="link.php?goto='.md5($row['url']).'">'.$row['title'].'</a><br />'; } Basically just show an md5 checksum of the url rather than the url itself. The code for link.php would be somthing like this: $rs = mysql_query("SELECT url FROM links WHERE MD5(url) = '".$_GET['goto']."'"); $url = mysql_result($rs, 0); header("Location: $url"); exit(); This would take the $_GET['goto'] checksum and search for it in the database, returning the url and sending the browers to it. I think you can use the mysql MD5() function like ive shown, else you would have to loop through the results and compare them instead. Ofcourse you should add some validation in there as anything passed in $_GET['goto'] that does exist would cause and error on this script. But im just showing the basic principle. I hope ive understood you correctly and this helps you achieve what you need.
April 25, 200818 yr Author proberbly the easiest way is to use md5() you would then display your links somthing like so: $rs = mysql_query("SELECT url, title FROM links"); while ($row = mysql_fetch_array($rs)) { echo '<a href="link.php?goto='.md5($row['url']).'">'.$row['title'].'</a><br />'; } Basically just show an md5 checksum of the url rather than the url itself. The code for link.php would be somthing like this: $rs = mysql_query("SELECT url FROM links WHERE MD5(url) = '".$_GET['goto']."'"); $url = mysql_result($rs, 0); header("Location: $url"); exit(); This would take the $_GET['goto'] checksum and search for it in the database, returning the url and sending the browers to it. I think you can use the mysql MD5() function like ive shown, else you would have to loop through the results and compare them instead. Ofcourse you should add some validation in there as anything passed in $_GET['goto'] that does exist would cause and error on this script. But im just showing the basic principle. I hope ive understood you correctly and this helps you achieve what you need. Hi thanks for this but if i just use the "$_GET" straight to mysql wouldnt that leave me open to hackers and security flaws?
April 26, 200818 yr Yes it would leave you open to mysql injections but i provided it as a quick example to show you and i wrote it really quickly. You should definatly improve on the code by adding mysql_escape_string() or your own choice of function.
April 26, 200818 yr Author Thanks for the input i will use your examplebut i will have to expand on the security.
April 26, 200818 yr I tried to keep it very basic to make it easy to understand, i was unaware of your PHP knowledge. There are validation issues you should cover too. For example you should cover for URL's that dont exist in the database, the easiest way is to use mysql_num_rows $rs = mysql_query("SELECT url FROM links WHERE MD5(url) = '".$_GET['goto']."'"); if(mysql_num_rows($rs) < 1) { // The requested link is not in the database // Do some error or whatever } else { $url = mysql_result($rs, 0); header("Location: $url"); exit(); }
April 26, 200818 yr Author Thanks,i do only have a basicknowlege of this but im a quick learner and appreciate the help. That is agreat help as i would not have thought about that one, so many pit holes!!!
Create an account or sign in to comment