Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks
Author Message
scorpious
Worker
Worker



Joined: Dec 03, 2005
Posts: 153

PostPosted: Fri Mar 28, 2008 5:51 am Reply with quote

Hi All

I have block that takes requests and then place the information within the database. As it stands it works great, but the contents are showing outside the block. I have tried other ways but am unable to make the content stay inside the block, here is the orignial file to view.

http://camp-battlegroup.myby.co.uk/block-Request.txt

Any advise

Cheers Scorp
 
View user's profile Send private message
Gremmie
Former Moderator in Good Standing



Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Fri Mar 28, 2008 10:12 am Reply with quote

Blocks need to capture all output in a variable called $content. The higher level logic then echo's the $content. Also get rid of the <html>, <head>, <body>, etc tags since Nuke already outputs those for you. Google the PHP-Nuke HOW-TO, there is some advice on how to make blocks that explains this.

_________________
GCalendar - An Event Calendar for PHP-Nuke
Member_Map - A Google Maps Nuke Module 
View user's profile Send private message
scorpious







PostPosted: Fri Mar 28, 2008 11:06 am Reply with quote

Hi

I have already tried the $content and the echo, when I place any of them in front of the code, the block either dont show or the right hand side wont show. I have been trying this out for the last few days and googled it.

Cheers Scorp
 
Gremmie







PostPosted: Fri Mar 28, 2008 11:42 am Reply with quote

I told you what you need to do in general. Without seeing your other attempts I can't help you. Again, look at the HOW-TO. You can't just echo stuff out inside a block, it needs to get captured in $content.
 
scorpious







PostPosted: Fri Mar 28, 2008 11:59 am Reply with quote

Hi

I have tried the below:

// User Input Area
$content .="<form action="index.php" method="POST">";
$content .="<table>";
$content .="<tr><td>Song title: </td><td><input type="text" name="song" value=""></td></tr>";
$content .="<tr><td>Artist: </td><td><input type="text" name="artist" value=""></td></tr>";
$content .="<tr><td>Your name: </td><td><input type="text" name="name" value=""></td></tr>";

$content .="</table>";
$content .="<input type="submit" name="submit" value="Send!">";
$content .="</form>";

?>

All HTML Tags have been removed.

But the block and the right side does not show. The linked script is the orginal script, which needs to be turned into a block or maybe a module at a later date. I have done a block that will show the date input fromthe orignial script, but this is my first time at trying to insert data from a block.

I have looked through the php nuke How to Do I have googled it for the last few days, so, as a last resort I thought I seek help here. Can anyone show me a example or where I am going wrong.

Cheers
Scorp
 
Gremmie







PostPosted: Fri Mar 28, 2008 12:10 pm Reply with quote

Well what you have above, should "work", except I would add a

Code:


$content = '';


before all of that.

I'm not sure sure about your form posting to index.php...but that is another issue.

Post the entire block code (if you haven't already).
 
scorpious







PostPosted: Fri Mar 28, 2008 12:16 pm Reply with quote

Hi Gremmie

Where would I had the $content =;

LMAO ok here is the full code with the database connection information.
Code:


$reg = "yes";
$ip = $_SERVER['REMOTE_ADDR'];
$content .="<center>Your ip is: ".$ip."</center><br />";
//
if (isset($_POST['submit'])) {
if (empty($_POST['song'])) {
$content .="Sorry, you haven't supplied the song title!<br />";
$reg = "no";
}
if (empty($_POST['artist'])) {
$content .="Sorry, you haven't supplied the artists name!<br />";
$reg = "no";
}
if (empty($_POST['name'])) {
$content .="Sorry, you haven't supplied your name<br />";
$reg = "no";
}

  $sql = "SELECT COUNT(*) FROM request_song WHERE ip='{$ip}'";
  $result = mysql_query($sql);
  if (mysql_result($result, 0) > 0) {
$content .="Sorry, your ip has already wished for one song, you can not wish for <br />another until the DJ's have seen your request!<br />";
$reg = "no";
}
if ($reg == "yes") {
    $sql = "INSERT INTO request_song(song, artist, name, ip)
            VALUES('{$_POST['song']}', '{$_POST['artist']}', '{$_POST['name']}', '{$ip}')";
    mysql_query($sql);
}
}
// User Input Area
$content .="<form action="index.php" method="POST">";
$content .="<table>";
$content .="<tr><td>Song title: </td><td><input type="text" name="song" value=""></td></tr>";
$content .="<tr><td>Artist: </td><td><input type="text" name="artist" value=""></td></tr>";
$content .="<tr><td>Your name: </td><td><input type="text" name="name" value=""></td></tr>";
 
$content .="</table>";
$content .="<input type="submit" name="submit" value="Send!">";
$content .="</form>";

?>
 
Guardian2003
Site Admin



Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam

PostPosted: Fri Mar 28, 2008 2:48 pm Reply with quote

I edited your post to put the code within BBCode 'code' tags
Try it on the line below $ip=$_SERVER......
I will have to also assume the forums here stripped out your opening php tag
 
View user's profile Send private message Send e-mail
scorpious







PostPosted: Fri Mar 28, 2008 4:19 pm Reply with quote

Hi guardian

Nope block will not show and the righthand side is not showing.

I left out the top part of the code with the database connection when posting the code at first.

Scorp
 
Gremmie







PostPosted: Fri Mar 28, 2008 5:13 pm Reply with quote

Your problem, scorpious, was that you had put double quotes inside a double quoted string without properly escaping them. I switched you over to single quotes, and added the $content = ''; at the top. This displays on my site.

Code:


<?php
$content = '';
$reg = "yes";
$ip = $_SERVER['REMOTE_ADDR'];
$content .="<center>Your ip is: ".$ip."</center><br />";
//
if (isset($_POST['submit'])) {
if (empty($_POST['song'])) {
$content .="Sorry, you haven't supplied the song title!<br />";
$reg = "no";
}
if (empty($_POST['artist'])) {
$content .="Sorry, you haven't supplied the artists name!<br />";
$reg = "no";
}
if (empty($_POST['name'])) {
$content .="Sorry, you haven't supplied your name<br />";
$reg = "no";
}

  $sql = "SELECT COUNT(*) FROM request_song WHERE ip='{$ip}'";
  $result = mysql_query($sql);
  if (mysql_result($result, 0) > 0) {
$content .="Sorry, your ip has already wished for one song, you can not wish for <br />another until the DJ's have seen your request!<br />";
$reg = "no";
}
if ($reg == "yes") {
    $sql = "INSERT INTO request_song(song, artist, name, ip)
            VALUES('{$_POST['song']}', '{$_POST['artist']}', '{$_POST['name']}', '{$ip}')";
    mysql_query($sql);
}
}
// User Input Area
$content .='<form action="index.php" method="POST">';
$content .='<table>';
$content .='<tr><td>Song title: </td><td><input type="text" name="song" value=""></td></tr>';
$content .='<tr><td>Artist: </td><td><input type="text" name="artist" value=""></td></tr>';
$content .='<tr><td>Your name: </td><td><input type="text" name="name" value=""></td></tr>';
 
$content .='</table>';
$content .='<input type="submit" name="submit" value="Send!">';
$content .='</form>';

?>


BTW, you should set your error reporting to high and you would see that you had a syntax error.
 
scorpious







PostPosted: Fri Mar 28, 2008 5:27 pm Reply with quote

Hi

Yes worked first time

Many thanks to you all for your advise and help

Scorp
 
fresh
Regular
Regular



Joined: Mar 12, 2008
Posts: 74

PostPosted: Fri Mar 28, 2008 10:16 pm Reply with quote

this block work as a stand alone or does this work with shoutcast or something like that?? cpz ic database for some mod?
 
View user's profile Send private message
scorpious







PostPosted: Sat Mar 29, 2008 3:47 am Reply with quote

Hi Fresh

This Block was done for members to send requests for a song, it can be used for anything, but if you want to use it for shoutCast like me here is the sql info you will need:

CREATE TABLE `request_song` (
`id` bigint NOT NULL auto_increment,
`song` longtext NOT NULL default '',
`artist` longtext NOT NULL default '',
`name` longtext NOT NULL default '',
`ip` varchar(100) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM;

Cope and paste the above save as request.sql

Remember if you have coped the code that Gremmie posted you will need the Connection information at the top.

<?php

if (eregi("block-Request.php",$PHP_SELF)) {
Header("Location: index.php");
die();
}

mysql_connect("Localhost","username","password");
// Change the above line
mysql_select_db("DBName");
// global $prefix, $db <<< Would not work

Copy and paste the above at the top of your file.

Did you have a look at the ShoutCast Blocks at Camp-Battlegroup.

Cheers

Scorp
 
Gremmie







PostPosted: Sat Mar 29, 2008 9:43 am Reply with quote

Well...$prefix and $db would work if you convert the rest of the mysql_ calls over to the $db abstraction layer.
 
scorpious







PostPosted: Sat Mar 29, 2008 1:11 pm Reply with quote

Cheers Gremmie

I was wondering how to use the global $prefix

Thanks for all the advise and help

Scorp
 
Gremmie







PostPosted: Sat Mar 29, 2008 2:16 pm Reply with quote

Well it doesn't look like you used a prefix on your table request_song, so you wouldn't have to use it if you didn't want to. The prefix is used in case you want to run multiple nuke sites or add-ons together in the same database and need to avoid name clashes.

To use the $db layer, just take a look at some of the included blocks and see what they are doing. There are member functions like $db->sql_query(), $db->sql_fetchrow(), etc that simply replace the mysql_xxx() calls you have in the block code. You could keep the code you have the same; the only caveats with doing that is that you are creating an extra database connection per page load for that block code, and your code isn't totally "nuked". You can decide if those are important enough to switch the code over.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks

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 ©