mailingList tutorial

Post here is you are having problems with any of the tutorials.
Post Reply
constantgamer247
Posts: 4
Joined: Mon May 21, 2012 2:26 pm

mailingList tutorial

Post by constantgamer247 »

So I'm following the [youtube]http://www.youtube.com/watch?v=dQBFBuYyHVk[/youtube] tutorial and I've run into a bit of a problem. No matter what I do I can not get my signup.php form to insert into the database. I think I'm having a bit of a problem with the
 mysql_select_db();
function as no matter what I include for a parameter I get no errors on the page what so ever T_T

I'm gonig to take an educated guess and say that
mysql_connect('localhost','USERNAME','PASSWORD');
is working as if I change USERNAME and PASSWORD in that line then I get errors such as can't connect to db.

Anything else I should post? My add user function
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}')");

	return ($result !== false) ? true: false;
}
Code for my signup.php form
<?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 only be comprised of letters'; 
	}
	
	if (preg_match('/^[a-z]+$/i', $_POST['lastname'] === 0)){
	$errors[] = 'Your last name should only be comprised of letters'; 
	}
	
	if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false){
	$errors[] =  'Your email address is not a valid format';
	}	
	
	if (empty($errors)){
		add_user($_POST['firstname'], $_POST['lastname'], $_POST['email']);
	}
	
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml/DTD/xhtml1-strick.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>OpenKonga</title>
		<link rel="stylesheet" type="text/css" href="stylez.css" media="all" />
	</head>
	<body>
		<div>
			<?php
			
			//echo print_r($errors);
						
			?>
		</div>
		<div>
			<form action="" method="post">
				<p>
					<label for="firstname">First Name: </label>
					<input type="text" name="firstname" id="firstname" />
				</p>
				<p>
					<label for="lastname">Last Name: </label>
					<input type="text" name="lastname" id="lastname" />
				</p>
				<p>
					<label for="eMail">eMail Address:</label>
					<input type="text" name="eMail" id="eMail" />
				</p>
				<p>
					<input type="submit" value="Signup" />
				</p>
			</form>
		</div>
	</body>
</html>
	
Can't think of anywhere else that the problem is O.o? I've followed the tutorial pretty much verbatim; only exception being I didn't perform the typos (maybe I did and don't know it).
Last edited by constantgamer247 on Mon May 21, 2012 4:00 pm, edited 2 times in total.
bowersbros
Posts: 534
Joined: Thu May 05, 2011 8:19 pm

Re: mailingList tutorial

Post by bowersbros »

its mysql_select_db() for a start, that might have some of the issues in it?
Last edited by jacek on Tue May 22, 2012 6:32 pm, edited 1 time in total.
Reason: Removed massive quote.
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ;)

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
constantgamer247
Posts: 4
Joined: Mon May 21, 2012 2:26 pm

Re: mailingList tutorial

Post by constantgamer247 »

>_< Blast the devil; yah I have
<?php

mysql_connect('localhost','USERNAME','PASSWORD');
mysql_select_db('mailing_list');

$path =  dirname(__FILE__);

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

?>
for my /core/init.inc.php file, I just typed it wrong it my post >_<

So I believe its correct. mysql_select_db(); right?
constantgamer247
Posts: 4
Joined: Mon May 21, 2012 2:26 pm

Re: mailingList tutorial

Post by constantgamer247 »

Okay, does this prove that it is the
mysql_select_db('mailing_list');
is the problem?

I threw in
or die();
statements so now my /core/init.inc.php file looks like
<?php

mysql_connect('localhost','USERNAME','PASSWORD')
or die("Error1");

mysql_select_db('mailing_list')
or die("Error2");

$path =  dirname(__FILE__);

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

?>
And I am getting Error2 ):

if I change line#6 to
mysql_select_db('openkong_mailing_list');
I do not get Error2 but it still also wont insert into the database ):

Could it be that in signup.php form action=""?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: mailingList tutorial

Post by jacek »

In your add_user() function the table and columns names in the SQL should have backticks around them instead of quotes '

Other than that, check your form inputs to make sure they have the correct names I guess.
Image
constantgamer247
Posts: 4
Joined: Mon May 21, 2012 2:26 pm

Re: mailingList tutorial

Post by constantgamer247 »

jacek wrote:In your add_user() function the table and columns names in the SQL should have backticks around them instead of quotes '

Other than that, check your form inputs to make sure they have the correct names I guess.
Thank you so much! :)

I thought it was just a different font. Didn't realise that the ` was on the same key with the ~ so I just assumed they were 'singleQuotes'

Anyway I changed it and it now works.

Thank you again :)
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: mailingList tutorial

Post by jacek »

The ` tells MySQL that the thing between then is a name of a column, table database etc and the ' tells it that the thing should just be treated as a string.

:)
Image
Post Reply