Code works on a free host but not a payed one.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
akjackson1
Forum Newbie
Posts: 18
Joined: Mon Apr 14, 2008 9:08 am

Code works on a free host but not a payed one.

Post by akjackson1 »

Hi

Why does this code work on a free host, but not on a payed one? both have the same version of PHP.

Free host:http://adamjackson.890m.com/quiz/quiz.html

Payed host:http://www.truth-for-youth.com/test/quiz.html

Here is another example on the payed host:http://www.truth-for-youth.com/test/name.php
on the go.php page it has a smple code,

Code: Select all

<?php
switch ($name){
    case "$name":
        echo "Hello $name!, How are you doing?";
        break;
}
 
?>
Again this works on the other host perfectly.

Please help!
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Code works on a free host but not a payed one.

Post by onion2k »

At a guess I'd say register_globals are switched off on the paid host. That means you can't access variables with $name, you have to explicitly use $_GET['name'] or $_POST['name'].
User avatar
akjackson1
Forum Newbie
Posts: 18
Joined: Mon Apr 14, 2008 9:08 am

Re: Code works on a free host but not a payed one.

Post by akjackson1 »

Thanks, do you mean like this?

Code: Select all

<?php
    echo "Hello $_GET['name']!, How are you doing?";
?>
If you try it now http://www.truth-for-youth.com/test/name.php I get an error, so I must be doing something wrong??
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Code works on a free host but not a payed one.

Post by onion2k »

You can't just stick an array variable into the middle of a string like that. Either use {} or escape out of the string..

Code: Select all

<?php
echo "Hello {$_GET['name']}!, How are you doing?";
//or
echo "Hello ".$_GET['name']."!, How are you doing?";
?>
Personally, I use the second way.

PS. Your form is using POST, so you need to use $_POST['name'].
User avatar
akjackson1
Forum Newbie
Posts: 18
Joined: Mon Apr 14, 2008 9:08 am

Re: Code works on a free host but not a payed one.

Post by akjackson1 »

Thanks so much it worked!
User avatar
akjackson1
Forum Newbie
Posts: 18
Joined: Mon Apr 14, 2008 9:08 am

Re: Code works on a free host but not a payed one.

Post by akjackson1 »

I have a contact form that thanks the person by name and is supposed to send the information to a email addess, however I never get an email! It works when I make it just send the form and then go to a thank you page but then I can't thank than by name.

Here is what I have:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Message sent successfully</title>
<meta http-equiv="refresh" content="4; url=http://www.truth-for-youth.com/">
<link rel="stylesheet" type="text/css"href="main.css" />
<body>
<table width="309" border="0" align="center">
  <tr>
    <td><div align="center" class="Title2">
Thank You <?php
echo "".$_POST['name']."";
?>
    </div>
      <p align="center" class="style1">Your message was sent successfully!</p>
      <p align="center" class="SmallText">If you are not automatically redirected in a few seconds, <a href="http://www.truth-foryouth.com/">click here</a> to proceed.</p>
    <p class="style4">&nbsp;</p></td>
  </tr>
</table>
<span class="style2">
</span>
<?php
  $name = $_POST['name'] ;
  $email = $_POST['email'] ;
  $message = $_POST['message'] ;
 
 
  mail( "akjackson1@gmail.com", "Contact Form", "Name: ". $name . "\r\n\r\n". "Email: " . $email . "\r\n\r\n" . "Message: ". $message . "\r\n\r\n". "Mailing List: ". $mailinglist, "From: $email" );
?>
</body>
</html>
The first part thanks the person and the bottom php part is supposed to send it.
Post Reply