Have you executed this query in the mysql client or phpmyadmin
diafol commented: Deprecated. Why do these people insist on using MySQL functions? +15
Have you executed this query in the mysql client or phpmyadmin
From the discussion, your question is not all that clear. But if you want the value of $v, I'm afraid you are already having it when you used
echo '<br>value =>'.$v;
So if you want something else, can you kindly elucidate your question.
If you are a person who learns best by text the codeacademy or w3schools can help. But if you learn best by video, then I recommend the video playlist on phpacademy channel on youtube.
I don't get you very well can you please explain it further and can you please edit your question (full of mistakes, sorry)
.
Thanks cereal it after what you told me it wasn't the codes which were wrong but the server configuration. Thanks for your time.
I have corrected my smtp with some other credentials. My status is 200 but no json response is sent back to the front end
Okay Cereal, thank you very much for your help. I will contact my Tech Lead to clarify my codes.
Do I need to configure something in xampp when I'm still using PHPMailer
Now this is what I got
SMTP -> ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.(10060)
<br />The following From address failed: gideon.a@scopicsoftware.com : Called Mail() without being connected
{"error":"Mail Not Sent"}
Cereal, the same but now the succeess message is replaced with the error message.
Thanks Cereal, very very much. But it response is both an error and a success.
This is the response
Could not instantiate mail function.
{"success":true}
Could you brief me about that
I'm building an API and on the aspect of sending a mail. I'm getting mail not sent error. In my API, the front-end sends a JSON request consisting of the mail parameters.
{
"to":"gideonappoh@gmail.com",
"subject":"Testing Reviewer's Page",
"body": "Hello Gideon",
"headers":"oksana.v@scopicsoftware.com"
}
I then decode them and pass them through a PHPMail method in my controller. But its not working, and I can't find whats wrong. Can someone help me. These are my codes.
public function actionSendMail() {
//Getting request from frontend
$request = file_get_contents('php://input');
//Decoding input into an array
$input = json_decode($request, true);
//Validating request
if (is_null($input)) {
$response = json_encode(['error' => 'Bad Input']);
die($response);
} else {
//mail parameters
$to = $input['to'];
$subject = $input['subject'];
$body = $input['body'];
$headers = $input['headers'];
//Sending mail
if(!$this->sendMail($to, $subject, $body, $headers)) {
$response = json_encode(['error' => 'Mail Not Sent']);
die($response);
} else {
$response = json_encode(['success' => true]);
echo $response;
}
}
}
private function sendMail ($to, $subject, $body, $headers) {
//Configurating PHP Mailer
$mail = new PHPMailer();
$mail->Host = 'stmp.emailsrvr.com';
$mail->Username = 'gideon.a@scopicsoftware.com';
$mail->Password = '*******';
$mail->Mailer = 'stmp';
$mail->Port = 25;
$mail->SMTPAuth = true;
//Sending mail
$mail->SetFrom($headers);
$mail->Subject = $subject;
$mail->IsHTML(true);
$mail->Body = $body;
$mail->AddAddress($to, "");
return $mail->Send();
}
I have read many articles on configuring xampp and I think I should work but still not working. Always getting the response { "error":"Mail not sent" }
Thanks for your help.
@Stephano, the logic I'm referring to here is not anything special than your conditions specified in the if and switch statements.
For instance,
Normally, you will say if (username_is_unique && password_is_correct)
then login or else do something else (which is usually the error message). So, provided that your database connection is correct and also there is no fault with your sql then check those conditions.
I hope it helped.
@Stephano, from what you are saying it means that every thing is okay with the database connection. If so, then can you check your logic well. Sometimes it happens when dealing with especially logical operators.
Yh I agree with andrevanzuydam, some people has very long names (both first and last ones). So 100 chars will be okay. But one thing I can add is that, if you know the hashing method you will use on the passwords, set the password length to the hash length.
Example
md5() gives 32 chars
hash('sha256') gives 64 chars
I hope it helped.
Your question is not all that understandable but the little knowledge I have is that you are trying to filter the results returned from a search field.
My suggestion is that you can make this asynchronously with AJAX. But if you have tried something post your codes so that we might help.
@mattster, its not that I'm encouraging the mysql database connection layer but I don't know whether he has the basics of the mysqli database layer. And surprisely you just jumped to OOP mysqli for someone who codes in procedual and deprecated mysql.
I think he should learn the foundamentals first with procedual and then switch to OOP.(Personal Preference)
Hello Mohammed, the only flaws I see in your codes are you are using mysql PHP database connection layer which is deprecated. I recommend you to use mysqli or PDO database connection layer. Also your codes are not escaped which makes it very open to sql injection.
Now coming to your question, you are saying its a login system but there is no session set. After successful login you can set a session with the value of the user id (which should be a unique field in the database).
Example
<?php
session_start();
//including database connection file
include "connect.php";
//if form is submitted
if (isset($_POST['submit'])) {
//validating that input fields are not empty (also escaping them).
if (!empty($_POST['username']) && !empty($_POST['passwordname'])) {
//setting variables
$email = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['passwordname']);
//querying the database
$sql = "SELECT * FROM users WHERE email='{$email}' AND password='{$password}'";
$query = mysql_query( $query);
//rows returned
$count = mysql_num_rows($query);
//if there is no user return invalid
if ($count == 0) {
echo "invalid";
//user must be only one so need for >0
} else if ( $count == 1) {
//fetching user data
$results = mysql_fetch_array($result);
//setting session with user id
$_SESSION['user'] = $results['id'];
//redirecting user to direct.php.
header("location:direct.php");
}
}
}
?>
Sorry for making few changes in your variable names, but hope it helped.
@zagga, the file is only stored in the temporary location on the server so unless you give it a permanent location is not uploaded yet.
Hello Mohammed, helping people is the job of a forum, but you need to show us your efforts first. With your codes we will help you find your way out of the concerned problem.
@showman, If I were in your shoes, to think of security and flexibility, I will upload the file to my server for the first instance, then when the verification of the initial form data has returned true. I will just link to the uploaded file as an attachment to the email.
Yes, I agree with diafol. When selecting user data based on the condition of the username (i.e. WHERE username = ?), provided the username is not a unique field you can have multiple rows returned. So is always advisable that at the login page, after a successful login, a user id is stored as a session. Thus retrieving user info will be just a simple sql statement with id being used as the filter.
But If you can show your codes. (About the retrieving) And we can help.
Good luck
Yh, your question does not justify the error you are having right now. You said PDO but the error is in mysqli. Also you are not querying the database for the $result1
instead fetching the array of a string.
Can you show the codes for the connection.
Thanks, diafol and cereal, but that being said are my skills good enough for that position (being junior web developer).
Does it produce the same error
are you trying to insert into the database with the select statement or ...?
I am a 19 year old guy who is yet to get a CS degree from the university. I learned web development on my own from resources online. Mostly from youtube videos precisely from thenewboston and phpacademy and a few text-based tutorials from w3schools.com.
I am good with HTML, HTML5, CSS3. I am also good with procedual and function PHP. But by the way I am very cool with OOP in PHP. I don't know much about JS but I know how to do some few AJAX calls to dynamically query my database and show results in my apps. I am very proficient in SQL statements and using MySQL as my RDBMS. I sometimes use already built JQuery functions to implement sliders and carousels in a few of my projects. I don't know any PHP Framework yet I like building my own and also I have fair knowledge in MVC Frameworks.
My problem is with my skills above can I apply for a junior web developer position. It's like a fear to be intimidated by co-workers that I'm a novice or something like that.
Thanks for your comments.
I am a 19 year old guy who is yet to get a CS degree from the university. I learned web development on my own from resources online. Mostly from youtube videos precisely from thenewboston and phpacademy and a few text-based tutorials from w3schools.com.
I am good with HTML, HTML5, CSS3. I am also good with procedual and function PHP. But by the way I am very cool with OOP in PHP. I don't know much about JS but I know how to do some few AJAX calls to dynamically query my database and show results in my apps. I am very proficient in SQL statements and using MySQL as my RDBMS. I sometimes use already built JQuery functions to implement sliders and carousels in a few of my projects. I don't know any PHP Framework yet I like building my own and also I have fair knowledge in MVC Frameworks.
My problem is with my skills above can I apply for a junior web developer position. It's like a fear to be intimidated by co-workers that I'm a novice or something like that.
Thanks for your comments.
Yh. At least show us what you got so that we might help.
@tobyITguy, I agree with pritaeas. There was no string represent $email_message
so the first one must not be concatenated.
$q = "SELECT user_id, fname, user_level FROM members WHERE (email='$e' AND psword=SHA1('$p'))";
Why don't you hash psword separately and try again.
so$psword = SHA1($p);
before
$q = "SELECT user_id, fname, user_level FROM members WHERE (email='$e' AND psword=$psword";
What is the real error you are having? and If not a real error echo your sessions out and see whether they are working.
Maybe you are reharshing the password from the database. Can you show the codes performing the hashing and verification.
Try this Mike.
$subUsername = trim($_POST["user"]);
$sql = "SELECT userID, username, password FROM user WHERE username = :user";
$q = $conn->prepare($sql);
$q->bindParam(':user', $subUsername);
$q->execute();
$result = $q->fetchAll(PDO::FETCH_ASSOC);
print_r($result);
echo "</p>";
print_r($subUsername);
echo "</p>";
print_r($subPassword);?>
You were adding a parenthesis to the Param and aslo you did not use the right argument for the fetch(). Its
`fetch(PDO::FETCH_ASSOC)` NOT `fetch(PDO::FETCHASSOC`)
Yes I agree with pritaeas, using mysql keywords as raw text renders your sql statement invalid. For my personal preference I usually like using column names nested in back ticks. Try this.
$decline = $dbh->prepare("UPDATE users SET `status` = ? WHERE `name` = ?, `username` = ?, `email` = ?, `phone` = ?");
You are welcome, but don't forget to mark it as solved.
You are welcome, don't forget to mark discussion as solved.
I agree perfectly with pritaeas. I will advice you to go and learn the basis of php and programming. But since you are a beginner, I thought of refreshing myself with your problem. I have commented it very well for you to understand. Try it and I hope it solved your problem.
<?php
//this is the set of numbers
$numbers = 1432;
//getting the number of characters(length) of the set of numbers
$num_length = strlen($numbers);
//Will be using substr so setting the offset to zero
$i = 0;
//intialising the sum variable.
$sum = 0;
//executing the loop
while ($i < $num_length) {
//adding up numbers till the last one
$sum += substr($numbers, $i, 1);
//incrementing $i(offset) each time the a number is added
$i++;
}
//outputting the total results.
echo $sum;
?>
In your question you said, in the console this appears : Uncaught SyntaxError: missing ) after argument list page.php:64
, but the codes you have posted ends on line 52. Can you please show all your codes?
@Trabelsi, I should not be talking for everyone but it seems you have not specified the exact problem you are having. Please specify the exact difficulty you are having. It's like you just posting your codes but there's no question. We are all willing to help one way or the other if the question is clear.
I think you have an issue with the uploads. try changing this
$csvFile1 = $_FILES["file1"];
to
$csvFile1 = $_FILES["file1"]["tmp_name"];
Justin_14, this is a setting in php.ini file. If you have controll of the php.ini file, change memory limit form 64M or 32M to 128M(Maximum Limit).
If not try overriding the php.ini configurations with you .htaccess file in you public folder. Use this instead
php_memory_value_limit 128M
Thanks diafol and pritaes.
thanks pritaeas, but thinking of what diafol said, its true though. Many job requirements include at least one php framework.
So how can i study all these frameworks or is it okay to study one. If yes please recommend that one for me to start learning.
Thanks diafol, but can i create my own framework.
Hello everyone, it seems that most often many projects or let me say jobs requires PHP frameworks. But I have not used a framework before and I love coding in the actual php OOP syntax. Is it necessary to use a framework for a project?
I think the <<<abc abc in the $str is causing the error. Please use this
$str = "Account is created click on the activation link <a href=\"http://abc.com/active.php?$link\">Click</a>";
@jollydd, you sql is not working because you are running php codes in it.
Follow pritaes tutorial and run that sql in phpMyadmin. By the way mysql is deprecated try to use PDO or Mysqli
Please mysql is deprecated, try to get used to mysqli or PDO.