Quantcast
Channel: PHP Freaks: PHP Help
Viewing all 13200 articles
Browse latest View live

Loop Searching The Array For Banned Words A Failure

$
0
0

Folks,

 

Can you figure-out why the following script fails to find the banned words on the page when the banned words are listed in an array ?

<?php
 
/*
ERROR HANDLING
*/
//declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
 
 
// 1). $curl is going to be data type curl resource.
$curl = curl_init();
 
// 2). Set cURL options.
curl_setopt($curl, CURLOPT_URL, 'https://www.buzzfeed.com/mjs538/the-68-words-you-cant-say-on-tv?utm_term=.xlN0R1Go89#.pbdl8dYm3X');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
 
// 3). Run cURL (execute http request).
$result = curl_exec($curl);
$response = curl_getinfo( $curl );
 
if( $response['http_code'] == '200' )
{
    //Set banned words.
    $banned_words = array("Prick","Dick","Fag");
 
    //Separate each words found on the cURL fetched page.
    $word = explode(" ", $result);
    
   //var_dump($word);
 
    for($i = 0; $i <= count($word); $i++){
        foreach ($banned_words as $ban) {
            if (stripos($word[$i],$ban) !== FALSE){
                echo "word: $word[$i]<br />";
                echo "Match: $ban<br>";
            }else{
                echo "word: $word[$i]<br />";
                echo "No Match: $ban<br>";  
            }
        }
    }
}
 
// 4). Close cURL resource.
curl_close($curl);

Remember the banned words exist on the page. And No. It is not because the banned words are not text but imgs as I checked the source code of the page and the banned words do exist as text. Check it out yourself, if you have any doubts.

I hope it is not because this was set to false:

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);

 

Setting it to "true", how-ever, shows a complete blank page. Why ? Must it not be set to "true" since the page is "httpS" anyway!


How To Prevent Downloads With Php?

$
0
0
 
Php Guys,
 
Are you aware of any function or method where I can prevent downloads ?
Imagine a page with a lot of links. Like: links to pages and links to imgs or links to downloads.
Now, imagine I fetched that page with curl and the user is viewing the links present on the page.
 
Q1a. Now, if I were to prevent any downloads from the download links. How would I do it ?
Q1b -. Any php function that manages this prevention ?
Q1b - If not, then any workarounds you can think of ? I'm thinking of str_replacing the download links so they no longer showup as download links but as something else such as nothing.
 
Q2a. How would you get your cURL script to spot a download link and get it to not appear on your user's screen ?
Q2b. Would you get the script to check for the file extension that would reveal if it's a viewable file (html page, img file, etc.) or a downloading file ?
Q2c. What are the long list of download file extensions ?
 
 
When I cURL fetch or build my own web proxy or build my crawler, have to make sure they ignore download links. :)

Drop down with pay periods...

$
0
0

So I would like to do a drop down menu with 4 pay periods this drop down would include the current pay period and 3 previous pay periods.

 

I can calculate dates within a range of days but I need a static starting point so that all the "pay periods" within are always based on that.  Any hints or tricks on doing this?  I usually like to post some code usually to show I am trying but I am at a total loss!!

Basic Array Question

$
0
0

I'm so confused with multidimensional arrays. May I please ask a couple questions?

 
1.) In the json array below, How do I use PHP to echo, for example, the price offered by Susan?
 
I tried things like echo $result["data"][0]["Susan"] to work, but it won't work.
 
2.) Near the top of the array it shows the lowest price is $25.56. How do I get PHP to echo that?
 
Again, I tried echo $result[LowestPrice] but that doesn't work.
 
3.) The array below is really big. What code do I use to create a smaller array of just [Name] and [OfferingPrice] ?? 
 
If I can do that, then I can do the PHP thing where you go "foreach ($result as $var=>$value) { echo "$var...$value" } etc., and I can sort it etc.
 
Here's the array:
 
$result = json_decode($stuff,true);
print_r($result);
 
//this is what it is output
 
