What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » PHP Help

PHP Help
Author: Message:
DJeX
Veteran Member
*****

Avatar


Posts: 1138
Reputation: 11
– / Male / –
Joined: Jul 2003
O.P. PHP Help
Ok this is hard to explain so bare with me. What I want to do is take input from a dropdown list box and use it in 2 different functions in a php script.

Here is the drop down code:

code:
<select name="song_genre" id="song_genre">
      <option selected>select one</option>
      <option>----------------------------</option>
      <option value="techno">Techno</option>
      <option value="hip-hop">Hip-Hop</option>
    </select>


And here is the php that I need to work:

code:
<?php
include "link.php";
$file="filecount.txt";
$handle=fopen($file, "r+");
$hits=fread($handle,filesize("$file"));
$hits+=1;
fclose($handle);
$handle=fopen($file, "w");
fwrite($handle, $hits);

$file = fopen("$hits.html","w");

$filenamesong = "song.mrn";
$html = "<a href='http://www.beachassaultstudios.com/mrn/newfiles/$hits.html'target=frame2><font color='#FFFFFF'>$song_name</font></a><font color='#FFFFFF'>, posted by $artist </font>\n";
$fp = fopen($filenamesong, 'a+');
fputs($fp, $html) or die("Could not open file!");
fclose($fp);




