Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

sEnte

Query errado?

Recommended Posts

sEnte

<?php
function add_user($firstname, $lastname, $email){
 $firstname = mysql_real_escape_string($firstname);
 $lastname = mysql_real_escape_string($lastname);
 $email = mysql_real_escape_string($email);
 $result = mysql_query("INSERT INTO `users` (`firstname`, `lastname`, `email`) VALUES ('{$firstname}', '{$lastname}', '{$email}')");
 echo mysql_error();
 return ($result !== false) ? true : false;
}
?>

<?php
include ('core/init.inc.php');
if (isset($_POST['firstname'], $_POST['lastname'], $_POST['email'])) {
 $errors = array();
 if (preg_match('/^[a-z]+$/i', $_POST['firstname']) === 0) {
  $errors[] = 'Your first name should contain letters only';
 }
 if (preg_match('/^[a-z]+$/i', $_POST['lastname']) === 0) {
  $errors[] = 'Your last name should contain letters only';
 }
 if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
  $errors[] = 'The email address you gave does not appear to be valid';
 }
 if (empty($errors)) {
  add_user($_POST['firstname'], $_POST['lastname'], $_POST['email']);
 }
}
?>
<!DOCTYPE html>
<html>
<head>
 <style type="text/css">
  body{background: #f1f1f1;}
  label{display: block;}
  input[type="text"]{width: 300px;}
 </style>
 <title></title>
</head>
<body>
 <div>
  <?php
   print_r($errors);
  ?>
 </div>
 <div>
  <form action="" method="post">
   <p>
 <label for="firstname">Firstname: </label>
 <input type="text" name="firstname" id="firstname" />
   </p>
   <p>
 <label for="lastname">Lastname: </label>
 <input type="text" name="lastname" id="lastname" />
   </p>
   <p>
 <label for="email">eMail: </label>
 <input type="text" name="email" id="email" />
   </p>
   <p>
 <input type="submit" />
   </p>
  </form>
 </div>
</body>
</html>

Quanto a erros... simplesmente nada. Insiro os dados nos campos e quando clico para postar simplesmente recebo uma página em branco e não insere nada na bd


"If It Ain't Broke, Break it and build something Cooler!" Unknown

Share this post


Link to post
Share on other sites
sEnte

Warning: include({$path}/mail.inc.php): failed to open stream: No such file or directory in /var/www/mailing_list/core/init.inc.php on line 8

Warning: include(): Failed opening '{$path}/mail.inc.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/mailing_list/core/init.inc.php on line 8

Notice: Undefined variable: errors in /var/www/mailing_list/signup.php on line 46


"If It Ain't Broke, Break it and build something Cooler!" Unknown

Share this post


Link to post
Share on other sites
sEnte

Esta é a minha estrutura

mailing_list
> core
 ->inc
	 -->mail.inc.php
->init.inc.php
> send_mail.php
> signup.php
> unsubscribe.php

init.inc.php

<?php

mysql_connect('localhost', 'user', 'password');
mysql_select_db('mailing_list');

$path = dirname(__FILE__);

include('{$path}/core/inc/mail.inc.php');

?>

substitui isto

include('{$path}/core/inc/mail.inc.php');

por isto

include("{$path}/core/inc/mail.inc.php");

e funcionou

Edited by sEnte

"If It Ain't Broke, Break it and build something Cooler!" Unknown

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. 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.