Forum Moderators: coopster
I have made this php but it gives me this 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 '����' at line 1"
Php:
<?php
$con = mysql_connect("#*$!","#*$!","#*$!");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("#*$!", $con);
$sql="SELECT password, email FROM company_profile WHERE name=".$name.;
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
print "no such login in the system. please try again.";
exit();
}
else {
$row=mysql_fetch_array($r);
$password=$row<"password">;
$email=$row<"email">;
$subject="your password";
$header="from:robot@grenzjobber.dk";
$content="your password is ".$password;
mail($email, $subject, $row, $header);
print "An email containing the password has been sent to you";
}
?>
The variable $name is from this submit form:
<form action="/assets/snippets/firma/forgot_pass.php" method="post" name="forgot">
<input name="Login" size="20" type="text" value="name" /><br />
<input name="submit" type="submit" value="submit" />
<input name="reset" type="reset" value="reset" />
</form>
Can Anyone help me tracking down the error?
Thanks in advance
I worked with changing the quotes. I use the texteditor notepad++
But most of the php is copy&paste from various sites (im still very new to php :-) )
Now I get another error
Warning: mail() expects parameter 3 to be string, array given in /home/grenzjob/public_html/assets/snippets/firma/forgot_pass.php on line 41
An email containing the password has been sent to you
Line 41 is:
mail($email, $subject, $row, $header);
Thanks a lot for your help :-)
$row=mysql_fetch_array($r);$password=$row<"password">;
$email=$row<"email">;
$subject="your password";
$header="from:robot@grenzjobber.dk";
$content="your password is ".$password;
mail($email, $subject, $row, $header);
print "An email containing the password has been sent to you";
print "An email containing the password has been sent to you";
>>>>
by:
if(mail($email, $subject, $row, $header))
{
echo"<h3>An email containing the password has been sent to you</h3>";
}
else
{
echo"<h3>sorry, mail problem!</h3>";
}
$content="your password is ".$password;
mail($email, $subject, $content, $header);
Read about mail funtion [php.net]
<edit>added URL</edit>
I think its the link from the form to the php cus if I try to hardcode the name its working perfectly.
$sql="SELECT email, password FROM company_profile WHERE name='$name' ";
The variable $name seems to be the problem.
I found an error in the form but still it doesnt work. The form is now:
<form action="/assets/snippets/firma/forgot_pass.php" method="post" name="forgot">
<input name="name" size="20" type="text" value="name" /><br />
<input name="submit" type="submit" value="submit" />
<input name="reset" type="reset" value="reset" />
</form>
Below where it says $sql="SELECT etc...
add
echo $sql;
are the expected values showing up
if yes copy the output and paste it in phpMyAdmin
then report again
your trouble comes from "borrowing" many multiple pieces
you have the beginning of a script that pretty much works
now that you have a few working pieces
write down your plan
and work at creating by yourself the missing part
give it a try!
I also added this:
echo=$_REQUEST["loginid"];
The output is:
SELECT email, password FROM company_profile WHERE name=''testfirma (mat)An email containing the password has been sent to you
So now the input from the form is sent for sure.
The next thing could the use of the variable. cus it seems like thing goes wrong in this sentence:
WHERE name=''testfirma (mat)
The setup it this:
Page where the user enter username
If username exist=> confirmation page
If username does not exist => error page
The php that gives the error is:
$sql="SELECT email, password FROM company_profile WHERE name='$loginid'";
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
echo "<h2>Det brugernavn du har indtastet eksisterer ikke. Indtast venligst et andet.</h2>";
exit();
ow do I make the ECHO appear on the "error page" ? Right now it just opens a blank page.
The later echo with the "confirmation page" works fine. Although I havent made anything different.
Hope someone can help :-)
you are using
mysql_affected_rows
but a SELECT does not pertain to that function
<<<
Get the number of affected rows by the last INSERT, UPDATE, REPLACE or DELETE query associated with link_identifier .
>>>
instead you could figure out if there is any row corresponding to that username
$r = mysql_query($sql);
$num=mysql_numrows($r); //echo $num;
if ($num == 0)
{
echo your error....
}