Jump to content


Check out our Community Blogs

uniqueideaman

Member Since 12 Oct 2016
Offline Last Active Mar 21 2017 05:17 AM
-----

Topics I've Started

Which Parts Of Php Not To Learn ?

19 March 2017 - 06:43 AM

Guys,
 
After getting putoff from php.net to learn php 7 (because it is not beginner friendly) and raoming around youtube for 1.5mnth to learn php and failing to get proper tutorials there, I returned to php.net. Was reading the CONSTANT chapter and really got pissed-off.
Read this page and tell me if it is a beginner friendly tut or not:
 
<a href="http://php.net/manua...e.constants.php">PHP: Constants - Manual</a>[<a href="http://php.net/manual/en/language.constants.php" target="_blank" title="New Window">^</a>]
 
I find contributor's quarreling in the comments of what works and what not. Obviously, one of them is right and the other wrong. Now, question is, why did php.net put the arguments of the incorrect person in front of us getting us newbies to read quarrels of an incorrect programmer going back and forth with the correct programmer ? Result ? Newbies get confused and put-off from php. Php seems like a neverending mess!
Anyway, I have come to the conclusion not to get my tutorial from there. Can use php.net as a reference in the future once more experienced. And so, heading towards tutoprialspoint.com.
 
This however, just lists the newly added features on php 7 and so no good to me:
 
</a>[<a href="http://www.tutorialspoint.com/php7/" target="_blank" title="New Window">^</a>]
 
And so, I guess you guys would recommend:
 
</a>[<a href="http://www.tutorialspoint.com/php/" target="_blank" title="New Window">^</a>]
 
But, looking at the chapters in their list, which ones (functions, etc.) are deprecated in php 7 so I shouldn't bother with them ? Do you mind pointing-out the chapters and their links from their tutorial ? You can find their chapters on the leftside of their page:
 
<a href="http://www.tutorialspoint.com/php/">PHP Tutorial</a>[<a href="http://www.tutorialspoint.com/php/" target="_blank" title="New Window">^</a>]
 
 
And no, phptherightway.com is not for beginners as it assumes you kno php 5 etc. which I don't.
 
 
Thank You!
 
 
PS - Remember, other newbies would find your contributions here and hopefully give you good rating.
 

Why Is The Closing Bracket Black ?

17 March 2017 - 05:13 PM

Howdy,

On my NotePad++, the line at 116 shows the closing bracket of the ELSE black. Really really puzzling!
I know my code is not neat but I will tidy it up based on the feedback I got so far but in the meanwhile my great mind is filled with the question why the line at 116 shows the closing bracket of the ELSE black.


<html>
<head>
<title>
$user Home Page
</title>
</head>
<body>
<body background=".png">

<?php
session_start();
require "conn.php";

/*Check if user is logged-in or not by checking if session is set or not. 
If user is not logged-in then redirect to login page. Else, show user's account homepage.*/

