Jump to content


Photo

Can not get e-mail info from login system


  • Please log in to reply
18 replies to this topic

#1 mariocesar

mariocesar
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 24 October 2006 - 03:40 PM

Please I need help, how can I get the e-mail info from the login table, I know I'm doing something wrong but I'm new with PHP, here is the code I using
<? session_start() ?>
<?php
if (!$logged_in_user)
echo "You are login as, ".$logged_in_user.".";
 
	mysql_connect ('mysql145.secureserver.net', $user = "userregister", $pass = "userregister" );
	
$result = mysql_fetch_array(mysql_query("SELECT * FROM `userregister` WHERE `name`='".$logged_in_user."'"));
//then to grab the users email just do:
echo "An email was sent to ".$result['email']." with the information.";
	
	?>

thanks,

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 24 October 2006 - 04:02 PM

Don't nest your functions, it looks untidy and is harder to trap errors, try this:

<?php
// Create session
session_start();

// Is user logged in
if (!$logged_in_user){
   echo "You are login as, ".$logged_in_user.".";

   // Connect to the database
   mysql_connect("mysql145.secureserver.net", "userregister", "userregister");

   // select and execute the query
   $sql = "SELECT * FROM `userregister` WHERE `name`= '$logged_in_user'";
   $result = mysql_query($sql) or printerror($sql, mysql_error());
   $row = mysql_fetch_array($result) or printerror($sql, mysql_error());

   //then to grab the users email just do:
   echo "An email was sent to {$result['email']} with the information.";
}

function printerror($code, $message){
   echo "Couldn't run the following code: $code\n\nFailed with the following error: $message\n\n";
}
?>

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 mariocesar

mariocesar
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 24 October 2006 - 05:28 PM

Thanks, Huggie the scrip give me a blank page, what I trying to do is get the e-mail from the userregister dbase, what happen is that I have a scrip that pulls info from a form and upload a file all at once, but when the client is allready register all the main info is in the dbase, what I was doing is make them fill the form with all the info they allready enter plus some info of the file they uploading, them the script send them an e-mail, but when I take all the main info from the form the scrip does not work don't send the e-mail back to them, just dowload the file. I don't want them to fill their info each time they send a file.

#4 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 24 October 2006 - 06:11 PM

