Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im following Kristian Guevara great PHP Tutorial (Step-by-Step PHP Tutorials for Beginners - Creating your PHP Program FROM SCRATCH: Basic Authentication, Membership and CRUD Functionalities[^])

I have managed to solve several issues on the code related to deprecated functions and all that by myself (ie mysql vs mysqli). I have also been able to add includes and functions.
Yet im stucked at edit.php on this line:

Im not being able to get pass through that "if" and im not sure what $def means asi it has not been declared previously and it doesnt seem to be taking the value from the url as that should and is done later with $_GET

Can someone enlighten me?

        <title>My first PHP Website</title>
    session_start();       //starts the session
    if($_SESSION['user']){ // checks if the user is logged in  
        header('location: index.php'); // redirects if user is not logged in
    $user = $_SESSION['user']; //assigns user value
        <h2>Home Page</h2>
        <p>Hello <?php Print "$user"?>!</p> 
        <a href="logout.php">Click here to go logout</a><br/><br/>
        <a href="home.php">Return to home page</a>
        <h2 align="center">Currently Selected</h2>
        <table border="1px" width="100%">
			    <th>Post Time</th>
			    <th>Edit Time</th>
			    <th>Public Post</th>
				$id_exists = false;
					$id_exists = true;
					$con = getDBConnection();
                    $id = $_GET['id'];
                    $_SESSION['id'] = $id;
					$query = mysqli_query($con,"Select * from list");
                    $count = mysqli_num_rows($query);
					Print '<h2 align="center">There are ' . $count . 'rows';
					if($count > 0)
                       while($row = mysqli_fetch_array($query))
							Print "<tr>";
			                Print '<td align="center">' . $row['id'] . "</td>";
                            Print '<td align="center">' . $row['details'] . "</td>";
			                Print '<td align="center">' . $row['date_posted'] . " - " . $row['time_posted']."</td>";
			                Print '<td align="center">' . $row['date_edited'] . " - " . $row['time_edited']."</td>";
			                Print '<td align="center">' . $row['public'] . "</td>";
		                    Print "</tr>";
						$id_exists = false;
        Print '
        <form action="edit.php" method="post">
            Enter new detail: <input type="text" name="details"/><br/> 
            public post? <input type="checkbox name="public[]" value="yes"/><br/> 
            <input type="submit" value="Update List"/> 
            Print '<h2 align="center">There is not data to be edited.</h2>';

Thank you.

What I have tried:

If I remove
this code, it seems to work perfectly fine.
But im not one of those who cuts code without understanding its purpose
Updated 4-Mar-21 9:46am
Richard MacCutchan 3-Mar-21 12:06pm    
I assume that $def is an array that is being tested to see if it contains an item named 'id'. However, you would get the actual answer by asking the writer of the tutorial.
W Balboos, GHB 3-Mar-21 13:12pm    
When you say it 'Im not being able to get pass through that "if" ', do you get an error message? I'd imagine it could say something like 'undefined index' or undefined for $def, itself? You've got to describe the error.

You could try print_r($def) and, if it's defined, it'll show you all of the members of $def array. If it's not defined then it will give an error of its own.
Cristian Angel Bruner 3-Mar-21 13:37pm    
No, i mean that it never gets TRUE and the code is the one above, so there is no other place where it can be defined. So maybe im right when im saying that there is an error there and that $def is null, therefore its always false condition
W Balboos, GHB 3-Mar-21 14:29pm    
Well - it certainly wouldn't be the first posted code to have an error. Or maybe you're missing something?

OK - I don't know what the page is all about but suppose that $def['id'] is supposed to be $_SESSION['id']? Where would it get any $def values from, anyway?
Cristian Angel Bruner 3-Mar-21 15:16pm    
I totally agree. It just seems an error on the code. Im trying to contact the author but as mentioned... i dont like modifying things without understanding. Just wanted to know if I was missing anything

1 solution

You need to download the author's code; there are some discrepancies in the article.

The line in question is actually:

GitHub - kristianguevara/MyFirstWebsite: The finished product for the PHP tutorials for Beginners[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900