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>
<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\">«Previous</a> ";
$first = " <a href=\"&p=1\">First</a> ";
}
else
{
$prev = ' «Previous ';
$first = ' First ';
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"&p=$page\">Next»</a> ";
$last = " <a href=\"&p=$maxPage\">Last</a> ";
}
else
{
$next = ' Next» ';
$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
###############
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?
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.