PHP problem...
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.
$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;
}
?>```
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…
"; 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; } ?>```
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 :( 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 **
First of, your code sucked, second: forgot an ; after random string function. third: its switch () {} not switch(); {}.
To shorten your code you can do
."blablabla";```
instead of
```markupecho "blablabla"."<br />";
echo "blablabla";```
Working code:
```markup
<?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)