Jump to content

Recommended Posts

Helo! I'm developing a simple e-mail database, where the users can register their and receive som news posted by another script.

My script runs perfectlly over php 4 but when I try it on a PHP 5 server (testing in WAMP5) it just don't work!

It ignores the ifs and elseifs than returns:

"Error 003 unable to save data!"); echo "E-mail is now registered!"; } } else { echo "Invalid e-mail adress!"; } ?>"

 

Here is the full code for insert.php:

<?

include("inc/db_config.php");

$nome = $_GET['nome'];
$email = $_GET['email'];

$normal = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";

if ($nome == "") {
echo "Please type your <b>name</b>. ";
}
elseif ($email == "") {
echo "Please type your <b>e-mail</b>. ";
}
elseif (eregi($normal, $email) && $nome !="") {

$check = "SELECT email FROM `newsletter` WHERE `email`='".$email."'";
$verif = mysql_query($check);
if (mysql_num_rows($verif) != 0) {
	die("E-mail already registered!");
} else {

	$sql = "INSERT INTO `newsletter` VALUES (NULL,'$nome','$email')";

	$query = mysql_query($sql) or die ("<b>Error 003</b> unable to save data!");	

	echo "E-mail is now registered!";
}
} else {
echo "Invalid <b>e-mail adress</b>!";
}

?>

What am I doing wrng?

 

I hope someone can help me.

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/64161-solved-php-5-ignoring-the-if/
Share on other sites

Dont know whats going wrong with your script but im just pointing two things that can make your code a bit easier to write and read.

 

In queries u dont need apostrophes, it will work even without those.

 

"INSERT INTO `newsletter` VALUES (NULL,'$nome','$email')"

 

And also in queries, variables can be called inside double quotes:

 

"SELECT email FROM `newsletter` WHERE `email`='".$email."'";

 

to

 

"SELECT email FROM newsletter WHERE email='$email'";

Are shorttags enabled for php5?

 

I thought they were off by default, so you have to actually use <?php and not just <?

 

Oh mother! how couldn't I see this be4? dang! (sorry bout the fool words)

Thank you infinitelly very much for opening my "eye"

From now I will never forget to start with "<?php" instead of just "<?"!

 

The topic is now solved!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.