Follow us on Twitter!
It is never to LATE to become what you never WERE.
Friday, April 18, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 25
Guests Online: 21
Members Online: 4

Registered Members: 82824
Newest Member: devilslegion
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

PHP problem...

shadowboy1505
Member

Your avatar

Posts: 24
Location:
Joined: 12.02.08
Rank:
Newbie
Posted on 16-08-08 06:32
I'm trying to make a random verse generator for my church's webpage, but I can't seem to get it to work and I can't figure out what's wrong. Please can someone help? Thanks in advance.
Code
<?php
$randverse = mt_rand(1,7)
switch($randverse);
   {
   case 1:
      echo "For God so loved the world, that He gave His only begotten Son, that whoever believes in Him shall not perish, but have eternal life." . "<br />";
      echo "-John 3:16";
      break;
   case 2:
      echo "as it is written, THERE IS NONE RIGHTEOUS, NOT EVEN ONE" . "<br />";
      echo "-Romans 3:10";
      break;
   case 3:
      echo "5 For there is one God, and one mediator also between God and men, the man Christ Jesus, 6 who gave Himself as a ransom for all, the testimony given at the proper time." . "<br />";
      echo "-1 Timothy 2:5-6";
      break;
   case 4:
      echo "Jesus said to him, "I am the way, and the truth, and the life; no one comes to the Father but through Me." . "<br />";
      echo "-John 14:6";
      break;
   case 5:
      echo "So faith comes from hearing, and hearing by the word of Christ." . "<br />";
      echo "-Romans 10:17";
      break;
   case 6:
      echo "for all have sinned and fall short of the glory of God," . "<br />";
      echo "-Romans 3:23";
      break;
   case 7:
      echo "For the wages of sin is death, but the free gift of God is eternal life in Christ Jesus our Lord." . "<br />";
      echo "-Romans 6:23";
      break;
   default:
      echo $randverse;         //for finding errors...if the script will actually work
      break;
   }
?>





Author

RE: PHP problem...

shadowboy1505
Member

Your avatar

Posts: 24
Location:
Joined: 12.02.08
Rank:
Newbie
Posted on 16-08-08 06:34
Oh and any ideas on how to make this better (or shorter) would be appreciated also. Thanks


Author

RE: PHP problem...

fashizzlepop
Member



Posts: 482
Location: Old folks home.
Joined: 08.04.08
Rank:
Moderate
Posted on 16-08-08 07:15
Put a semi colon after $randverse = mt_rand(1,7)


"The definition of insanity is doing the same thing over and over again and expecting different results.
~Albert Einstein~


csullivan.codeinspire.net/images/boomsig2.png
fashizzlepop@gmail.com http://csullivan.codeinspire.net/
Author

RE: PHP problem...

shadowboy1505
Member

Your avatar

Posts: 24
Location:
Joined: 12.02.08
Rank:
Newbie
Posted on 16-08-08 07:23
that's not it...


Author

RE: PHP problem...


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 16-08-08 07:30
Code
switch($randverse);




wrong syntax for a switch/case


Author

RE: PHP problem...


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 16-08-08 07:41
<?php
$verses = array(
'a',
'b',
'c',
'd'
);
echo $verses[ rand(1, count($verses))-1 ];
?>



Author

RE: PHP problem...

shadowboy1505
Member

Your avatar

Posts: 24
Location:
Joined: 12.02.08
Rank:
Newbie
Posted on 16-08-08 07:42
How is that incorrect syntax? It's the same syntax I used in another file and the other one works fine. I even removed the semicolon to be sure and it still didn't work...
Actually, for clarification, the script does work. It just doesn't output what I want. I want it to output only one verse, but it outputs this...
Code
"; echo "-John 3:16"; break; case 2: echo "as it is written, THERE IS NONE RIGHTEOUS, NOT EVEN ONE" . "
"; echo "-Romans 3:10"; break; case 3: echo "5 For there is one God, and one mediator also between God and men, the man Christ Jesus, 6 who gave Himself as a ransom for all, the testimony given at the proper time." . "
"; echo "-1 Timothy 2:5-6"; break; case 4: echo "Jesus said to him, "I am the way, and the truth, and the life; no one comes to the Father but through Me." . "
"; echo "-John 14:6"; break; case 5: echo "So faith comes from hearing, and hearing by the word of Christ." . "
"; echo "-Romans 10:17"; break; case 6: echo "for all have sinned and fall short of the glory of God," . "
"; echo "-Romans 3:23"; break; case 7: echo "For the wages of sin is death, but the free gift of God is eternal life in Christ Jesus our Lord." . "
"; echo "-Romans 6:23"; break; default: echo $randverse; //for finding errors...if the script will actually work break; } ?>