Array
(
    [data] => Array
        (
            [Info] => Array
                (
                    [LowestPrice] => 25.56
                    [PlaceOfManufacture] => USA
                )
 
            [OfferingPrice] => Array
                (
                    [0] => Array
                        (
                            [OfferingPrice] => 20.00
                            [SalesAssociate] => Array
                                (
                                    [BadgeNumber] => 125
                                    [Name] => Fred
                                )
 
                        )
 
                    [1] => Array
                        (
                            [OfferingPrice] => 18.36
                            [SalesAssociate] => Array
                                (
                                    [BadgeNumber] => 932
                                    [Name] => Susan
                                )
 
                        )
 
                    [2] => Array
                        (
                            [OfferingPrice] => 2.34
                            [SalesAssociate] => Array
                                (
                                    [BadgeNumber] => 73
                                    [Name] => Grandpa
                                )
 
                        )
 
                    [3] => Array
                        (
                            [OfferingPrice] => 44.28
                            [SalesAssociate] => Array
                                (
                                    [BadgeNumber] => 202
                                    [Name] => Stewart
                                )
 
                           )
 
                )
 
        )
 
)

Can I request a member's bank account info through email?

$
0
0

I have been doing some research and I found out that it's a really really bad idea to store users' sensitive information in a database. 

 

Here's what I am trying to do.

 

1. Request a member's bank account info.

2. Make a direct deposit into their bank account from my bank account. This is done online through my bank's website.

 

My question is, if I can't store the member's bank account info in the database, can I at least request them to send it through an email? From there I can put it in excel sheet offline for storage and use that to make direct bank deposits to their account(s). Or is that illegal? If it is, then what's the best way to do this?

Is there a way to keep from putting URL in a Users history?

$
0
0

My guess is the answer is no, because I'm doing any trailblazing with this site.  However, I'm creating a domestic violence help website, and my client wants me to put a pop up that provides information on how to delete browser history and a quick out off the page.  

 

I'd like to take it one step further and see if it's possible to block the placement of the URL altogether.  Probably not, but I thought I would ask.  

 

Thank you.

 

 

'Guess a number' - pervert version (with hidden fields and arrays)

$
0
0

Hello! I'm rookie.

 

Please help me to solve problem with storing stuff in hidded fields for 'Guess a number' program:
 
https://hastebin.com/vomasuvere.xml
 
Why this...

