Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Ravens PHP Scripts And Web Hosting Forum Index -> phpnuke 6.5
Author Message
gator
Hangin' Around



Joined: Jul 24, 2003
Posts: 36
Location: Canada

PostPosted: Mon Mar 08, 2004 1:50 pm Reply with quote

Hello,

I'm a noob, well maybe one step above (I have been learning php and mysql in my spare time from a book). I finally managed to create a script that serves as an admin interface to allow me to search and add new entries to my dbase (it is a dbase of beer reviews). I tried understanding the information held here: http://www.karakas-online.de/EN-Book/module-admin.html, but have had much difficulty.

Is there an easier way to convert this script into an admin module (it does not have to be an official admin module, but I only want site admins to access it? BTW there will only be one language used (english). I know I have to change the nuke db connection information and admin permisions. Do I need to re-write the sql statements given that this module will always be run from a mysql server? I thought the conversion into a nuke module would be easier than it's creation Rolling Eyes
Any help appreciated if more information is need I'll provide it.

http://www.boozebros.ca/beer/beer_review_add_live.php

The code is below:
Code:
<style type="text/css">

<!--
.style2 {font-size: xx-small}
-->
</style>
<h2 align="center">Welcome to the Beer Administration Page</h2>

<fieldset><legend><b>Last 5 beers added</b></legend>
<?php
// Connect to the db
require_once ('mysql_connect.php');

//Beer Admin Last 10 beers added:
$query = "select ubi, bn, url, fi, speed, cool, tq, os, poster, pkey from bb_br order by pkey desc limit 5";
$resultlatest = @mysql_query($query);

//Create Last 10 table
{echo '<table align="center" cellspacing="0" cellpadding="2" table border="1">
<td align="left"><b><a>UBI</b></td>
<td align="left"><b>Beer Name</b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "First Impression: What are your initial thoughts on colour, aroma, head, taste, etc...">First Impression</a></b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "Speed: Can you drink this beer in vast quantities and with speed? Or is it more of a sipper? AKA: the “Poundability Factor.”">Speed</a></b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "Intangible: Other than the taste, are there things about the label, advertising, etc... that make you appreciate this brew?">Intangible</a></b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "Overall Taste Quality: Now that you’re well into the beer, what do you think about how it tastes?">Taste Quality</a></b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "Overall Score: Just math. Add’em up.">Overall Score</a></b></td>
<td align="left"><b>Poster</b></td>
<td align="left"><b>Beer Mod #</b></td></tr>';


//Fetch and print
while ($row = mysql_fetch_array($resultlatest, MYSQL_NUM))

{echo
"<tr><td align=\"left\">$row[0]</td>
<td align=\"left\"><a href='$row[2]'>$row[1]</a></td>
<td align=\"left\">$row[3]</td>
<td align=\"left\">$row[4]</td>
<td align=\"left\">$row[5]</td>
<td align=\"left\">$row[6]</td>
<td align=\"left\">$row[7]</td>
<td align=\"left\">$row[8]</td>
<td align=\"left\">$row[9]</td></tr>"; }

echo '<br></table></br>';

}
?>
</fieldset>


<p><fieldset><legend><b>Beer Search Script</b></legend></p>
<form name="form" action="search_live.php" method="get">
  <p>
    <input type="text" name="q" />
    <input name="Submit" type="submit" value="Beer Search" />
    <span class="style2">*script only supports single word searching
  </span></p>
</form>
</fieldset>



<p><fieldset><legend><b>Beer Submit Form</b></legend></p>

<?php
function validateInput($input,$textVal)
{
    if(strlen($input)==0)
        $message .= "<p>You forgot to enter the $textVal score!</p>";
    elseif(!is_numeric($input))
        $message .= "<p>The $textVal was not a valid number score!</p>";
    elseif($input<0 || $input>6)
        $message .= "The $textVal score was not between 0 and 6!</p>";
    return $message;
}

if($_POST['submit'])
{
$ubi = $_POST['ubi'];
$bn = $_POST['bn'];
$url = $_POST['url'];
$fi = $_POST['fi'];
$speed = $_POST['speed'];
$cool = $_POST['cool'];
$tq = $_POST['tq'];
$poster = $_POST['poster'];

if(!$ubi)
$message .= '<p>You forgot to enter the unique beer ID!</p>';
if(!$bn)
$message .= '<p>You forgot to enter the beer name!</p>';
if(!$url)
$message .= '<p>You forgot to enter the URL!</p>';

$message .= validateInput($fi,"first impression");
$message .=validateInput($speed,"speed");
$message .=validateInput($cool,"intangible");
$message .=validateInput($tq,"taste quality");

if(!$poster)
$message .= '<p>You forgot to enter the poster name!</p>';

$num = mysql_num_rows(mysql_query("SELECT ubi,poster from bb_br WHERE ubi='$ubi' AND poster='$poster' LIMIT 1"));
if($num>0)
$message .= '<p>Beer ID already exists in database.</p>';

if(!$message)
{
require_once ('mysql_connect_live.php');
$os = ($fi + $speed + $cool + $tq);
$query = "INSERT INTO bb_br(ubi, bn, url, fi, speed, cool, tq, os, poster) VALUES('$ubi', '$bn', '$url', '$fi', '$speed', '$cool', '$tq', '$os', '$poster')";
$result = mysql_query($query) or die('<p>You beer could not be registered due to a system error. We apologize for any inconvenience.</p><p>'.mysql_error().'</p>');
echo 'You Beer has been registered...to continue <a href = "http://www.boozebros.ca/beer/beer_review_add_livea.php"><b>Click Here</b></a>';
mysql_close();
exit();
}
else
echo "<font color='red'>$message</font>";
}
?>


<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  <p><strong>  Unique Beer ID:     
    <input name="ubi" type="text" value="<?=$ubi?>" size="4" maxlength="3"> 
  </strong><span class="style2">*use the search script above to determine the unique beer ID</span></p>
  <p><strong>Beer Name:     
    <input name="bn" type="text" value="<?=$bn?>" size="75">
  </strong></p>
  <p><strong>Forum URL:       
    <input name="url" type="text" value="<?=$url?>" size="50">
  </strong></p>
  <p><strong>
      First Impression: 
    <input name="fi" type="text" value="<?=$fi?>" size="4" maxlength="3"> 
    Speed:     
    <input name="speed" type="text" value="<?=$speed?>" size="4" maxlength="3">
    Intangible:
    <input name="cool" type="text" value="<?=$cool?>" size="4" maxlength="3">     
    Taste Quality:
  <input name="tq" type="text" value="<?=$tq?>" size="4" maxlength="3">
    </strong></p>
  <p><strong>Poster Name:     
    <input name="poster" type="text" value="<?=$poster?>" size="30" maxlength="30">
  </strong></p>
  <p><strong>     
    <input name="submit" type="submit" value="Submit new Beer">
    </strong>
  </p>
</form>

</fieldset>
 
View user's profile Send private message Visit poster's website
sixonetonoffun
Spouse Contemplates Divorce



Joined: Jan 02, 2003
Posts: 2496

PostPosted: Tue Mar 09, 2004 7:43 am Reply with quote

I have to ask this? Why not just use the native review application in nuke and clean it up to appear as you want it? I don't see where your adding much in the way of functionality with this script.
 
View user's profile Send private message
gator







PostPosted: Tue Mar 09, 2004 1:14 pm Reply with quote

Yes,

Except for that fact that I wrote it Smile This is my first attempt at php coding (in fact it is my first attempt at coding anything). The review module is great, but at the time I didn't have any php knowledge and thus wouldn't have been able to modify it. Regardless, this is my own and I still want to see it through to completion...if for anything other than to say I did it.
 
sixonetonoffun







PostPosted: Tue Mar 09, 2004 5:54 pm Reply with quote

Ok well if your going to do it might as well do it "the nuke way" you might as well take the extra steps and add the lang to it and use the nuke db connect

Anyway first thing I'd do is split it up into functions
Last 5 beers added
Beer Search Script
Beer Submit Form

You can then call each function with one line.
OpenTable();
last5();
CloseTable();

function last5()
{
Details here
}

At the bottom of the page create the switch case. Then you can create a seperate search page ect from your default page and call it in the url with op=last5 or op=search op=myreview something like that. Or how ever you want to lay it out.
($op) {

case "last5":
last5();
break;
}
^^ This would only be to open a new page other then default if you want to lump it all into one page don't bother with this....

Look at some of the other admin modules, re read the info in the nuke book its all in there. The sql stuff isn't too hard to convert your queries are pretty basic so it shouldn't take much trial and error.

Generally for each module there will be a file in
/admin/
/case/ defines/limits switch($op)
/language/ defines language SurprisedP
/links/ defines the link in admin menu and graphic
/modules/ your php file with everything in it


Hope this kinda helps...
Check out faq that is a fairly easy module to use as a model.
Goodluck,
 
gator







PostPosted: Wed Mar 10, 2004 12:34 pm Reply with quote

HI thanks for the help Smile I've run into a small problem (I hope). When I go to the admin panel in nuke I get the following error.

Code:
Parse error: parse error in /home/boozebro/public_html/admin/links/links.beeradmin.php on line 23


Here is the code from that file: (excluding php tags)
Code:
if ($radminsuper==1) {   

    adminmenu("admin.php?op=last5 ", "" _BA." ", "beer.gif"); //line23
}


Incidently I added the relevant beer.gif file and added the definition for _BA. to the language file.

Here is the code from the case.beeradmin.php file: (excluding php tags)

Code:
if (!eregi("admin.php", $_SERVER['PHP_SELF'])) { die ("Access Denied"); }

switch($op) {
    case "last5":
    include ("admin/modules/beer_admin.php");
    break;
}


Finally here is the code from the beer_admin.php file: (I reduced the original code to include only a single function for testing purposes).

Code:


<html>
<body>
<h2 align="center">Welcome to the Beer Administration Page</h2>
<fieldset><legend><b>Last 5 beers added</b></legend>

<?php
//nuke specific stuff
if (!eregi("admin.php", $_SERVER['PHP_SELF'])) { die ("Access Denied"); }
$querystr = "SELECT radminsuper, admlanguage FROM "
.$prefix."_authors where aid='$aid'";
$result = sql_query($querystr, $dbi) or die ("invalied query");
list($radminsuper) = sql_fetch_row($result, $dbi);
if ($radminsuper==1) {
   switch($op) {
      case "":
         last5();
         break;
      case "last5";
         last5();
         break;
   }
}
else {
   echo "Access Denied";
}
 
//Function last 5 beers
function last5(){
global $admin, $bgcolor2, $prefix, $dbi, $multilingual;
include("header.php");
GraphicAdmin();
Opentable();

/*Original SQL query
$query = "select ubi, bn, url, fi, speed, cool, tq, os, poster, pkey from bb_br order by pkey desc limit 5";
$resultlatest = @mysql_query($query);*/

//Nuke Specific query (I think)
$querystr = "SELECT ubi, bn, url, fi, speed, cool, tq, os, poster, pkey from FROM ".$prefix. "_beer";
   $resultlatest = sql_query($querystr, $dbi)
   or die ("invalid query in last5");

//Create last 5 table
{echo '<table align="center" cellspacing="0" cellpadding="2" table border="1">
<td align="left"><b><a>UBI</b></td>
<td align="left"><b>Beer Name</b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "First Impression: What are your initial thoughts on colour, aroma, head, taste, etc...">First Impression</a></b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "Speed: Can you drink this beer in vast quantities and with speed? Or is it more of a sipper? AKA: the “Poundability Factor.”">Speed</a></b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "Intangible: Other than the taste, are there things about the label, advertising, etc... that make you appreciate this brew?">Intangible</a></b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "Overall Taste Quality: Now that you’re well into the beer, what do you think about how it tastes?">Taste Quality</a></b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "Overall Score: Just math. Add’em up.">Overall Score</a></b></td>
<td align="left"><b>Poster</b></td>
<td align="left"><b>Beer Mod #</b></td></tr>';


//Fetch and print
while ($row = mysql_fetch_array($resultlatest, MYSQL_NUM))

{echo
"<tr><td align=\"left\">$row[0]</td>
<td align=\"left\"><a href='$row[2]'>$row[1]</a></td>
<td align=\"left\">$row[3]</td>
<td align=\"left\">$row[4]</td>
<td align=\"left\">$row[5]</td>
<td align=\"left\">$row[6]</td>
<td align=\"left\">$row[7]</td>
<td align=\"left\">$row[8]</td>
<td align=\"left\">$row[9]</td></tr>"; }

echo '<br></table></br>';

}
   closetable();
   include("footer.php");
}
?>

</fieldset>
</body>
</html>


I think I'm missing something simple? Any help greatly appreciated Smile
 
sixonetonoffun







PostPosted: Wed Mar 10, 2004 2:26 pm Reply with quote

I couldn't test this but I think your case and links files are ok.

Try using something like this:
beer_admin.php
Code:


<?php

//nuke specific stuff
if (!eregi("admin.php", $_SERVER['PHP_SELF'])) { die ("Access Denied"); }
$querystr = "SELECT radminsuper, admlanguage FROM "
.$prefix."_authors where aid='$aid'";
$result = sql_query($querystr, $dbi) or die ("invalied query");
list($radminsuper) = sql_fetch_row($result, $dbi);
if ($radminsuper==1) {
 
//Function last 5 beers
function last5(){
global $admin, $bgcolor2, $prefix, $dbi, $multilingual;
include("header.php");
GraphicAdmin();
Opentable();

/*Original SQL query
$query = "select ubi, bn, url, fi, speed, cool, tq, os, poster, pkey from bb_br order by pkey desc limit 5";
$resultlatest = @mysql_query($query);*/

//Nuke Specific query (I think)
$querystr = "SELECT ubi, bn, url, fi, speed, cool, tq, os, poster, pkey from FROM ".$prefix. "_beer";
   $resultlatest = sql_query($querystr, $dbi)
   or die ("invalid query in last5");

//Create last 5 table
{echo '<table align="center" cellspacing="0" cellpadding="2" table border="1">
<td align="left"><b><a>UBI</b></td>
<td align="left"><b>Beer Name</b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "First Impression: What are your initial thoughts on colour, aroma, head, taste, etc...">First Impression</a></b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "Speed: Can you drink this beer in vast quantities and with speed? Or is it more of a sipper? AKA: the “Poundability Factor.”">Speed</a></b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "Intangible: Other than the taste, are there things about the label, advertising, etc... that make you appreciate this brew?">Intangible</a></b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "Overall Taste Quality: Now that you’re well into the beer, what do you think about how it tastes?">Taste Quality</a></b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "Overall Score: Just math. Add’em up.">Overall Score</a></b></td>
<td align="left"><b>Poster</b></td>
<td align="left"><b>Beer Mod #</b></td></tr>';


//Fetch and print
while ($row = mysql_fetch_array($resultlatest, MYSQL_NUM))

{echo
"<tr><td align=\"left\">$row[0]</td>
<td align=\"left\"><a href='$row[2]'>$row[1]</a></td>
<td align=\"left\">$row[3]</td>
<td align=\"left\">$row[4]</td>
<td align=\"left\">$row[5]</td>
<td align=\"left\">$row[6]</td>
<td align=\"left\">$row[7]</td>
<td align=\"left\">$row[8]</td>
<td align=\"left\">$row[9]</td></tr>"; }

echo '<br></table></br>';

}
   closetable();
   include("footer.php");
}

switch($op) {
     
      case "last5";
         last5();
         break;
   }
}
else {
   echo "Access Denied";
}

?>


I did parse this and it seems ok but of course I didn't have the database or nuke functions to plug into.
 
gator







PostPosted: Wed Mar 10, 2004 3:08 pm Reply with quote

OK some progress...I originally had:

Code:
if ($radminsuper==1) {    

    adminmenu("admin.php?op=last5 ", "" _BA." ", "beer.gif"); //line23
}


but it should have been...(it was missing the period before ._)

Code:
"" ._BA." "


Now the beer admin selection link shows up in the admin panel (Smile) but when selected it yields the following message:

Code:
invalid query in last5


I decided to use your code (beer_admin.php), but my original code yields the same result. Must be something wrong with the sql query? More troubleshooting with this line I guess?

Code:
$querystr = "SELECT ubi, bn, url, fi, speed, cool, tq, os, poster, pkey from FROM ".$prefix. "_beer"; 

   $resultlatest = sql_query($querystr, $dbi)
   or die ("invalid query in last5");

The table in my nuke dbase is nuke_beer
 
gator







PostPosted: Wed Mar 10, 2004 3:22 pm Reply with quote

Apparently "from FROM" is not proper SQL syntax LOL. It is alive Laughing
 
sixonetonoffun







PostPosted: Wed Mar 10, 2004 4:18 pm Reply with quote

lmao glad you worked it through have fun!
 
gator







PostPosted: Wed Mar 10, 2004 6:19 pm Reply with quote

Thanks Smile Having big trouble with incorporating the other functions into the module (mostly because there are isolated sections of html). However, I think I can get it to work eventually.

Is it safe to say that using html in modules is a bad thing? I see most modules are written just with php? It seems difficult to get html to work.
 
sixonetonoffun







PostPosted: Wed Mar 10, 2004 6:34 pm Reply with quote

They just echo the html content if that makes sense yet?
echo "<html></html>";

I use a dirty little perl script I snagged of the web for large amounts of html. Beats turning php on and off I think which is one other alternative.

All it does is fix quotes change them to from double to single. and adds the echo" and "; to each line of the .html file it parses. Then copy paste the results into a my php script.
 
gator







PostPosted: Wed Mar 10, 2004 10:04 pm Reply with quote

I found a nice little html to php converter so I just decided to complete everything in php. So for most things are working nicely. The last 5 beers function works 100%. However, the beer submit function is not working...I think it is a problem with the sql conversion. When I submit a new beer for entry I get the following error message (although the beer is, in fact, added to the dbase):

Code:
Warning: Missing argument 2 for sql_query() in /home/boozebro/public_html/includes/sql_layer.php on line 176


Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/boozebro/public_html/includes/sql_layer.php on line 238

You Beer has been registered


Could someone check my sql code to see where the problem lies? Basically wherever I used a mysql_command I just dropped the the 'my'
Thanks...I know I'm flooding the forums, but I think I'm close Smile

Code:


//start overall submit beer function

function submit(){
global $admin, $bgcolor2, $prefix, $dbi, $multilingual;
include("header.php");
GraphicAdmin();
Opentable();

//start beer submit php code

function validateInput($input,$textVal)
{
    if(strlen($input)==0)
        $message .= "<p>You forgot to enter the $textVal score!</p>";
    elseif(!is_numeric($input))
        $message .= "<p>The $textVal was not a valid number score!</p>";
    elseif($input<0 || $input>6)
        $message .= "The $textVal score was not between 0 and 6!</p>";
    return $message;
}

if($_POST['submit'])
{
$ubi = $_POST['ubi'];
$bn = $_POST['bn'];
$url = $_POST['url'];
$fi = $_POST['fi'];
$speed = $_POST['speed'];
$cool = $_POST['cool'];
$tq = $_POST['tq'];
$poster = $_POST['poster'];

if(!$ubi)
$message .= '<p>You forgot to enter the unique beer ID!</p>';
if(!$bn)
$message .= '<p>You forgot to enter the beer name!</p>';
if(!$url)
$message .= '<p>You forgot to enter the URL!</p>';

$message .= validateInput($fi,"first impression");
$message .=validateInput($speed,"speed");
$message .=validateInput($cool,"intangible");
$message .=validateInput($tq,"taste quality");

if(!$poster)
$message .= '<p>You forgot to enter the poster name!</p>';

//beer submit query for a repeat beer entry
$num = sql_num_rows(sql_query("SELECT ubi, poster FROM ".$prefix. "_beer WHERE ubi='$ubi' AND poster='$poster' LIMIT 1"));
if($num>0)
$message .= '<p>Beer ID already exists in database.</p>';

if(!$message)
{

//create overall score variable
$os = ($fi + $speed + $cool + $tq);

//beer submit insert sql query
$querystr = "INSERT INTO ".$prefix. "_beer (ubi, bn, url, fi, speed, cool, tq, os, poster) VALUES ('$ubi', '$bn', '$url', '$fi', '$speed', '$cool', '$tq', '$os', '$poster')";
$result = sql_query($querystr, $dbi) or die('<p>You beer could not be registered due to a system error. We apologize for any inconvenience.</p><p>'.sql_error().'</p>');
echo 'You Beer has been registered';
//sql_close();

exit();
}
else
echo "<font color='red'>$message</font>";
}
 
Display posts from previous:       
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Ravens PHP Scripts And Web Hosting Forum Index -> phpnuke 6.5

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©