Jump to content


Photo

need more help


  • Please log in to reply
8 replies to this topic

#1 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 09 June 2006 - 07:01 PM

Ok I have actually tried for my first major script, I was doing great, I followed some advice, put together my own ideas into it, and came up with the perfect solution for validation and email, now I was trying to get a little fancier and throw in some other stuff, I also upgraded the way I coded xhtml/css and started doing it more neat, and more commented, on my site I said that that's what I believe, and I was trying now to go even further, I also read a post on here from someone named crayon violent and I started following advice so far as far as general structuring of php and it's helped a lot, I know I am not that good at structuring it yet but I will get better. Here is the problem I am encountering, and need help with.
<?php
if (isset($_POST['subscribe'])){
    $error = '';
 if ($_POST['name'] == '') {
    $error[] .= print 'The name field was filled in incorrectly, please correct<br/>';
 }if ($_POST['email'] == '') {
    $error[] .= print 'The Email Field was filled in incorrectly, please correct.<br />';
 }if ($_POST['verifyemail'] != $_POST['email']) {
    $error[] .= print 'The email Fields Do Not match, please correct.<br />';
 }if (is_array($alert)) {
    foreach($error as $key => $correctthis) {
    echo '$correctthis';
 >>> }else{
 $connection = mysql_connect('localhost', 'cantsay, 'definitelynote');
 $selectdb = mysql_select_db('stillalittletoomuchinfo');
     if(!$connection && !$selectdb){
    print 'Problem during database connection or selection';
    }else {
    $insert = 'INSERT INTO cantsaytablename (name, email) VALUES ("{$_POST[name]}", "{$_POST[email]")'; 
    }if(!mysql_query($insert)){
    print 'The information could not be inserted into the database';
    }else{
    echo 'successfuly completion of all processes';
free();
disconnect();

 }
};
It tells me that the else statement isn't good on a specific line, here is the error.
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Parse error: parse error, unexpected T_ELSE in /home/all/funnyemailforwards/public_html/dbprocessing/signuphandler.php on line 13[/quote]
I marked the line in the php. I am trying to create a double contact form, but there's nothing to see in the php file, and I was so damn stupid I just about left my password and username, and database name in the code, that would have been very very bad. But anyway what I was wondering is a few things, I marked the line the error is coming from in the code with a >>>.
What I need to figure out is, well I am setting up a subscribe and unsubscribe for a newsletter, so people can enter there email address to recieve the funny emails, right now I am trying to set the script for if they click submit on subscribe, that works, it validates, my error statement I took from all this worked out as well. I got all that, but when I started adding in database code I can't get it working. What I need help with is what am I doing wrong, I also need to somewhere wire in there, something to still email it to him, I am wanting to email him if the WHOLE process is successful for instance, if the error validation passes, the and all the database processes finish, then it send an email, then close the database and free. The questions I want to ask is why isn't this working here, how do I try and wire in the mail function properly. What about free and disconnect() how do I specify the connection I want closed. Do I need to do anything like remove slashes or anything specific before database entry that I am forgetting, The reason I am asking is magic quotes is on, I checked on his database phpinfo() information. But what I am wondering is are there any suggestions on
1. why this isn't working.
2. How to make it work.
3. How to integrate the mail program, and properly free and close the database connection.
4. ANY AND ALL advice about how I could do this differently, better ways to do certain parts, ANYTHING that involves advice on new ways to do this or anything.
5. IF there is ANYTHING I can POSSIBLY do to add any more security to this script when it's complete, I am trying to learn a hell of a lot at once, once I get this script to work, I am writing one below it for isset($_POST['unsubscribe']))
and doing exactly the same thing for it, except removing the database information instead, any advice would be great, I am at a critical learning point, to where I have almost pulled over the learning curve, and most of all I am starting to get new scripts ideas, how to work things differently, I am almost finally over that hump, any help would be appreciated.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 09 June 2006 - 07:14 PM

If you write your code so that you always indent every conditional and nested conditional, you'll soon see that you have unclosed { } tags, and you'll get the conditions checked logically and avoid syntax errors.
Legend has it that reading the manual never killed anyone.
My site

#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 09 June 2006 - 07:31 PM

I like that advice, can you show me some kind of open example, the reason is, I was attempting a few forms of indentation, but when I write my variables, that have longer text, and I end up having to have part of the variable on one line and the other part of the variable trailing down, is this ok, see if you go to
[a href=\"http://www.funnyemailforwards.com/signup.php\" target=\"_blank\"]Look at source code[/a]
and you look at the source code you will see what I am attempting to start doing with my html, any advice on that too would be appreciated, and examples for the php I can start following would be nice too, any advice as well about up there, what might be causing that error, or how I can do some of the stuff I asked, any help appreciated, especially advice, opinions or anything else i learnt 2 days ago, doing things my own way is good, but I can integrate 10 peoples ideas, and throw in my own fun stuff for the hell of it, and have a great time, with a much better programming ability.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 09 June 2006 - 08:33 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]if (isset($_POST['subscribe'])){
$error = '';
if ($_POST['name'] == '') {
$error[] .= print 'The name field was filled in incorrectly, please correct<br/>';[/quote]

Where to start?


1 ) You need to decide whether $error is a string or an array variable - it can't be both.

2 ) Print is a function returning TRUE/FALSE depending on wheher it worked, it doesn't return the printed output.

3 ) If you want to add to an array, just use $array[] = $something and not the concatenation operator ".=".

So, if $error is a string var

if (isset($_POST['subscribe'])){
    $error = '';
if ($_POST['name'] == '') {
    $error .= 'The name field was filled in incorrectly, please correct<br/>';

If OTOH it's an array var
if (isset($_POST['subscribe'])){
    $error = array();
if ($_POST['name'] == '') {
    $error[] = 'The name field was filled in incorrectly, please correct';

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 09 June 2006 - 09:23 PM

Thank you so much for advice, feedback and opinions barand, I removed that string setter up there, I changed the thing to = 'whatever' instead of using that operator, and using print. I made all those changes, thanks for the advice, any more would be appreciated.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#6 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 09 June 2006 - 10:21 PM

ok I took barand's advice, and andy's and someone from somewhere else I redid a large portion of my script, it works fine, I am now trying to integrate the mailing function, I would like any more advice, opinions, or anything on relating to any subject related to this.
Thanks for all the help so far, I was told that you didn't have to close the control structures is that true or no, because the last control structure on that one,

Here is the new code based based on advice given
<?php
if (isset($_POST['subscribe']))
{
 $error = "";

 if ($_POST['name'] == '')
   $error .= 'The name field was filled in incorrectly, please correct<br/>';

 if ($_POST['email'] == '')
   $error .= 'The Email Field was filled in incorrectly, please correct.<br />';

 if ($_POST['verifyemail'] != $_POST['email'])
   $error .= 'The email Fields Do Not match, please correct.<br />';

 if ($error != "")
   echo $error;
 else
 {
   $connection = mysql_connect('localhost', 'assmongers', '2centsandabarolofcrap');
   $selectdb = mysql_select_db('funnyemailforwards');

   if(!$connection || !$selectdb)
   {
     echo 'Problem during database connection or selection';
     echo mysql_error();
   }
   else
   {
     $insert = "INSERT INTO tablefrometernalhell (name, email) VALUES ('" . mysql_escape_string($_POST['name']) . "', '" . mysql_escape_string($_POST['email']) . "')";

     if(!mysql_query($insert))
       echo 'The information could not be inserted into the database';
     else
       echo 'successfuly completion of all processes';
   }
   @mysql_close($connection);
 }
}
?>
Well that's it, any advice suggestions or whatever I would be glad to hear them.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#7 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 10 June 2006 - 12:04 AM

How do I pass variables into message, I tried but it doesn't work I am sending one email to the person signing up to let them know they were added, and I was sending one email to my client letting him know someone signed up and who. What I need to figure out is how to get to pass the variables in where I need to like the name and email I tried a few different things but nothing worked thanks.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#8 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 12 June 2006 - 04:32 PM

I need advice, is this good or with the sql should I use, OR DIE, if so how do I utilize that over what I already have. I need to be able to switch it, but don't know enough about sql yet, How do I switch the if-else statements to utilize OR DIE with the error printed instead.


<?php
if (isset($_POST['subscribe']))
{
 $error = "";

 if ($_POST['name'] == '')
   $error .= 'The name field was filled in incorrectly, please correct<br/>';

 if ($_POST['email'] == '')
   $error .= 'The Email Field was filled in incorrectly, please correct.<br />';

 if ($_POST['verifyemail'] != $_POST['email'])
   $error .= 'The email Fields Do Not match, please correct.<br />';

 if ($error != "")
   echo $error;
 else
 {
   $connection = mysql_connect('shouldbeobvious', 'iknowiamnotgay', 'haveyoueverlostimportantpassword');
   $selectdb = mysql_select_db('hahacantsay');

   if(!$connection || !$selectdb)
   {
     echo 'Problem during database connection or selection';
     echo mysql_error();
   }
   else
   {
     $insert = "INSERT INTO crackheadtable (name, email) VALUES ('" . mysql_real_escape_string($_POST['name']) . "', '" . mysql_real_escape_string($_POST['email']) . "')";

     if(!mysql_query($insert))
       echo 'The information could not be inserted into the database';
     else
       $name = $_POST['name'];
       $email = $_POST['email'];
       $to = 'businessman332211@hotmail.com';
       $subject = 'Funny Email Forwards Sign up Notification';
       $message = "This is a confirmation to inform you that";
       $message .= "you have been signed up to the Funny Email Forwards";
       $message .= "Newsletter.  If you choose to unsubscribe please visit";
       $message .= "The website again to unsubscribe.";
       $message = wordwrap($message);
      if(mail($to, $subject, $message))
       echo "You have been subscribed successfully<br />";
      else
      echo "There was an error sending an email";
      }
   @mysql_close($connection);
   $to = "businessman332211@hotmail.com";
       $subject = "Funny Email Forwards sign up";
       $message = "This is a notification letting you know that {$name} has";
       $message .= "signed up to the news letter using {$email}.";
       $message .= "notification is coming from Funny Email Forwards.com";
       $message = wordwrap($message);
       mail($to, $subject, $message);
 }
}
?>

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#9 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 13 June 2006 - 05:10 AM

I have no idea what you mean... but it sounds very much like a non-SQL question. Besides, you should never die() out of any script that's publicly accessible... die() is for development only (and even that's not pretty).
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users