see any problems here ? --> if (!$logged_in_user){ echo "You are login as, ".$logged_in_user.".";

Try removing the "not" (!) and you should get one step in the right direction:
if ($logged_in_user){
   echo "You are login as, ".$logged_in_user.".";

But as the script is now, i cannot find any call to mail() anywhere, is this the full code ? ?

#5 mariocesar

mariocesar
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 24 October 2006 - 06:31 PM

No Is not the full code, but I tryed to get the email from  the user register dbase now I have this message:
You are login as, Mario Balarezo.Couldn't run the following code: SELECT * FROM 'userregister' WHERE 'name'= 'Mario Balarezo' Failed with the following error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''userregister' WHERE 'name'= 'Mario Balarezo'' at line 1
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/m/a/r/mariocesar/html/getemail2.php on line 15
Couldn't run the following code: SELECT * FROM 'userregister' WHERE 'name'= 'Mario Balarezo' Failed with the following error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''userregister' WHERE 'name'= 'Mario Balarezo'' at line 1 An email was sent to with the information.

#6 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 24 October 2006 - 06:38 PM

seems you are using single quotes around the col-names in your query

wrong: SELECT FROM 'tablename' WHERE 'colname' = '$something'

note that using single quotes around the variable $something IS correct

works: SELECT FROM tablename WHERE colname = '$something'

or you can back-tick ( ` ) around the tabledata, but not single or double quote

#7 mariocesar

mariocesar
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 24 October 2006 - 07:05 PM

thanks, I changed and know is giving me this:
Parse error: parse error, unexpected T_STRING in /home/content/m/a/r/mariocesar/html/getemail2.php on line 13



#8 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 24 October 2006 - 07:07 PM

post your current code, the full relevant code

#9 mariocesar

mariocesar
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 24 October 2006 - 07:13 PM

here is the code:
<?php
// Create session
session_start();

// Is user logged in
if ($logged_in_user){
   echo "You are login as, ".$logged_in_user.".";

   // Connect to the database
   mysql_connect("mysql103.secureserver.net", "userregister", "userregister");

   // select and execute the query
   $sql = SELECT * FROM userregister WHERE name = '$logged_in_user';
   $result = mysql_query($sql) or printerror($sql, mysql_error());
   $row = mysql_fetch_array($result) or printerror($sql, mysql_error());

   //then to grab the users email just do:
   echo "An email was sent to {$result['email']} with the information.";
}

function printerror($code, $message){
   echo "Couldn't run the following code: $code\n\nFailed with the following error: $message\n\n";
}
?>


#10 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 24 October 2006 - 07:19 PM

OK - you took my select example for definitive "as was" i see, you still have to put double quotes around the select string:

$sql = "SELECT * FROM userregister WHERE name = '$logged_in_user'";

#11 mariocesar

mariocesar
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 24 October 2006 - 07:37 PM

I still got thia message:
You are login as, Mario Balarezo.Couldn't run the following code: SELECT * FROM userregister WHERE name = 'Mario Balarezo' Failed with the following error: No Database Selected
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/m/a/r/mariocesar/html/getemail2.php on line 15
Couldn't run the following code: SELECT * FROM userregister WHERE name = 'Mario Balarezo' Failed with the following error: No Database Selected An email was sent to with the information.
here is the code:
<?php
// Create session
session_start();

// Is user logged in
if ($logged_in_user){
   echo "You are login as, ".$logged_in_user.".";

   // Connect to the database
   mysql_connect("mysql103.secureserver.net", "userregister", "userregister");

   // select and execute the query
   $sql = "SELECT * FROM userregister WHERE name = '$logged_in_user'";
   $result = mysql_query($sql) or printerror($sql, mysql_error());
   $row = mysql_fetch_array($result) or printerror($sql, mysql_error());

   //then to grab the users email just do:
   echo "An email was sent to {$result['email']} with the information.";
}

function printerror($code, $message){
   echo "Couldn't run the following code: $code\n\nFailed with the following error: $message\n\n";
}
?>


#12 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 24 October 2006 - 07:57 PM

Well, the message is clear - No database selected


<?php

$dbhostname = "????";
$dbuser = "????";
$dbpassword = "????";
$db = "????";

mysql_connect($dbhostname, $dbuser, $dbpassword) or die("Could not connect to db");
mysql_select_db("$db") or die("Could not select db");

// THEN you can do MySql stuff from here and down!

?>


In your case here, it would be adding mysql_select_db() below your mysql_connect()

#13 mariocesar

mariocesar
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 24 October 2006 - 08:52 PM

here this one is working but don't pull the e-mail info from the dbase

<?php
// Create session
session_start();

// Is user logged in
if ($logged_in_user){
   echo "You are login as, ".$logged_in_user.".";

   // Connect to the database
   $user="userregister";
    $host="mysql103.secureserver.net";
    $password="userregister";
    $database = "userregister";
    mysql_connect($host,$user,$password);
    mysql_select_db($database);

   // select and execute the query
   $sql = "SELECT * FROM `usersreg` WHERE `name`= '$logged_in_user'";
   $result = mysql_query($sql) or printerror($sql, mysql_error());
   $row = mysql_fetch_array($result) or printerror($sql, mysql_error());

   //then to grab the users email just do:
   echo "An email was sent to {$result['email']} with the information.";
}

function printerror($code, $message){
   echo "Couldn't run the following code: $code\n\nFailed with the following error: $message\n\n";
}
?>



#14 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 24 October 2006 - 08:58 PM

change
$result['email']
to
$row['email']
as
$row=mysql_fetch_array($result)

#15 mariocesar

mariocesar
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 24 October 2006 - 09:24 PM

thanks a lot, as I mentioned before I have to send a message to this e-mail saying that  I received their info and we received the file, now that I pull out the e-mail how can I send the message? thanks fo all

#16 mariocesar

mariocesar
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 25 October 2006 - 04:36 AM

Thanks for everything Alpine, here is what I'm talking about:

<? 
session_start();

// Is user logged in
if ($logged_in_user){
   

   // Connect to the database
   $user="userregister";
    $host="mysql103.secureserver.net";
    $password="userregister";
    $database = "userregister";
    mysql_connect($host,$user,$password);
    mysql_select_db($database);

   // select and execute the query
   $sql = "SELECT * FROM `usersreg` WHERE `name`= '$logged_in_user'";
   $result = mysql_query($sql) or printerror($sql, mysql_error());
   $row = mysql_fetch_array($result) or printerror($sql, mysql_error());

//grabs the POST variables and puts them into variables that we can use */ 

$Projectname=$_POST['Projectname'];
$Duedate=$_POST['Duedate'];
$Reference=$_POST['Reference'];
$Copiesrequired=$_POST['Copiesrequired'];
$Artworkprovided=$_POST['Artworkprovided'];
$Flatsize=$_POST['Flatsize'];
$Finishedsize=$_POST['Finishedsize'];
$Stockforcolorcopies=$_POST['Stockforcolorcopies'];
$Stockforbw=$_POST['Stockforbw'];
$Printcoverson=$_POST['Printcoverson'];
$Bworiginals=$_POST['Bworiginals'];
$Bworiginalsare=$_POST['Bworiginalsare'];
$Bwprint=$_POST['Bwprint'];
$Collatebw=$_POST['Collatebw'];
$Additionalbw=$_POST['Additionalbw'];
$Filetype=$_POST['Filetype'];
$Applicationtype=$_POST['Applicationtype'];


   if($Copiesrequired){
        } 
        else{ 
            $error.=""; 
            } 

    if($error==""){ 
        echo "Thank you! A receipt of your submission will be e-mailed to you immediately."; 
 
$mailContent="--------Contact--------\n" 
            ."Projectname: ".$Projectname."\n" 
            ."Reference: ".$Reference."\n"
			."Copiesrequired: ".$Copiesrequired."\n"
			."Artworkprovided: ".$Artworkprovided."\n"
			."Filetype: ".$Filetype."\n"
            ."Applicationtype: ".$Applicationtype."\n";
            
$toAddress="upload@copymailforyou.com"; 
$subject="Copyroominc.com Upload Form";  
$recipientSubject="Copyroominc.com Upload Form"; 
$receiptMessage = "Thank you ".$row['name']." Our Representative will contact you as soon as possible.\n\n\nHere is what you submitted to us:\n\n" 
            ."----------------\n" 
            ."Projectname: ".$Projectname."\n" 
            ."Reference: ".$Reference."\n"
			."Copiesrequired: ".$Copiesrequired."\n"
			."Artworkprovided: ".$Artworkprovided."\n"
			."Filetype: ".$Filetype."\n"
            ."Applicationtype: ".$Applicationtype."\n";
            
//---------------------------------- 
mail($row['email'], $subject, $receiptMessage,"From:$toAddress"); 
mail($toAddress,$recipientSubject,$mailContent,"From:$row['email']");

$connection=mysql_connect('mysql103.secureserver.net', $user = "quoteupload", $pass = "quoteupload") or die("Unable to connect!"); 

mysql_select_db("quoteupload") or die("Unable to select database!"); 
 
$query="INSERT INTO quoteupload ( Name, Company, Projectname, Duedate,  Reference, Copiesrequired, Artworkprovided, Flatsize,
Finishedsize, Stockforcolorcopies, Stockforbw, Printcoverson, Bworiginals, Bworiginalsare, Bwprint, Collatebw, Additionalbw, Filetype, Applicationtype) 
        VALUES( '".$row['name']."', '".$row['company']."', '".$Projectname."', '".$Duedate."', '".$Reference."', '".$Copiesrequired."', '".$Artworkprovided."', '".$Flatsize."', '".$Finishedsize."',
		'".$Stockforcolorcopies."', '".$Stockforbw."', '".$Printcoverson."', '".$Bworiginals."', '".$Bworiginalsare."', '".$Bwprint."', '".$Collatebw."',
		'".$Additionalbw."', '".$Filetype."', '".$Applicationtype."')"; 

$result=mysql_query($query) or die("Error in query:".mysql_error()); 

mysql_close($connection); 
 
        } }
    else{ 

            print "Sorry, but the form cannot be sent until the fields indicated are filled out completely - <br>\n"; 
            print "$error<br>\n"; 
            print "<br>\n"; 
            print "<br>\n"; 
            print "Please use your \"Back\" button to return to the form to correct the omissions.  Thank you.<br>\n"; 
        } 
?>
                          <?php
include ("uploadclass.php"); 
$upload_class = new FileUpload; 
$upload_class->temp_file_name = trim($_FILES['upload']['tmp_name']); 
$upload_class->file_name = trim(strtolower($_FILES['upload']['name'])); 
$upload_class->upload_dir = "php_uploads/"; 
$upload_class->upload_log_dir = "php_uploads/upload_logs/"; 
$upload_class->max_file_size = 5242880; 
$upload_class->banned_array = array(""); 
$upload_class->ext_array = array(".zip",".rar",".ace",".tar",".jpg",".gif",".jpeg",".png",".xls",".pdf",".doc",".ppt"); 

$valid_ext = $upload_class->validate_extension(); 
$valid_size = $upload_class->validate_size(); 
$valid_user = $upload_class->validate_user(); 
$max_size = $upload_class->get_max_size(); 
$file_size = $upload_class->get_file_size(); 
$file_exists = $upload_class->existing_file(); 

    if (!$valid_ext) { 
        $result = "The file extension is invalid, please try again!"; 
    } 
    elseif (!$valid_size) { 
        $result = "The file size is invalid, please try again! The maximum file size is: $max_size and your file was: $file_size"; 
    } 
    elseif (!$valid_user) { 
        $result = "You have been banned from uploading to this server."; 
    } 
    elseif ($file_exists) { 
        $result = "This file already exists on the server, please try again."; 
    } else { 
        $upload_file = $upload_class->upload_file_with_validation(); 
        if (!$upload_file) { 
            $result = "Your file could not be uploaded!"; 
        } else { 
            $result = "Your file has been successfully uploaded to the server."; 
        } 
    } 
	echo $result;
?>

This code is working fine, but in line 73 wich is this one
mail($toAddress,$recipientSubject,$mailContent,"From:$row['email']");

I got this error:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/m/a/r/mariocesar/html/qteuploadcode.php on line 73

Thanks


#17 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 25 October 2006 - 04:41 AM

Try:

mail($toAddress,$recipientSubject,$mailContent,"From:{$row['email']}");

#18 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 October 2006 - 10:29 AM

FYI,

It looks as though you've removed the printerror() function I created.  This will cause you problems if your database is ever unavailable.

If you don't want that function in there, then change each instance of this:

printerror($sql, mysql_error());
to this
or die("Can't execute: $sql\n\n" . mysql_error());

Regards
Huggie

Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#19 mariocesar

mariocesar
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 25 October 2006 - 01:33 PM

thanks, I just add{} and is working.
mail($toAddress,$recipientSubject,$mailContent,"From:{$row['email']}");





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users