UGN Security Forums
My ProfileMember DirectoryLogin
Search our ForumsView our FAQView our Site Rules
View our CalendarView our Active TopicsGo to our Main Page

UGN Security Store
 

Network Sites UGN Security, The GoNix Initiative, Elite Web Gamers, Back of the Web, EveryDay Helper, VNC Web Design & Development
July
Su M Tu W Th F Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Sponsored Links
Latest Postings
Latest Reviews
Topic Options
Rate This Topic
#18406 - 02/26/03 05:25 PM Good source code to start in PHP/MySQL
§intå× Offline


*****

Registered: 12/03/02
Posts: 3255
Loc: Maryland
So you want to start using PHP/MySQL hu? I myself learn best looking through some basic code. I read tuts and texts and still barely knew what PHP was. Then Scallion/http://www.scallion.spoofed.net offered me a search engine he wrote for rrfn. I went through the code with a fine toothed comb.

I finally got it. It all came together and made perfect sense. Below I am posting the code scallion gave to rrfn. I have made many changes and add ons since this version. But this will help any PHP/MySQL newb out. It covers all the basics.

Take a look at the code and post any questions you have. Good luck. I would like to offer this as a download(the newest version) and maybe get a bit of open source with it. I am most intrested to see what you guys do different from what I did.


Code:
 <?php