if(!isset($_SESSION["user"])) 
{
    header("location:login.php");
}
else 
{
    $user = $_SESSION["user"];
    $sql = "SELECT * FROM users WHERE Username = '".$user."'";
    $result = $conn->query($sql);
    while($row = mysqli_fetch_assoc($result)) 
    {
        $db_id = $row["Id"];
        $db_username = $row["Username"];
        $db_forename = $row["Forename"];
        $db_surname = $row["Surname"];
        $db_email = $row["Email"];
        $db_bio = $row["Bio"];
        $db_status = $row["Status"];
    
    
        //Welcome user by name.
        echo "<center>Welcome <b><h2>$db_forename $db_surname!</center>"?></h2></b>|

        <?php
        //Display log-out link.
        echo "<p align='right'><a href='logout.php'>$user Log Out</a>";?>|</p><br>
    
        <form method="post" action="">    
        <div class="form-group">
        <center><label>Post Status To Friends:</label>
        <input type="text" placeholder="Post Status To Friends" name="post_status_to_friends" /></center><br>
        <center><button type="submit" class="btn btn-default" name="post_status_to_friends" />Post Status To Friends!</button></center>
        </div>

        <form method="post" action="">
        <div class="form-group">
        <center><label>Post Status To Public:</label>
        <input type="text" placeholder="Post Status To Public" name="post_status_to_public" /></center><br>
        <center><button type="submit" class="btn btn-default" name="post_status_to_public" />Post Status To Public!</button></center>
        </div>
    
        <?php
        //Post User Status To Friends in $user table.
        
        if  (isset($_POST['post_status_to_friends']))
        {
            $status_to_friends = trim($_POST["post_status_to_friends"]);
            $status_to_friends = mysqli_real_escape_string($conn,$status_to_friends);
        
            $conn->query("UPDATE $user SET Status_To_Friends $status_to_friends WHERE Username = '".$user."'");
            if($conn->query($sql)===TRUE)
            {
                echo "posted status for friends to $user table!";
                $conn->close();
                exit();
            }
            else    
            {
                echo "posting status for friends to $user table failed!";
                $conn->close();
                exit();
            }
    
            //Post User Status To Friends in "users" table.
        
            $conn->query("UPDATE users SET Status_To_Friends $status_to_friends WHERE Username = '".$user."'");
            if($conn->query($sql)===TRUE)
            {
                echo "posted status for friends to users table!";
                $conn->close();
                exit();
            }
            else    
            {
                echo "posting status for friends to users table failed!";
                $conn->close();
                exit();
            }
        
            //Display User Status To Friends. Search for User's data with $user.
            
            $query = "SELECT * FROM $user WHERE Username = '".$user."'";
            $result = mysqli_query($conn,$query);
            $numrows = mysqli_num_rows($result);
            if($numrows = 0)
            {        
                echo "No data!";
                $conn->close();
                exit();
            }
            else 
            {
                while($row = mysqli_fetch_assoc($result)) 
                {      
                    $db_status_to_friends = $row["Status_To_Friends"];
                }
                echo "<br><b>$user Status To Friends:</b><br>
                $db_status_to_friends";?><br>
                <br>
            }
    
        <?php
        //Post User Status To Public in $user table.
    
        if  (isset($_POST['post_status_to_public']))
        {
            $status_to_public = trim($_POST["post_status_to_public"]);
            $status_to_public = mysqli_real_escape_string($conn,$status_to_public);
        
            $conn->query("UPDATE $user SET Status_To_Public $status_to_public WHERE Username = '".$user."'");
            if($conn->query($sql)===TRUE)
            {
                echo "posted status for public to $user table!";
                $conn->close();
                exit();
            }
            else    
            {
                echo "posting status for public to $user table failed!";
                $conn->close();
                exit();
            }
    
            //Post User Status To Public in users table.
            $conn->query("UPDATE users SET Status_To_Public $status_to_public WHERE Username = '".$user."'");
            if($conn->query($sql)===TRUE)
            {
                echo "posted status for public to users table!";
                $conn->close();
                exit();
            }
            else    
            {
                echo "posting status for public to users table failed!";
                $conn->close();
                exit();
            }
    
            //Display User Status To Public. Search for User's data with $user.
            
            $query = "SELECT * FROM $user WHERE Username = '".$user."'";
            $result = mysqli_query($conn,$query);
            $numrows = mysqli_num_rows($result);
            if($numrows = 0)
            {        
                echo "No data!";
                $conn->close();
                exit();
            }
            else 
            {
                while($row = mysqli_fetch_assoc($result)) 
                {      
                    $db_status_to_public = $row["Status_To_Public"];
                }
            echo "<br><b>$user Status To Public:</b><br>
            $db_status_to_public";?><br>
            <br>
            <?php 
            }
        }
        
        //Display User Bio.
        echo "<br><b>Bio:</b><br>";
        echo "$db_bio";?><br>
        <br>
        
        <?php 
        //Display User's Latest View.
        echo "<br><b>Latest View:</b><br>";
        echo "$db_latest_view";?><br>
        <br>

        <?php 
        //Display User's Latest Viewed Url in iFrame.?>
        <iframe src="<?php $db_latest_view;?>"></iframe>
        <?php     
    }
}
?>

</body>
</html>



How To Display In iFrame A Url From Mysql ?

16 March 2017 - 07:38 AM

This is my latest shortened version of the homepage in my reg-login site php.
When you login to your account, your homepage welcomes yuo with your first & surname.
Then it is supposed to show you your bio ($row "bio" in tbl) and show you a url in an iframe ($row "your website" in tbl).
 
Problem is, the iframe is not showing the data (url) that is in the  "your website" in tbl.
I tried escaping, switching to single quote from double but no luck.
What do you think is wrong ?
 
 
<html>
<head>
<title>
$user Home Page
</title>
</head>
<body>
<body background=".png">
 
<?php
session_start();
require "conn.php";
 
/*Check if user is logged-in or not by checking if session is set or not. 
If user is not logged-in then redirect to login page. Else, show user's account homepage.php.*/
 
if(!isset($_SESSION["user"])) 
{
    header("location:login.php");
}
else 
{
    $user = $_SESSION["user"];
    $sql = "SELECT * FROM users WHERE Username = '".$user."'";
    $result = $conn->query($sql);
    while($row = $result->fetch_assoc()) 
{
   $db_id = $row["Id"];
   $db_username = $row["Username"];
   $db_forename = $row["Forename"];
   $db_surname = $row["Surname"];
   $db_email = $row["Email"];
   $db_bio = $row["Bio"];
   $db_your_fav_url = $row["Fav_Url"];
    
 
   //Welcome user by name.
echo "<center>Welcome <b><h2>$db_forename $db_surname!</center>"?></h2></b>|
 
<?php
//Display log-out link.
echo "<p align='right'><a href='logout.php'>$user Log Out</a>";?>|</p><br>
 
        <?php 
//Display User Bio.   
echo "<br><b>Bio:</b><br>
$db_bio";?><br>
<br>
 
<?php 
//Display User's Fav Url in iFrame.?>
<iframe src='$db_your_fav_url'></iframe>
<?php
}
}
?>
 
</body>
</html>
 
 
The "Bio" column shows no data on page even thopugh the column contains data in the db.
I get error:
 
[16-Mar-2017 15:29:44 UTC] PHP Notice:  Undefined index: Your_Fav_Url in /home/sn/public_html/sn/home.php on line 34
 

What On Earth Is This Outlandish Error ?

13 March 2017 - 05:47 PM

Programming Buddies,

Here's my latest script. It is a member reg-login script.
It registers you and gets you to activate your account confirming your email and then auto logs you into your account. It uses cookies to remember your user details. It was working fine until I added the feature for you to make posts to your friends or the public.
I get error:

PHP Parse error: syntax error, unexpected '"', expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home/sn/public_html/sn/home.php on line 168

On many lines, I changed from:

$query = "SELECT * FROM users WHERE Username = '".$user."'";

to:

$query = "SELECT * FROM users WHERE Username = '$user';

but no luck in getting rid of the error. You will see line 168 doesn't have any ".
I use notepad++. Error mssg seems irrelevant.

And so, looking at the error and my script, what do you think the problem is ? Best to c
heck my code on your wamp/xampp to really understand the problem.


Thank You!


PPS - Script in next post.


Which tutorial should I pick out of these (member reg, login site) ?

12 March 2017 - 04:15 AM

Programming Buddies,
 
 
Looking at the following links, can you be kind enough to tell me which one I should learn from and which one teaches what method (mysqli, pdo, etc.) and whether they are on php 7 or 5 because only looking for php 7: