Snippet Add/View

By F*U*R*B*Y* on Dec 25, 2006

ok, its alot like Hawkee.com's snippet but its 100% purely mine.

i'm 100% sure it works BUT i made this without mysql so i dunno if it will work. stupid mysql is stuffing up

there is an upload.php and view.php

When you upload this to your webserver just change the database information. add a database as follow. sorry i don't know how to do the fancy SQL code. if someone does it and post it as a pm/comment i'll gladly add that to this snippet.

snippets (database name)
snippet_type (mIRC/php/tcl)
snippet_id (int auto_increcment)
snippet_date (date)
snippet_user (username that uploaded the script)
snippet_title (the title of the snippet)
snippet_code (the actual snippet)
snippet_description (a description of the snippet)

once you upload visit http://yourwebsite.com/upload.php?type=mIRC (for uploading a mIRC snippet) and once you've filled in all fields then visit http://yourwebsite.com/view.php?snippet=1 <--- will show you the very first snippet posted.

I've left out ALL the copyright stuff. because i've been visiting websites that use this and have edited the copyright stuff so it seem's they've made this. i know i did this once with mIRC Scripting, but i deleted them and started learning mIRC Scripting so if people leave feedback on how they use it. i'll be happy.

this can also be used as a shoutbox sort of way, with a bit of tweeking and that.

################
Start upload.php
################

<?

$snippets = $_GET[type];

$dbhost='localhost';
$dbusername='root';
$dbuserpass='root';
$dbname='root';

// connect to the mysql database server.
mysql_connect ($dbhost, $dbusername, $dbuserpass);
mysql_select_db($dbname) or die("Cannot select database");

//Are they just getting here or submitting their info?
if (isset($_POST["name"])) {
$snippet = $_POST["name"];
$description = $_POST["description"];
$code = $_POST["script"];
$date = date("Y-m-d");
$username = $_COOKIE['name'];
//Was a field left blank?
if($snippet==NULL|$description==NULL|$code==NULL) {
echo "A field was left blank.";
}else{
//Everything seems good, lets insert.
$query = "INSERT INTO snippets VALUES('$snippets','','$date','$_COOKIE[user]','$snippet','$description','$code')";
mysql_query($query) or die(mysql_error());
echo "The Code $snippet has been successfully added.";
}
}
?>
<html>
<body>
        <?
        $snippets = $_GET[type];

if (isset($_COOKIE['user'])) {
?>
<form method="post" action="upload.php?type=<? echo $snippets; ?>" name="add" align="center">Snippet Title: <input name="name"><br><br>
Snippet Description:<br>
&nbsp;<textarea cols="30" rows="10"
 name="description"></textarea><br>
Snippet Code: (test it firstly)<br>
  <textarea cols="30" rows="10" name="script"></textarea>
  <input value="Submit this Code" type="submit"></form>
<?
}else{
        echo "Please login to post a Script.";
        }
        ?>
</body>
</html>

#################
End of upload.php
#################

#################
Start of View.php
#################

<?
require('config.php');

$snippets = $_GET[snippet];

$row1 = mysql_query("SELECT * FROM snippets WHERE `snippet_id` = '$snippets'") or die(mysql_error());
while ($row=mysql_fetch_array($row1))
{
echo "<H1>$row[snippet_title]</H1><br>";
echo "<b>Snippet Author:</b> $row[snippet_user]</b><br>";
echo "<b>Snippet Description:</b> $row[snippet_description]</b><br>";
echo "<blockquote>";
echo "<textarea rows=\"25\" cols=\"57\" class=\"snippetarea\">$row[snippet_code]</textarea>";
echo "</blockquote>";
}
?>
###############
End of View.php
###############

#################
Start of List.php
#################

<?
        $snippets = $_GET[type];
        echo "<table border=\"0\" width=\"100%\">";
if (isset($_COOKIE['user'])) {
        echo "<tr><td width=\"35%\">Snippet</td><td width=\"45%\">Author</td><td width=\"15%\" style=\"font-size: 15px;\"><a href=\"post.php?type=$snippets\">add a code</a></tr>";
}else{
        echo "<tr><td width=\"35%\">Snippet</td><td width=\"69%\">Author</td></tr>";
        }
        require('config.php');

$rowsPerPage = 3;
$pageNum = 1;
if(isset($_GET['p']))
{
    $pageNum = $_GET['p'];
}
$offset = ($pageNum - 1) * $rowsPerPage;
$result = mysql_query("SELECT * FROM snppets WHERE `snippet_type` = '$snippet' LIMIT $offset, $rowsPerPage") or die(mysql_error());

while($row1 = mysql_fetch_array($result))
{
}

echo '<br />';
#result  = mysql_query("SELECT COUNT($snippet_id) AS numrows FROM snppets WHERE `snippet_type` = '$snippet'") or die(mysql_error());
$result = mysql_query("SELECT COUNT(snippet_id) AS numrows FROM snppets WHERE `snippet_type` = '$snippet'") or die(mysql_error());
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPage = ceil($numrows/$rowsPerPage);
if ($pageNum > 1)
{
    $page = $pageNum - 1;
    $prev = " <a href=\"&p=$page\">&laquo;Previous</a> "; 
    $first = " <a href=\"&p=1\">First</a> ";
}
else
{
    $prev  = ' &laquo;Previous ';
    $first = ' First ';
}
if ($pageNum < $maxPage)
{
    $page = $pageNum + 1;
    $next = " <a href=\"&p=$page\">Next&raquo;</a> ";

    $last = " <a href=\"&p=$maxPage\">Last</a> ";
}
else
{
    $next = ' Next&raquo; ';
    $last = ' Last ';
}
echo $first . $prev . " Side <strong>$pageNum</strong> of <strong>$maxPage</strong> " . $next . $last;
        $row1 = mysql_query("SELECT * FROM snppets WHERE `snippet_type` = '$snippets'") or die(mysql_error());
while($row=mysql_fetch_array($row1))

{

echo "<b><tr><td><a href=\"view.php?snippet=$row[snippet_id]\">$row[snippet_title]</a></td><td><a href=\"profile.php?user=$row[snippet_poster]\">$row[snippet_poster]</a></td></b>";
}

        echo "</table>";
?> 

###############
End of List.php
###############

###################
Start of Search.php
###################

<?
require('config.php');

if (isset($_POST["search"])) {
$search = $_POST["search"];
if($search==NULL) {
echo "Please type something in the Field to Search.";
}else{
//Everything seems good, lets insert.
echo "<table border=\"1\">";
echo "<tr><td>Snippet Title</td><td>Author</td></tr>";
$row1 = mysql_query("SELECT * FROM snippets WHERE `snippet_title` = '$search'") or die(mysql_error());
while ($row=mysql_fetch_array($row1))
{
echo "<b><tr><td><a href=\"view.php?snippet=$row[snippet_id]\">$row[snippet_title]</a></td><td><a href=\"profile.php?user=$row[snippet_poster]\">$row[snippet_poster]</a></td></b>";
}
}
?>

<h2>Search</h2>
<form method="post" action="search.php" name="search">
 <input name="search"><br>
  <input type="submit" value="Search!" class="button" />
</form>

#################
End of Search.php
#################

#################
Start of SQL Code
#################
CREATE TABLE IF NOT EXISTS `snippets` (
  `snippet_type` text NOT NULL,
  `snippet_id` int(11) NOT NULL auto_increment,
  `snippet_user` text NOT NULL,
  `snippet_title` text NOT NULL,
  `snippet_description` longtext NOT NULL,
  `snippet_code` longtext NOT NULL,
  PRIMARY KEY  (`snippet_id`),
  KEY `snippet_id` (`snippet_id`),
) TYPE=MyISAM AUTO_INCREMENT=1 ;
###############
End of SQL Code
###############

Comments

Sign in to comment.
Hawkee   -  Apr 18, 2009

Yeah, looks like this is missing config.php. Seems like the database variables are here already, so I can't imagine what variables are contained in config.php

 Respond  
PuNkTuReD   -  Apr 18, 2009

what do i use for config.php?

 Respond  
Kedon   -  Feb 12, 2009

not bad for beginning :)

 Respond  
AdrianF   -  Feb 12, 2009

u need to add a login system

 Respond  
F*U*R*B*Y*   -  Aug 15, 2008

YEAH BABY +3 Likes :D

 Respond  
F*U*R*B*Y*   -  Nov 20, 2007

ah ok, uhhh don\'t suppose you\'ve debugged it and know which line it is?

 Respond  
wizkidweb16   -  Nov 20, 2007

Oh my goodness I hate those stupid Furby toys.

No offense, F.U.R.B.Y.

 Respond  
wizkidweb16   -  Nov 20, 2007

I found some problems that it was not reading the database because snippets is sometimes spelled snppets in the script.

Also, I fixed that, and connected to the database and table, but I have been getting this error even before fixing the typo:

\"Column count doesn\'t match value count at row 1\"

Does anyone know how I can fix this problem?

 Respond  
F*U*R*B*Y*   -  Aug 11, 2007

you would have alot of bloody text files for hawkee.com :P

 Respond  
Snipe   -  Aug 10, 2007

Very nice, just I hate mysql, i wish it was just purly php, and it saved data in like a text file or something...now that would be sweet.

 Respond  
F*U*R*B*Y*   -  Apr 22, 2007

:o i think this is the highest score i\'ve reached since being on Hawkee :P

 Respond  
Gex   -  Apr 22, 2007

Nice code..simple and readable,score submitted => 7.0

GJ

 Respond  
F*U*R*B*Y*   -  Apr 22, 2007

:( still no points :(

 Respond  
Hawkee   -  Jan 03, 2007

Furby, why don\'t you look at what I did here to include the \"create table\" query in your code:

http://www.hawkee.com/snippet.php?snippet_id=1262

You just need to dump the table layout with mysqldump and paste it into a variable.

 Respond  
F*U*R*B*Y*   -  Jan 02, 2007

Updated once more. included the SQL Table. thanks null for giving the code to me ;)

 Respond  
F*U*R*B*Y*   -  Jan 02, 2007

ok Edited again, now has a search feature :D

 Respond  
F*U*R*B*Y*   -  Dec 30, 2006

ok Editted so now you visit list.php?type=mIRC and it list all mIRC scripts. :P

 Respond  
F*U*R*B*Y*   -  Dec 27, 2006

2 weeks and 3 days :P

 Respond  
ZabuzaMomochi   -  Dec 26, 2006

Very nice, seems a lot of time was put in to this.

 Respond  
F*U*R*B*Y*   -  Dec 25, 2006

forgot to add, you have to have a login system, or a place where you can set a cookie called user

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.