Jump to content

Archived

This topic is now archived and is closed to further replies.

mariocesar

Can not get e-mail info from login system

Recommended Posts

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
[code]<? 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.";

?>[/code]

thanks,

Share this post


Link to post
Share on other sites
Don't nest your functions, it looks untidy and is harder to trap errors, try this:

[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("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";
}
?>[/code]

Regards
Huggie

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
see any problems here ? --> [color=blue]if ([/color][color=red]![/color][color=blue]$logged_in_user){ echo "You are login as, ".$logged_in_user.".";[/color]

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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
seems you are using single quotes around the col-names in your query

wrong: SELECT FROM [color=red]'[/color]tablename[color=red]'[/color] WHERE [color=red]'[/color]colname[color=red]'[/color] = '$something'

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

works: [color=blue]SELECT FROM tablename WHERE colname = '$something'[/color]

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
here is the code:
[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";
}
?>[/code]

Share this post


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

$sql = [color=red]"[/color]SELECT * FROM userregister WHERE name = '$logged_in_user'[color=red]"[/color];

Share this post


Link to post
Share on other sites
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:
[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";
}
?>[/code]

Share this post


Link to post
Share on other sites
Well, the message is clear - No database selected

[code]

<?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!

?>

[/code]

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

Share this post


Link to post
Share on other sites
here this one is working but don't pull the e-mail info from the dbase

[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
  $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";
}
?>[/code]

Share this post


Link to post
Share on other sites
change
$result['email']
to
$row['email']
as
$row=mysql_fetch_array($result)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Thanks for everything Alpine, here is what I'm talking about:

[code]<?
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;
?>[/code]

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

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

Share this post


Link to post
Share on other sites
Try:

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

Share this post


Link to post
Share on other sites
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:

[code=php:0]printerror($sql, mysql_error());[/code] to this [code=php:0]or die("Can't execute: $sql\n\n" . mysql_error());
[/code]

Regards
Huggie

Share this post


Link to post
Share on other sites
thanks, I just add{} and is working.
[code]mail($toAddress,$recipientSubject,$mailContent,"From:{$row['email']}");[/code]

Share this post


Link to post
Share on other sites

×

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.