if ($choice == 'big'){
print $guess[1]=($guess[0] / 2);
} elseif ($choice == 'small') {
print $guess[2]=($guess[0] + 25); 

...doesn't work?

 

p.s.

I know that it's the worst decision to use arrays and hidden fields in such program; but I've made decision to make it like this and can't drop it :) Please help!

 

p.p.s.

This is my live stream, how I made this program - https://www.youtube.com/watch?v=lLQ4J2JkO60 

Can you tell my why this doesn't work?

$
0
0

I had a simple array I was playing with. I wanted to number the output so that it would look like this

 

1. item one

2. item two

3. item three

4. item four

 

and so on.

 

so made a for loop that output my array just fine and tried doing this inside the for loop

$counter = 0; // this is outside the loop

//inside
echo $counter += 1 . '. ' . $myArray[$i] . '<br />';

what that gave me was

 

1234

 

instead of

 

1. item one

2. item two

3. item three

4. item four

 

however, when I separated it like so

echo $counter += 1;
echo '. ' . $myArray[$i] . '<br />';

it works just fine. Why is that?

 


issue in inserting data from dropdown into mysql table

$
0
0
Hi
I am new in PHP. I have used dropdown  to bind with my sql data. It is ok
But I could not insert data into table only from dropdown. Other controls like text can be inserted.
I have given code below. 
Pls advise me.
Maideen
 
<?php require_once '../inc/header.php'; ?>
      <div class="portlet light bordered">
          <div class="portlet-title">
              <div class="caption">
                  <i class="icon-social-dribbble font-green"></i>
                  <span class="caption-subject font-green bold uppercase">Parameter</span>
              </div>
          </div>
         <form class="forget-form" action="../classes/cls.parameter.php" method="POST">
             <div class="portlet-body">
                 <div class="form-group">
                     <label for="default" class="control-label">Parameter Details</label>
                     <input id="default" type="text" class="form-control" placeholder="Parameter Details" name="paramdetails">
                 </div>
                 <div class="form-group">
                     <label for="single" class="control-label">Parameter head</label>
                     <select id="paramhead" class="form-control select2" name="paramhead">
                         <option>-- Select --</option>
                         <?php
                               $sql  = "select * from tbl_paramhead order by paramhead";
                               $stmt   = $pdo->prepare($sql);
                               $stmt->execute();
                                   while ($row = $stmt->fetch())
                                   {
                                     echo '<option value>' .$row['paramhead']. '</option>';
                                   }
                         ?>
                     </select>
                 </div>
             </div>
         <div class="form-actions">
             <button type="submit" class="btn green uppercase btn btn-danger mt-ladda-btn ladda-button" data-style="zoom-out" name="paramhead">Submit</button>
         </div>
     </form>
     </div>
 <?php require_once '../inc/footer.php'; ?>


<?php
  require_once '../inc/config.php';
  if(isset($_POST['paramhead']))
  {
      if($_SERVER["REQUEST_METHOD"] == "POST")
      {
        $paramhead =$_POST['paramhead'];
        $paramdetails =$_POST['paramdetails'];
       $bool = true;
       $sql="insert into tbl_parameter(paramhead,paramdetails) values ('$paramhead','$paramdetails')";
       $stmt=$pdo->prepare($sql);
       $stmt->execute();
       $pdo = null;
       print '<script>alert("Saved");</script>';
       print '<script>window.location.assign("../admin/parameter.php");</script>';
     }
 }
 ?>

php comments news. help

$
0
0

Hello, please link me any tutorial or simply inform me how to do so that it showed comments only on news which had recently been added.

Insering Multple files

$
0
0

I have a code  that takes multiple text fields and 2 file uploads.

First before   people say i need to limit file types and images that i am working on once i get the problems i have now fixed

My issues

1. I am getting an undefined variable on line 31 even though all the names match with my db

2. The files arent uploading to server which i am testing on a private pc

3 I think this has to do  with issue of  the undefined variable problem but I want the  image links to go into the db under chat log and screenshot headings

the php code 

<!DOCTYPE html>
<html>
<body>
<form action="" method="POST" enctype="multipart/form-data">
Your SHG Player Name(required):<input type="text" name="commentfrom" required="required" /></br>
Your Email Address(required):  <input type="text" name="email" required="required" /></br>
Player Or Host this is about: <input type="text" name="about" /></br>
Do you Require a Director to contact you?:<p>
<input type="radio" name="reply" value="yes">Yes  <br/>
<input type="radio" name="reply" value="no">No <br/>
</p>
Please include your comments here:</br><textarea name="comments" rows="10" cols="25"></textarea></br>
Select Chatlog to upload:<input type="file" name="chatlog" id="chatlog"></br>
Select Screenshot to upload:<input type="file" name="screenShot" id="screenShot"></br>
<input type="submit" value="Submit" name="submit">
</form>
</body>
</html>
<?php
if(isset($_POST["submit"])){
$hostname='localhost';
$username='root';
$password='';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=Directors",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
$folder = "upload/";
$chatlog = $folder . basename($_FILES["chatlog"]["name"]);
$screenShot = $folder . basename($_FILES["screenShot"]["name"]);
$sql = "INSERT INTO comments (commentfrom, email, about, reply, comments, chatlog, screenShot  )
VALUES ('".$_POST["commentfrom"]."','".$_POST["email"]."','".$_POST["about"]."','".$_POST["reply"]."','".$_POST["comments"]."','".$_POST["chatlog"]."','".$_POST["screenShot"]."')";
if ($dbh->query($sql)) {
echo "New Record Inserted Successfully'";
}
else{
echo "Data not successfully Inserted.";
}
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
?>
</body>
</html>

Here is the table structure

s_fulltext.png ID commentfrom email about Reply Date Submitted comments chatlog screenshot NNN read Habs Read Directors comments   ID commentfrom  email  about  Reply  Date Submitted  comments  chatlog  screenshot  NNN read Habs Read  Directors comments 

 

email form help

$
0
0

hi there i am trying to creat a contact form but i cant seem to get it to work  every time i try it i get this https://snag.gy/qXMtiW.jpg

 

what i have

the contact form

the php code

an exsisting email

 

what i whant to be able to do

for pepole to fill in there info and for it to be sent to my email address the email i am useing is a gmail

 

if you would like to see the code i have just ask

 

by the way i am hosting the website from my own computer

<<Unknown error>> in PDOException

$
0
0

A MySQL (actually MariaDB) table has a trigger which can throw the following:

SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Object ID must be between 0 and 4,194,302';
When run from the SQL shell with out of range data, it responds with:
ERROR 1644 (45000): Object ID must be between 0 and 4,194,302
When executed with a PDO prepared statement, the PDOException::message is:
"SQLSTATE[45000]: <<Unknown error>>: 1644 Object ID must be between 0 and 4,194,302"

How should one replace <<Unknown error>> with some other content?

 

'Guess a number' - Help with hidden fields and arrays

$
0
0

Hello! I'm rookie.

 

Please help me to solve problem with storing stuff in hidded fields for 'Guess a number' program:
 
https://hastebin.com/vomasuvere.xml
 
Why this...

if ($choice == 'big'){
print $guess[1]=($guess[0] / 2);
} elseif ($choice == 'small') {
print $guess[2]=($guess[0] + 25); 

...doesn't work?

 

p.s.

I know that it's the worst decision to use arrays and hidden fields in such program; but I've made decision to make it like this and can't drop it :) Please help!

 

p.p.s.

This is my live stream, how I made this program - https://www.youtube.com/watch?v=lLQ4J2JkO60 

display data in input text and Option from my sql using php

$
0
0

Hi

 

I could not load data into input text and select option control.

I don't know where i did wrong.

Pls advice  me

Thank you in advence

 

maideen

<?php require_once '../inc/header.php'; ?>

<?php

if($_SERVER["REQUEST_METHOD"] == "GET")
    {
        $id=$_GET['id'];
        $sql ="Select * from tbl_parameter where id ='$id'";
        $stmt = $pdo->prepare($sql);
        $stmt->execute();
            while ($row = $stmt->fetch())
            {
                $paramhead =$row['paramhead'];
                $paramdetails =$row['paramdetails'];
                $id =$row['id'];

            // below is display information in page. It is OK

              echo "id entered is :",$id,"<br>";
              echo "paramHead entered is :",$paramhead,"<br>";
              echo "Param details entered is :",$paramdetails,"<br>";
            }
    }

?>
    <div class="portlet light bordered">
        <div class="portlet-title">
            <div class="caption">
                <i class="icon-social-dribbble font-green"></i>
                <span class="caption-subject font-green bold uppercase">Update Parameter</span>
            </div>
        </div>

        <div class="portlet-body">

                <form  action="../classes/cls.parameter.php" method="POST">
                    <div class="form-group">
                        <label for="default" class="control-label">Parameter Details</label>
                        <input id="paramdetails" type="text" class="form-control" placeholder="Parameter Details" name="paramdetails" values ="<?php echo $paramdetails; ?>" >
                    </div>
                    <div class="form-group">
                        <label for="single" class="control-label">Parameter head</label>
                        <select id="paramhead" name="paramhead" class="form-control select2" >
                            <option>-- Select --</option>
                            <?php
                                  $sql  = "select * from tbl_paramhead order by paramhead";
                                  $stmt = $pdo->prepare($sql);
                                  $stmt->execute();
                                      while ($row = $stmt->fetch())
                                      {
                                        $optvalue = $row['paramhead'];
                                        print '<option value ='.$optvalue.'>' .$row['paramhead']. '</option>';
                                        //echo '<option value ='.$row['paramhead'].'>' .$row['paramhead']. '</option>';
                                      }
                            ?>
                        </select>

                    </div>

                        <div class="form-actions">
                            <button type="submit" class="btn green uppercase btn btn-danger mt-ladda-btn ladda-button" data-style="zoom-out" name="add">Submit</button>
                    </div>
                </form>
        </div>
    </div>


<?php require_once '../inc/footer.php'; ?>




updating database

$
0
0

I am having a hard time updating a entry  rather then me just pasting my whole script ill break it up so you understand where it  is coming from I just don't know where to put 

 <form action="" method="POST" enctype="multipart/form-data"> to include the data from the select box


Step one a simple  echo form to  post all the results of the query  which works perfectly

<html>
<?php
	try {
		$dbh = new PDO("mysql:dbname=directors;host=localhost","root","");
	}catch(PDOException $e) {
		die('Error');
	}

	$tableheader = false;
	$query = "SELECT * FROM `comments` ORDER BY `id` ASC";
	$sth = $dbh->prepare($query);

	if(!$sth->execute()) {
		die('Error');
	}

	echo "<table>";

	while($row = $sth->fetch(PDO::FETCH_ASSOC)) {
		if($tableheader == false) {
			echo '<tr>';
			foreach($row as $key=>$value) {
				echo "<th>{$key}</th>";
			}
			echo '</tr>';
			$tableheader = true;
		}
		echo "<tr>";
		foreach($row as $value) {
			echo "<td>{$value}</td>";
		}
		echo "</tr>";
	}
	echo "</table>";
	?>

Step 2 is to use the info from the database to create a  drop down menu for the id numbers which are listed and this works fine

// To get the id numbers currently in the db to update the records which need to be looked at


<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('directors');

$sql = "SELECT id FROM comments";
$result = mysql_query($sql);

echo "UPDATE RECOED NUMBER" . "<select name='id'>";
while ($row = mysql_fetch_array($result)) {
    echo "<option value='" . $row['id'] ."'>" . $row['id'] ."</option>";
}
echo "</select>";
?>
// rest of form to use to update remaining columns
</br>
NNN Read <input id="NNNread" type="checkbox" value="yes"></br>
Habs Read <input id="HabsRead" type="checkbox"value="yes"></br>
Directors Comments:</br><textarea name="Directorscomments" rows="10" cols="25"></textarea></br>
<input type="submit" value="Submit" name="submit">
</form>
<?php
include("config.php");
if(isset($_POST['submit'])) {
    $Directorscomments = $_POST['Directorscomments'];
    $NNNread = $_POST['NNNread'];
    $HabsRead = $_POST['HabsRead'];
    $id = $_SESSION['id'];
// updating blank entrys  for NNNread and HabsRead  as well as to concat directors comments to one entry

    $sql = "UPDATE comments SET NNNread=:NNNread, HabsRead=:HabsRead, SET Directorscomments = CONCAT(Directorscomments, 'Directorscomments') WHERE id=:id";
    $stmt = $db->prepare($sql);
    $stmt->bindValue(":Directorscomments", $Directorscomments, PDO::PARAM_STR);
	$stmt->bindValue(":NNNread", $NNNread, PDO::PARAM_STR);
    $stmt->bindValue(":HabsRead", $HabsRead, PDO::PARAM_STR);
    $stmt->bindValue(":id", $id, PDO::PARAM_STR);
    $stmt->execute();
}
?>
</select>

</html>

and the bottom part is the rest of the form

 

Why "($_SERVER['REQUEST_METHOD'] == "POST")" Fails To Trigger ?

$
0
0

Php Folks,

 

 

Why is not this working ?

($_SERVER['REQUEST_METHOD'] == "POST")

I get no errors. Error reporting on.

declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

I get the ELSE getting triggered when it should not. This ELSE:

else
{
echo "$_SERVER['REQUEST_METHOD'] == "POST") is not getting triggered !";
exit;
}

Attached Files

Piped email suddenly not working

$
0
0

Ok - this was working earlier today and then after an edit or two I suddenly get this email in response to my piped message:

 

This message was created automatically by mail delivery software.
 
A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:
  pipe to |/home/albany/public_html/homejg/xxx.php
    generated by xxx@jimginer.net
 
The following text was generated during the delivery attempt:
------ pipe to |/home/albany/public_html/homejg/xxx.php
       generated by xxx@jimginer.net ------
 
Exception: Zend Extension /home/albany/public_html/homejg/xxx.php does not exist
 
Reporting-MTA: dns; domain.com
 
Action: failed
Final-Recipient: rfc822;|/home/albany/public_html/homejg/xxx.php
Status: 5.0.0

 

Ok - the piped email goes to the script name mentioned in the messages, which I've replaced with 'xxx'.  Yet the messages tell me the script does not exist, but it does.  I've checked.

 

So what does "Zend Extension" have to do with this and why is it giving me this issue?

Why Html Form Plays Hide & Seek with Php ?

$
0
0

Php Gurus,

 

This is my login.php.

All this time it was working when I place the php code at the top and the html form at the bottom. I made a few changes to the code and suddenly the code does not work unless I drag the html form above the php code. Why is that ?

On the other hand, on the registration.php, I got the php code above the html form and it is working. No problem there. What am I missing here ?

 

This forum has messed up both of my post's code indentations. So, best you check the attachments.

 

1. Html Form above Php Code (working):

 

<?php
 
/*
ERROR HANDLING
*/
declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
 
include 'config.php';
 
// check if user is already logged in
if (is_logged() === true) 
{
//Redirect user to homepage page after 5 seconds.
header("refresh:2;url=home.php");
exit; //Added it so script runs no further if user is logged-in. Mac_Guyver's suggestion.
}
?>
<!DOCTYPE html>
<html>
<head>
<title><?php $site_name?> Member Login Page</title>
  <meta charset="utf-8">
</head>
<body>
<div class = "container">
<form method="post" action="">
<center><h3><?php $site_name ?> Member Login Form</h3></center>
<div class="text-danger">
<div class="form-group">
<center><label>Username/Email:</label>
<input type="text" placeholder="Enter Username" name="login_username_or_email" value="<?php if(isset($_COOKIE["login_username_or_email"])) echo $_COOKIE["login_username_or_email"]; ?>"</center>
</div>
<div class="form-group">
<center><label>Password:</label>
<input type="password" placeholder="Enter password" name="login_password" value="<?php if(isset($_COOKIE["login_password"])) echo $_COOKIE["login_password"]; ?>"></center>
</div>
<div class="form-group">
<center><label>Remember Login Details:</label>
<input type="checkbox" name="login_remember" /></center>
</div>
<div class="form-group">
<center><input type="submit" name="login_submit" value="Login" class="button button-success" /></center>
</div>
<div class="form-group">
<center><font color="red" size="3"><b>Forgot your password ?</b><br><a href="login_password_reset.php">Reset it here!</a></font></center>
<center><font color="red" size="3"><b>Not registered ?</b><br><a href="register.php">Register here!</a></font></center>
</form>
</div>
</body>
</html>
 
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST")
{ 
if (isset($_POST["login_username_or_email"]) && isset($_POST["login_password"]))
{
$username_or_email = trim($_POST["login_username_or_email"]); // I rid the mysqli_real_escape_string based on Mac_Guyver's suggestion.
$password = $_POST["login_password"];
         
//Select Username or Email to check against Mysql DB if they are already registered or not.
$stmt = mysqli_stmt_init($conn);
if($stmt = mysqli_prepare($conn, "SELECT accounts_activations, usernames, emails, passwords FROM users WHERE usernames = ?"))
{
mysqli_stmt_bind_param($stmt, 's', $username_or_email);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt); //Use either this line, or ...
//$result = mysqli_stmt_bind_result($stmt, $db_account_activation_state, $db_username, $db_email, $db_password); // ... this line. But not both.
 
$row = mysqli_fetch_array($result, MYSQLI_ASSOC); 
 
// Check if inputted Username or Email is registered or not.
//Either type following paragraph or the next one but not both. Ask in forum which one is best.
 
// PARAGRAPH 1 
if ($username_or_email == $row['usernames'] || $username_or_email == $row['emails'] && password_verify($password, $row['passwords'])) // either this paragraph or ...
{
echo "Paragraph 1: Please wait while we check your account details ...";
if($row['accounts_activations'] == '0')
{
echo "Paragraph 1: You have not activated your account yet! Check your email for instructions on how to activate it. Check your spam folder if you don't find an email from us.";
exit;
}
}
else
{
echo "Paragraph 1: That Username or Email is not registered!"; 
exit;
} 
 
 
/* PARAGRAPH 2
if ($username_or_email == $db_username || $username_or_email == $row['emails'] && password_verify($password, $db_password)) // ..... this paragraph. But not both.
{
echo "Paragraph 2: Please wait while we check your account details ...";
if($row['accounts_activations'] == '0')
{
echo "Paragraph 2: You have not activated your account yet! Check your email for instructions on how to activate it. Check your spam folder if you don't find an email from us.";
exit;
}
}
else
{
echo "Paragraph 2: That Username or Email is not registered!"; 
exit;
} 
*/
 
//If 'Remember Me' check box is checked then set the cookie. 
if(!empty($_POST["login_remember"])) // Either use this line ....
//if (isset($_POST['login_remember']) && $_post['login_remember'] == "on") // ...or this line. But not both!
{
setcookie("login_username", $username, time()+ (10*365*24*60*60));
}
else
{
//If Cookie is available then use it to auto log user into his/her account!
if (isset($_COOKIE['login_username']))
{
setcookie("login_username","","");
}
if (isset($_COOKIE['login_password'])) //I will remove this later on as it is not safe to save passwords on cookies. Currently, got this on for debugging purpoises.
{
setcookie("login_password", "", "");
}
}
$_SESSION["user"] = $username_or_email;
header("location:home.php?user=$username");
}
else
{
echo "Your account details are incorrect!";
exit;
}
}
else
{
echo "isset else triggered!";
exit;
}
}
else
{
echo "SERVER REQUEST_METHOD is not getting triggered !";
exit;
}
 
echo "Do not forget to click the 'Login' button!";
exit;
?>

Attached Files

Fatal error: Uncaught mysqli_sql_exception:

$
0
0
Folks,
 
I am trying to create a Login sytem where the user can login to his account by either typing his Username or Email and Password. Like you do with your Youtube account.
I get this error:
 
Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM users WHERE usernames = ? OR emails = ? AND passwords = ?' at line 1 in C:\xampp\htdocs\id\login_2.php:32 Stack trace: #0 C:\xampp\htdocs\id\login_2.php(32): mysqli_prepare(Object(mysqli), 'SELECT accounts...') #1 {main} thrown in C:\xampp\htdocs\id\login_2.php on line 32
 
I coded like this:
//Select Username or Email to check against Mysql DB if they are already registered or not.
$stmt = mysqli_stmt_init($conn);
if($stmt = mysqli_prepare($conn, "SELECT accounts_activations, usernames, emails, FROM users WHERE usernames = ? OR emails = ? AND passwords = ?"))
{
mysqli_stmt_bind_param($stmt, 'sss', $username_or_email, $username_or_email, $password);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt); //Use either this line, or ...
//$result = mysqli_stmt_bind_result($stmt, $db_account_activation_state, $db_username, $db_email, $db_password); // ... this line. But not both.
This forum is breaking my indentations.

Attached Files

Viewing all 13200 articles
Browse latest View live