Page 1 of 2
mailform script, select from the database
Posted: Mon May 29, 2006 4:15 pm
by NAT
Hi,
i want to make a mailfrom script, that selects the email of a user automaticaly from the database and sends mail to a user. This script is usefull for users, where users can send mail to eachother.
Right now i am using a mailto function like this, wich opens automaticaly Outlook Exprees or other Email clients.
Code: Select all
<a href=mailto:$email_p><img src=images/email.jpg border=0></a>
So now i am twaing to make mailform script, wich selects a email adres automaticaly from the database, but i cant, i never made that kind of script.
Can any one explan me wich steps do i have to take to make that script work, so far i made this:
Code: Select all
$msg = "MESSAGE FROM SITE\n";
$msg .= "Sender's Name: $_POST[sender_name]\n";
$msg .= "Sender's E-Mail: $_POST[sender_email]\n";
$msg .= "Message: $_POST[message]\n\n";
$subject = "message from a user";
@mysql_connect(localhost,"zzzzzzz","xxxxxxx");
@mysql_select_db("xxxxxxx") or die( "<CENTER> Couldnt find a database.");
$query = "SELECT * FROM users WHERE email='$email'";
$result = mysql_query($query);
$num = mysql_numrows($result);
if ($num > 0) {
}
//send the mail
mail($to, $subject, $msg, $mailheaders);
But this would not work, couse 100% foult. I just dont know how to make that kind of script, i dont wich code do i have write first.
Posted: Mon May 29, 2006 4:49 pm
by ianhull
Code: Select all
$msg = "MESSAGE FROM SITE\n";
$msg .= "Sender's Name: $_POST[sender_name]\n";
$msg .= "Sender's E-Mail: $_POST[sender_email]\n";
$msg .= "Message: $_POST[message]\n\n";
$subject = "message from a user";
//Add this
$email = $_POST[sender_email];
//You must also say who the email is going to, you have the variable $to but it is currently empty.
// Maybe it should be
$to = $_POST['to'];
@mysql_connect(localhost,"zzzzzzz","xxxxxxx");
@mysql_select_db("xxxxxxx") or die( "<CENTER> Couldnt find a database.");
$query = "SELECT * FROM users WHERE email='$email'";
$result = mysql_query($query);
$num = mysql_numrows($result);
if ($num > 0) {
}
//send the mail
mail($to, $subject, $msg, $mailheaders);
Posted: Wed May 31, 2006 1:22 pm
by NAT
this is not nessasory:
//Add this
$email = $_POST[sender_email];
//You must also say who the email is going to, you have the variable $to but it is currently empty.
// Maybe it should be
$to = $_POST['to'];
my script works white out those lines too.

i need to fiz the query. I want that query selects the email adres of user from the database and then send the email to selected user. Thats the point of the script that trying to write.
But i think the query is wrong:
$query = "SELECT * FROM users WHERE email='$email'";
$result = mysql_query($query);
$num = mysql_numrows($result);
if ($num > 0) {
}
Posted: Wed May 31, 2006 3:14 pm
by ok
There isn't such function called "mysql_numrows"!!! There is a function called mysqli_numrows (
http://il.php.net/manual/en/function.my ... m-rows.php)!!!
You may use this:
Code: Select all
<?php
...
$query_res = mysql_query($query);
$line = -1;
while($results != FALSE)
{
$line++;
$results = mysql_result($query_res, $line);
}
...
?>
Posted: Wed May 31, 2006 4:03 pm
by Christopher
Posted: Wed May 31, 2006 4:10 pm
by ok
Oops... You are right!!! I didn't noticed that...
But you also made a mistake. You wrote "mysql_numrows" instead of "mysql_num_rows"!!!
Posted: Wed May 31, 2006 4:16 pm
by NAT
All my scripts r written with this code,
$result = mysql_query($query);
$num = mysql_numrows($result);
I never had problem with that. The script is not working, it want send any email, and i dont know if the query works .
I want to write a query, that selects a emailadres of a user from the database, en then send to it.
Posted: Thu Jun 01, 2006 1:47 am
by ok
So copy this:
Code: Select all
<?php
\\...
$query = "SELECT `email`, `user` FROM users WHERE `user`='$user";//remember to change `user` into unique!!!
$result = mysql_query($query);
$email = mysql_result($result, 0);
if(!$email)
{
die("Problem!!!");
}
\\...
?>
Posted: Sun Jun 04, 2006 7:43 am
by NAT
i am getting the folowing error:
Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 11 in httpd.www/Test-page/mailform_users2.php on line 56
Problem!!!
this is the line 56:
Code: Select all
$email = mysql_result($result, 0,'email');
I have made enoughf users in DB, but the script cant find any.

Posted: Sun Jun 04, 2006 8:01 am
by ok
I had a syntex error in my last post, copy this and check it again:
Code: Select all
$query = "SELECT `email`, `user` FROM users WHERE `user`='".$user."'";//remember to change `user` into
Posted: Sun Jun 04, 2006 8:09 am
by NAT
i am getting stil the same error with this guery too.
Code: Select all
$query = "SELECT `email`, `name` FROM users WHERE `name`='".$name."'";//remember to change `user` into
By the way i also wrote this query and i ma getting also the same error
Code: Select all
$query = "SELECT * FROM users WHERE name='$name'";
I dont think there is somethink worng with query write now, but entire script
Posted: Sun Jun 04, 2006 8:18 am
by ok
Copy this and see if there are problems:
Code: Select all
mysql_connect(localhost,"zzzzzzz","xxxxxxx") or die(mysql_error());
mysql_select_db("xxxxxxx") or die(mysql_error());
Posted: Sun Jun 04, 2006 8:21 am
by NAT
this is what i have:
Code: Select all
@mysql_connect(localhost,"xxxxxxx","xxxxxxxx");
@mysql_select_db("xxxxxxx") or die( "<CENTER> The database couldnt be found.");
$query = "SELECT * FROM users WHERE name='".$name."'";
$result = mysql_query($query);
$email = mysql_result($result, 0,'email');
if(!$email)
{
die("Probleem!!!");
}
Posted: Sun Jun 04, 2006 8:24 am
by ok
Replace:
Code: Select all
@mysql_connect(localhost,"xxxxxxx","xxxxxxxx");
@mysql_select_db("xxxxxxx") or die( "<CENTER> The database couldnt be found.");
With:
Code: Select all
mysql_connect("localhost","zzzzzzz","xxxxxxx") or die(mysql_error());
mysql_select_db("xxxxxxx") or die(mysql_error());
Posted: Sun Jun 04, 2006 8:30 am
by NAT
done that and stil the same error
Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 11 in