$password = "YOUR PASSWORD HERE";
$username = "YOUR USER NAME HERE";
$db = "YOUR DATABASE NAME HERE";
mysql_connect("localhost", $username, $password);
mysql_select_db($db);
if($cmd == "create") {
   $dg = mysql_query("CREATE TABLE ###IN THIS SPOT NAME OF YOUR TABLE FOR YOUR LINKS### (linkname VARCHAR(255), linkurl VARCHAR(255), kw1 VARCHAR(255), kw2 VARCHAR(255), kw3 VARCHAR(255), kw4 VARCHAR(255), kw5 VARCHAR(255), category INT,id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (ID))");  
     if($dg) echo "mySQL CREATE TABLE Worked Properly.
";
     else echo "mySQL Error: ".mysql_error();
     $dg = mysql_query("CREATE table ###NAME OF YOUR TABLE FOR CATEGORIES### (name VARCHAR(255), id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (ID))");
     if($dg) echo "mySQL CREATE TABLE Worked Properly.
";
     else echo "mySQL Error: ".mysql_error();
}
else if(!$cmd) {
   ?>
Search 

<form action="###NAME OF PHP FILE THIS SCRIPT IS IN###?cmd=search" method=POST>
Keyword: <font size=1>(Only one please)</font> 
<input type="text" name="keyword"> 
<input type="submit" value="Search">
</form>
<hr>
Browse 

<?
   $dg = mysql_query("SELECT * FROM NAME OF YOUR CATEGORY TABLE");
        while($dg2 = mysql_fetch_array($dg)) {
               echo "<a href=\"rrfn_links.php?cmd=browse&id=".$dg2['id']."\">".$dg2['name']."</a>
";
            }
}
else if($cmd == "admin") {
   ?>
Add Category 

<form action="rrfn_links.php?cmd=addcat" method=POST>
Category Name: <input type="text" name="catname"> 

Password: <input type="password" name="cpas"> 

<input type="submit" value="Add Category">
</form>
<hr>
Add Link 

<form action="rrfn_links.php?cmd=addlink" method=POST>
Password: <input type="password" name="cpas"> 

Link Name: <input type="text" name="lname"> 

Link URL: <input type="text" name="lurl"> 

Keywords <font size=1>(Up to 5 keywords, no spaces, separated by commas)</font>: <input type="text" name="kws"> 

Category: <select name="category">
<?
$cats = mysql_query("SELECT * FROM rrfn_cats");
while($cats2 = mysql_fetch_array($cats)) {
echo "<option value=\"".$cats2['id']."\">".$cats2['name'];
}
?>
</option>


<input type="submit" value="Add Link">
</form>
     <?
}
else if($cmd == "addcat") {
     if($cpas == "YOUR PASSWORD HERE") {
      $dg = mysql_query("INSERT INTO rrfn_cats (name) VALUES ('$catname')");
        if($dg) echo "mySQL INSERT Worked Properly.";
            else echo "mySQL Error: ".mysql_error();
             echo "<a href=\"./rrfn_links.php?cmd=admin\">
 back to the admin page</a>";
     }
     else { echo "Password didn't work out. Sorry."; }
}
else if($cmd == "addlink") {
     if($cpas == "YOUR PASSWORD HERE") {
      $keywords = split(",", $kws, 5);
        $dg = mysql_query("INSERT INTO rrfn_links (linkname, linkurl, kw1, kw2, kw3, kw4, kw5, category) VALUES ('$lname', '$lurl', '$keywords[1]', '$keywords[2]', '$keywords[3]', '$keywords[4]', '$keywords[0]', '$category')"); 
             if($dg) echo "mySQL INSERT Worked Properly.";
             else echo "mySQL Error: ".mysql_error();
             echo "<a href=\"./rrfn_links.php?cmd=admin\">
 back to the admin page</a>";
     }
     else { echo "Password didn't work out. Sorry."; }
}
else if($cmd == "browse") {
   echo "Results: 
";
   $dg = mysql_query("SELECT * FROM rrfn_links WHERE category='$id'");
     while($dg2 = mysql_fetch_array($dg)) {
        echo "<a href=\"".$dg2['linkurl']."\">".$dg2['linkname']."</a>
\n";
     }
}
else if($cmd == "search") {
   echo "Results: 
";
     $quer = "SELECT * FROM rrfn_links WHERE (kw1 LIKE '%$keyword%') OR (kw2 LIKE '%$keyword%') OR (kw3 LIKE '%$keyword%') OR (kw4 LIKE '%$keyword%') OR (kw5 LIKE '%$keyword%')";
     echo $quer."
";
     $dg = mysql_query($quer);
     if(mysql_num_rows($dg) == 0) { echo "No results found.  Sorry, try again. 
"; }
     else {
         while($dg2 = mysql_fetch_array($dg)) {
             echo "<a href=\"".$dg2['linkurl']."\">".$dg2['linkname']."</a>
\n";
             }
     } 
}
else if($cmd == "all") {
echo "<table border=1>";
?>
<tr>
<td>name
<td>url
<td>kw1
<td>kw2
<td>kw3
<td>kw4
<td>kw5
<td>category
<td>id#
<?
$result = mysql_query("SELECT * FROM rrfn_links");
while($myrow = mysql_fetch_row($result))
 {
 print " <tr> ";
  for($x=0; $x <= count($myrow); $x++)
  {
   print "<td>".$myrow[$x]."</td>";
  }
 print "</tr>";
}
echo "</table>";
}
?>  
_________________________
My New site OpenEyes

Top
Sponsored Links
      
#18407 - 02/27/03 01:28 AM Re: Good source code to start in PHP/MySQL
Gremelin Offline

Community Owner
*****

Registered: 02/28/02
Posts: 7192
Loc: Portland, OR; USA
You should have bolded everything that they need to change :x...
_________________________
Donate to UGN Security here.
UGN Security, Back of the Web, Elite Web Gamers & VNC Web Design Owner

Top
#18408 - 02/27/03 05:55 AM Re: Good source code to start in PHP/MySQL
§intå× Offline


*****

Registered: 12/03/02
Posts: 3255
Loc: Maryland
[b] and [/b] do not work in side the code tags...

*shrugs*
_________________________
My New site OpenEyes

Top
#18409 - 02/27/03 06:10 AM Re: Good source code to start in PHP/MySQL
Gremelin Offline

Community Owner
*****

Registered: 02/28/02
Posts: 7192
Loc: Portland, OR; USA
Ahh ok heh...
_________________________
Donate to UGN Security here.
UGN Security, Back of the Web, Elite Web Gamers & VNC Web Design Owner

Top
#18410 - 03/03/03 11:59 AM Re: Good source code to start in PHP/MySQL
§intå× Offline


*****

Registered: 12/03/02
Posts: 3255
Loc: Maryland
No one is going to take up this challenge?
_________________________
My New site OpenEyes

Top

Moderator:  §intå×, Gremelin 
Featured Member
Registered: 03/05/02
Posts: 9
Forum Stats
2145 Members
46 Forums
33352 Topics
68519 Posts

Max Online: 1567 @ 04/25/10 10:20 AM
Top Posters
UGN Security 26515
Gremelin 7192
§intå× 3255
SilentRage 1273
Ice 1146
pergesu 1136
Infinite 1041
jonconley 955
Girlie 908
unreal 860
Newest Members
Jimmie Menon, fghijk435948, Devo60, ali, lavos
2147 Registered Users
Who's Online
0 registered (), 688 Guests and 309 Spiders online.
Key: Admin, Global Mod, Mod
Latest News


Donate
  Get Firefox!
Get FireFox!