Author

RE: PHP problem...


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 16-08-08 07:47
There are broken quotes.
eg
Code

echo "Jesus said to him, "I am the way, and the truth, and the life; no one comes to the Father but through Me." . "<br />";





That is, there are 5 quotation marks in that line of code. Everything comes in pairs!! :)




Edited by on 16-08-08 07:54
Author

RE: PHP problem...

shadowboy1505
Member

Your avatar

Posts: 24
Location:
Joined: 12.02.08
Rank:
Newbie
Posted on 16-08-08 07:53
Never mind...I just ran a script I know works and it doesn't work so I guess my server's screwed up Sad crap


Author

RE: PHP problem...

Mr_Cheese




Posts: 2468
Location: Brighton, UK
Joined: 30.11.04
Rank:
Uber Elite
Posted on 16-08-08 12:15
shadowboy1505 wrote:
Never mind...I just ran a script I know works and it doesn't work so I guess my server's screwed up Sad crap


no its not your server. its your poor code.

As Swatmumba said, its extra quotes that break out of your echo;s.
echo "Jesus said to him, "I am

echo "Jesus said to him, \"I am
http://www.hellboundhackers.org/
Author

RE: PHP problem...


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 16-08-08 12:39
First of, your code sucked, second: forgot an ; after random string function. third: its switch () {} not switch(); {}.

To shorten your code you can do
Code
echo "blabla<br />"
     ."blablabla";




instead of

Code
echo "blablabla"."<br />";
echo "blablabla";




Working code:
Code

<?php
$randverse = mt_rand(1,7);
switch ($randverse){

case 1:
echo "For God so loved the world, that He gave His only begotten Son, that whoever believes in Him shall not perish, but have eternal life.<br />"
   ."-John 3:16";
break;

case 2:
echo "as it is written, THERE IS NONE RIGHTEOUS, NOT EVEN ONE<br />"
   ."-Romans 3:10";
break;

case 3:
echo "5 For there is one God, and one mediator also between God and men, the man Christ Jesus, 6 who gave Himself as a ransom for all, the testimony given at the proper time.<br />"
   ."-1 Timothy 2:5-6";
break;

case 4:
echo "Jesus said to him, \"I am the way, and the truth, and the life; no one comes to the Father but through Me.\"<br />"
   ."-John 14:6";
break;

case 5:
echo "So faith comes from hearing, and hearing by the word of Christ."
   ."-Romans 10:17";
break;

case 6:
echo "for all have sinned and fall short of the glory of God,<br />"
   ."-Romans 3:23";
break;

case 7:
echo "For the wages of sin is death, but the free gift of God is eternal life in Christ Jesus our Lord.<br />"
   ."-Romans 6:23";
break;

default:
echo $randverse; //for finding errors...if the script will actually work
break;

}
?>





B)


Author

RE: PHP problem...

shadowboy1505
Member

Your avatar

Posts: 24
Location:
Joined: 12.02.08
Rank:
Newbie
Posted on 16-08-08 18:57
Thank you but like I said my server really is screwed up so I have no way of testing anything right now.

p.s. I just started learning PHP 2 days ago and with school and work I haven't really had much time to learn, so my coding skills aren't too good right now.


Author

RE: PHP problem...


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 16-08-08 21:00
to make it easier, i would say store in a DB
Author

RE: PHP problem...

fashizzlepop
Member



Posts: 482
Location: Old folks home.
Joined: 08.04.08
Rank:
Moderate
Posted on 17-08-08 01:12
Easier??? Not for something this small...


"The definition of insanity is doing the same thing over and over again and expecting different results.
~Albert Einstein~


csullivan.codeinspire.net/images/boomsig2.png
fashizzlepop@gmail.com http://csullivan.codeinspire.net/
Author

RE: PHP problem...


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 17-08-08 01:23
Seeing how this thread is still alive, I'll try to help. The code can really be shortened.

Code
$quotes_arr = file('somefile.txt', FILE_IGNORE_NEW_LINES); //1 quote per line
$element_num = array_rand($quotes_arr, 1);
echo $quotes_arr[$element_num];