fclose($handle);
fwrite($file,"<html>
<head>
<title>MRN Radio Now Playing - &song_name By: $artist</title>
</head>

<body bgcolor='#000000' topmargin='0' leftmargin='0'>
<table border='2' width='31%' bordercolorlight='#000000' bordercolordark='#000000' height='195' bordercolor='#000080'>
    <tr>
        <td bordercolorlight='#000080' bordercolordark='#000080' bordercolor='#000000' bgcolor='#000000' height='174'>
<address>
    <font face='Verdana' size='2' color='#FFFFFF'><span style='font-style: normal'><b>Song Name:</b> $song_name</span></font></address>
<address>
    <font face='Verdana' size='2' color='#FFFFFF'><span style='font-style: normal'><b>Artist:</b> $artist</span></font></address>
<address>
    <font face='Verdana' size='2' color='#FFFFFF'><span style='font-style: normal'><b>Song Genre:</b> $song_gender</span></font></address>
<address>
    <font face='Verdana' size='2'><span style='font-style: normal'>
    <font color='#FFFFFF'><b>Email:</b>
    </font>
    <a href='mailto:$email'><font color='#FFFFFF'>$email</font></a><font color='#FFFFFF'>
    </font> </span></font>
</address>
<address>
    <font face='Verdana' size='2'><span style='font-style: normal'>
    <font color='#FFFFFF'><b>Website:</b>
    </font>
    <a href='$artist_website' target='_blank'><font color='#FFFFFF'>Visit Artists Website</font></a></span></font></address>
<address>
&nbsp;</address>
<address>
    <span style='font-style: normal'><font face='Verdana' size='2'><b>
    <font color='#FFFFFF'>Description:</font><br></b></font></span>
    <textarea rows='2' name='S1' cols='35'>$description</textarea></address>
<form method='POST' action='--WEBBOT-SELF--' onSubmit='location.href='_derived/nortbots.htm';return false;' webbot-onSubmit>
    <!--webbot bot='SaveResults' U-File='_private/form_results.csv' S-Format='TEXT/CSV' S-Label-Fields='TRUE' startspan --><input TYPE='hidden' NAME='VTI-GROUP' VALUE='0'><!--webbot bot='SaveResults' i-checksum='43374' endspan -->
</form>
        </td>
    </tr>
    <tr>
        <td bordercolorlight='#000080' bordercolordark='#000080'>
<!--webbot bot='HTMLMarkup' startspan -->    <object classid='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject' width='305' height='72' id='playa'>
    <param name='FileName' value='$filename'>
    <param name=AutoSize value=false>
    <param name=DisplaySize value=0>
    <param name=ShowControls value=1>
    <param name=ShowDisplay value=0>
    <param name=ShowStatusBar value=1>
    <param name=AutoStart value=TRUE>
    <embed width='305' height='72' type='application/x-mplayer2' pluginspage='http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/' src='$filename' ShowControls='1' AutoStart=True ShowDisplay='0' ShowStatusBar='1'></EMBED>
    </object>
<!--webbot bot='HTMLMarkup' endspan --></td>
    </tr>
</table>
<p></a>
</p>
</body>

</html>");
fclose($file);

    for($i=0;$i<sizeof($userfile);$i++)
    {
    if(!$userfile_size[$i])
    continue;
   
    $UPLOAD = fopen( $userfile[$i], "r" );
    $contents = fread( $UPLOAD,$userfile_size[$i]);
    fclose( $UPLOAD );
    $SAVEFILE = fopen( $userfile_name[$i], "wb" );
    fwrite( $SAVEFILE, $contents,$userfile_size[$i] );
    fclose( $SAVEFILE );
    }
    echo "Song is now uploaded. Click <a href='viewsongs.php'>here</a> to go to radio";


?>

Sorry for the length of the code, but you need to see it all to get what I’m trying to do here.

Ok to make this easier I’ll do it in steps.

1. First there user selects a song genre from the form.
2. Seconded the user clicks submit
*Now the php code comes in
3. Song uploads
3. The php takes the song_genre variable from the drop down and writes it to the songs html page.
4. (This is the part I need help with) the php will look at the variable and see if it is techno, or hiphop and decide what to do.

Example: If song_genre = techno then also write link to song in techno.mrn
and so on for each variable in the drop down.

this is the section of code that writes to the song.mrn (main file)

code:
$filenamesong = "song.mrn";
$html = "<a href='http://www.beachassaultstudios.com/mrn/newfiles/$hits.html'target=frame2><font color='#FFFFFF'>$song_name</font></a><font color='#FFFFFF'>, posted by $artist </font>\n";
$fp = fopen($filenamesong, 'a+');
fputs($fp, $html) or die("Could not open file!");
fclose($fp);

I hope I didn't confuse the question. Can any one help? Thanks.

This post was edited on 03-02-2005 at 03:45 AM by DJeX.
[Image: top.gif]
03-02-2005 03:44 AM
Profile PM Web Find Quote Report
fluffy_lobster
Veteran Member
*****

Avatar
Posts: -2

Posts: 1391
Reputation: 23
36 / Male / Flag
Joined: Nov 2002
RE: PHP Help
well i'm not exactly sure where $song_gender is supposed to come from but it looks like that contains the song genre so:

code:
switch ($song_gender)
{
case 'country_and_western':
die();
case 'techno':
// do something useful here
default:
// unrecognised genre
}

To be honest if you managed to get that far in writing it I can't believe that you needed to explain it all to ask the question.

This post was edited on 03-02-2005 at 06:07 PM by fluffy_lobster.
03-02-2005 06:06 PM
Profile E-Mail PM Web Find Quote Report
DJeX
Veteran Member
*****

Avatar


Posts: 1138
Reputation: 11
– / Male / –
Joined: Jul 2003
O.P. RE: PHP Help
LOL well I guess you could say I’m a half assed coder. I examine others codes and take parts and put them into mine. I'm not good with PHP, I’m still learning so there is still a lot more I need to learn. Thakns for you help, i'm still not sure how to fit that into the code but i'll try :P Thanks


EDIT:

code:
switch ($song_gender)
{
case 'country_and_western':
die();
case 'techno':
// do something useful here
default:
// unrecognised genre
}

Some questions:

What does die() do? Does it end the code?

Under default: will that code be used every time the case is called?

This post was edited on 03-02-2005 at 09:33 PM by DJeX.
[Image: top.gif]
03-02-2005 09:30 PM
Profile PM Web Find Quote Report
KeyStorm
Elite Member
*****

Avatar
Inn-sewer-ants-pollie-sea

Posts: 2156
Reputation: 45
38 / Male / –
Joined: Jan 2003
RE: PHP Help
Die(a) is the same as

print(a);
exit;

ie: it sends the argument to the output and then ends the script execution

code:
switch($random)
{
case 1:
echo 'I knew it was gonna be 1';

case 2:
echo 'Who\'d say it was gonna be 2';

default:
echo 'I couldn\'t guess it';
}


If $random is 1, This switch runs from case 1 and also runs case 2 and default since nothing stops the interpreter.

code:
switch($random)
{
case 1:
echo 'I knew it was gonna be 1';
break;

case 2:
echo 'Who\'d say it was gonna be 2';
break;

default:
echo 'I couldn\'t guess it';
break;
}


In this case only case 1 is run and then the switch is exited by break

code:
switch($random)
{

default:
echo 'I couldn\'t guess it';
break;

case 1:
echo 'I knew it was gonna be 1';
break;

case 2:
echo 'Who\'d say it was gonna be 2';
break;
}


Even in this case, default will only be run if $random is neither 1 nor 2. You have to mind the break's the rest is just as it's supposed to work.

This post was edited on 03-02-2005 at 09:56 PM by KeyStorm.
03-02-2005 09:45 PM
Profile E-Mail PM Web Find Quote Report
fluffy_lobster
Veteran Member
*****

Avatar
Posts: -2

Posts: 1391
Reputation: 23
36 / Male / Flag
Joined: Nov 2002
RE: PHP Help
Oops :$ forgot about break;s

die(); was just a joke by the way :P and yes it does end the script. Like it should if someone is trying to infest your server with country and western.
03-03-2005 10:34 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On