webweever Posted November 28, 2007 Share Posted November 28, 2007 I'm looking for a simple bookmarking system. Just something that wil accept a name and a url, nothing fancy. I've searched all over and can't find anything simple. Or, anyone have a clue how I would code one? I no very little php. All I need is something that will take a name and url from a form and post it to a page in a list. Maybe a delete function just in case I wanted to delete one but that's about it. Anyone have any input? Quote Link to comment https://forums.phpfreaks.com/topic/79333-solved-php-bookmarking-system/ Share on other sites More sharing options...
pocobueno1388 Posted November 28, 2007 Share Posted November 28, 2007 Have you even attempted to code it? This forum is not for people to code things for you, it is for specific help with problems that occur with peoples already existing code. I suggest to go through some online tutorials, or if you not interested in learning PHP/MySQL, then hire a freelancer. www.tizag.com or www.w3schools.com are good places to start. Quote Link to comment https://forums.phpfreaks.com/topic/79333-solved-php-bookmarking-system/#findComment-401588 Share on other sites More sharing options...
MadTechie Posted November 28, 2007 Share Posted November 28, 2007 maybe a this http://www.freewebmasterhelp.com/tutorials/phpmysql after a quick review it seams perfect for what you want (maybe) sorry to "pass the buck" but were here to help.. if you want us to write the code for you.. your need to post in freelance section and offer something.. Quote Link to comment https://forums.phpfreaks.com/topic/79333-solved-php-bookmarking-system/#findComment-401597 Share on other sites More sharing options...
Wolphie Posted November 28, 2007 Share Posted November 28, 2007 Doing it via a database would be easier. I'd do it like this - The form to write to the database(bookmarks.php): <?php include('config.php'); switch($_GET['do']) { default: echo ' <form method="?do=write" method="post"> Your name: <input type="text" name="name" /><br /> URL: <input type="text" name="url" /><br /> <input type="submit" value="Submit" /> </form> '; break; case 'write': $name = mysql_escape_string(htmlspecialchars($_POST['name'])); // Get the value of "name" from the form. $url = mysql_escape_string(htmlspecialchars($_POST['url'])); // Get the value of "url" from the form. function submitForm($name, $url) { // Insert the data into the database. $sql = mysql_query(sprintf("INSERT INTO `bookmarks` ( `name`, `url` ) VALUES ( '%s', '%s' )", $name, $url)) or die('Error: ' . mysql_error()); if($sql) { echo 'Your bookmark has been submitted successfully. View a list <a href="view.php">Here</a>'; } else { echo 'There appears to be an error. Please <a href="bookmarks.php">go back</a> and try again.'; } } function checkValues($name, $url) // Check form for valid inputs { $input = false; foreach($_POST as $field) { if($field == '') { $input = false; } else { $input = true; } } if($input) { submitForm($name, $url); } else { echo 'There appears to be an error. Please <a href="bookmarks.php">go back</a> and try again.'; } } checkValues($name, $url); break; } ?> The view.php page: <?php include('config.php'); $sql = mysql_query(sprintf("SELECT * FROM `bookmarks`")) or die('Error: ' . mysql_error()); while($row = mysql_fetch_array($sql)) { echo ' <table cellpadding="0" cellspacing="0"> <tr> <td style="padding-top: 10px;">Name:</td> <td>' . $row['name'] . '</td> </tr> <tr> <td>URL:</td> <td>' . $row['url'] . '</td> </tr> </table> '; } ?> config.php: <?php $host = 'localhost'; $user = 'root'; $pass = ''; $db = 'website'; $con = mysql_connect($host, $user, $pass); if($con) { mysql_select_db($db); } else { die('Could not connect to database'); } ?> I'm not sure if thats what you're looking for or even if this works since i just literally wrote it without testing it. Quote Link to comment https://forums.phpfreaks.com/topic/79333-solved-php-bookmarking-system/#findComment-401600 Share on other sites More sharing options...
webweever Posted November 29, 2007 Author Share Posted November 29, 2007 Some how I managed to hack this out. Took a combo of the tutorials mentioned above and a couple others. Take a look: http://www.racinnation.com/sandbox/bookmark/form.php It's very crude but it's something to build on. How can I make the url output in my http://www.racinnation.com/sandbox/bookmark/bookmarks.php file linkable and to open in a new window? BTW: Thanks for the quick responses. Quote Link to comment https://forums.phpfreaks.com/topic/79333-solved-php-bookmarking-system/#findComment-401636 Share on other sites More sharing options...
pocobueno1388 Posted November 29, 2007 Share Posted November 29, 2007 You would just make it a link <?php echo "<a href='{$row['url']}' target='_blank'>{$row['link_name']}</a>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/79333-solved-php-bookmarking-system/#findComment-401645 Share on other sites More sharing options...
kratsg Posted November 29, 2007 Share Posted November 29, 2007 Don't just do this... You need to mysql_real_escape_string() all the user inputs (the name and the url) and you also need to check to see if it actually is a valid url, etc... Quote Link to comment https://forums.phpfreaks.com/topic/79333-solved-php-bookmarking-system/#findComment-401653 Share on other sites More sharing options...
webweever Posted November 29, 2007 Author Share Posted November 29, 2007 I've been playing around and somehow get an error. Parse error: parse error, unexpected '}' in /homepages/27/d192713422/htdocs/sandbox/bookmark/insert.php on line 11 in my insert file, code: <?php $host="db1250.perfora.net"; // Host name $username="dbo226106710"; // Mysql username $password="8pf375hX"; // Mysql password $db_name="db226106710"; // Database name $tbl_name="bookmarks"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get values from form $name=$_POST['name']; $url=$_POST['url']; // Insert data into mysql $sql="INSERT INTO $tbl_name(name, url)VALUES('$name', '$url')"; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; echo "<BR>"; echo "<a href='form.php'>Back to main page</a>"; } else { echo "ERROR"; } // close connection mysql_close(); ?> any ideas what could be wrong? Quote Link to comment https://forums.phpfreaks.com/topic/79333-solved-php-bookmarking-system/#findComment-402198 Share on other sites More sharing options...
pocobueno1388 Posted November 29, 2007 Share Posted November 29, 2007 Whats up with this chunk of code? } else { echo "ERROR"; } You don't even have an IF statement to do an else off of...thats why your getting an error. Quote Link to comment https://forums.phpfreaks.com/topic/79333-solved-php-bookmarking-system/#findComment-402201 Share on other sites More sharing options...
helraizer Posted November 29, 2007 Share Posted November 29, 2007 echo "<a href='form.php'>Back to main page</a>"; } else { you have a random } on line 13, as poco... said you need an IF statement to have an else statement Quote Link to comment https://forums.phpfreaks.com/topic/79333-solved-php-bookmarking-system/#findComment-402205 Share on other sites More sharing options...
webweever Posted November 29, 2007 Author Share Posted November 29, 2007 If I remove the: } else { echo "ERROR"; } It spits out I can't connect to the DB. What sort of if statement do I need? Quote Link to comment https://forums.phpfreaks.com/topic/79333-solved-php-bookmarking-system/#findComment-402218 Share on other sites More sharing options...
Adam Posted November 29, 2007 Share Posted November 29, 2007 if ($result) { echo "Successful"; echo "<BR>"; echo "<a href='form.php'>Back to main page</a>"; } else { echo "ERROR"; } Quote Link to comment https://forums.phpfreaks.com/topic/79333-solved-php-bookmarking-system/#findComment-402223 Share on other sites More sharing options...
webweever Posted November 29, 2007 Author Share Posted November 29, 2007 Using: // Get values from form $name=$_POST['name']; $url=$_POST['url']; // Insert data into mysql $sql="INSERT INTO $tbl_name(name, url)VALUES('$name', '$url')"; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ if ($result) { echo "Successful"; echo "<BR>"; echo "<a href='form.php'>Back to main page</a>"; } else { echo "ERROR"; } // close connection mysql_close(); ?> I get "cannot connect"??? Quote Link to comment https://forums.phpfreaks.com/topic/79333-solved-php-bookmarking-system/#findComment-402257 Share on other sites More sharing options...
helraizer Posted November 29, 2007 Share Posted November 29, 2007 Using: // Get values from form $name=$_POST['name']; $url=$_POST['url']; // Insert data into mysql $sql="INSERT INTO $tbl_name(name, url)VALUES('$name', '$url')"; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ if ($result) { echo "Successful"; echo "<BR>"; echo "<a href='form.php'>Back to main page</a>"; } else { echo "ERROR"; } // close connection mysql_close(); ?> I get "cannot connect"??? In this code (above) you don't have a mysql_connect nor mysql_select_db functions... Could be why, perhaps? Quote Link to comment https://forums.phpfreaks.com/topic/79333-solved-php-bookmarking-system/#findComment-402293 Share on other sites More sharing options...
webweever Posted November 29, 2007 Author Share Posted November 29, 2007 Got it, used: if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("db226106710", $con);$sql="INSERT INTO bookmarks (name, url) VALUES ('$_POST[name]','$_POST[url]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added";mysql_close($con) ?> Quote Link to comment https://forums.phpfreaks.com/topic/79333-solved-php-bookmarking-system/#findComment-402305 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.