Hello i want learn PHP could you please help me?
so here is a problem
i connected to database everything works if i use
echo "name: " . $row[“name”]; it shows name somewhere else but i want it show
name in html text
like
here php text
i tried do like $name = ‘name’
but it just show name not that text what is in my database
i dont even know why i use $row[“name”] i tried put it there but didn’t work
can someone explain me please?
I’m sure there are other ways as well, but those are the two I mostly have use. I just added the extra HTML to show the examples more clearly. HTH John
P.S. I never short tag, example:
[php]<?= $name; ?>[/php] for there might be a server that the code is put on that it won’t work, then it’s going to be a pain to go back and change the code.
Well i still need help i am beginner in php but i know programming and other languages i know how stuff works
but i need know how make them
i use this
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "names";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT name FROM name";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "name: " . $row["name"];
}
} else {
echo "0 results";
}
$conn->close();
?>
it is working like in echo but i need to show it down in html code i tried put
<?php $row["name"] ?>
but didn't work then i saw in other script
that they used like <?php echo $_SESSION['name'];?> but for me dont work
ye i know programming kind of other language and i know how system is working
but i need to know what these SESSION things mean etc..
i already connected to db selected my tables and got my text in $row why row ? i dont know saw in
tutorial but anyway i need to get like this
i connect to db
somehow define that $name = get name from db
and then in html part just put it <?php $name ?> if someone could help would be Great
but Thank You for that previous thing
Yea not gonna lie im copying and dont understand what it mean but latter i am trying to figure out how that works i just need few good examples
I know it is not the best way how to learn but i have already learned few programming languages like that
and trying to do same thing with php
I know it is not the best way how to learn but i have already learned few programming languages like that
and trying to do same thing with php
Obviously, you haven’t learned that way. echo is a print statement used just like it is in Python, Bash, Java, and a host of others. When it is encountered, it immediately prints the variable.
If you want to print the statement somewhere else, you need to tell it to print where you want it to, as in Striders examples.