Get up to 80 % extra points for free! More info:

Discussion: help me out

Activities
Avatar
lawrence njoroge:3/15/2017 16:00

errors look like
"Notice: Undefined variable: first in C:\xampp\htdoc­s\PhpProject2\da­tain.php on line 4

Notice: Undefined variable: last in C:\xampp\htdoc­s\PhpProject2\da­tain.php on line 4

Notice: Undefined variable: nickname in C:\xampp\htdoc­s\PhpProject2\da­tain.php on line 4

Notice: Undefined variable: email in C:\xampp\htdoc­s\PhpProject2\da­tain.php on line 4

Notice: Undefined variable: salary in C:\xampp\htdoc­s\PhpProject2\da­tain.php on line 4

Notice: Undefined variable: result in C:\xampp\htdoc­s\PhpProject2\da­tain.php on line 4

Notice: Undefined variable: sql in C:\xampp\htdoc­s\PhpProject2\da­tain.php on line 4
information entered succesifully. "
idex.php

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title>Learning</title>
    </head>
    <body>
        <?php
        $db = mysql_connect("localhost", "root", "");
mysql_select_db("learnerdb",$db);
$result = mysql_query("SELECT * FROM personnel",$db);
if($result === FALSE) {
    die(mysql_error()); // TODO: better error handling
}
echo "<TABLE border=1>";
echo"<TR><TD><B>Full Name</B><TD><B>Email</B><TD><B>Nick Name</B><TD><B>Salary</B></TR>";
while ($myrow = mysql_fetch_array($result))
{
echo "<TR><TD>";
echo $myrow["firstname"];
echo " ";
echo $myrow["lastname"];
echo "<TD>";
echo $myrow["email"];
echo "<TD>";
echo $myrow["nick"];
echo "<TD>";
echo $myrow["salary"];
}
echo "</TABLE>";
        ?>
        <a href="form.php"> Add data</a>
    </body>
</html>

form.php
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title>form</title>
    </head>
    <body>
        <form method="post" action="datain.php">
First name:<input type="Text" name="first"><br>
Last name:<input type="Text" name="last"><br>
Nick Name:<input type="Text" name="nickname"><br>
E-mail:<input type="Text" name="email"><br>
Salary:<input type="Text" name="salary"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
    </body>
</html>

datain.php
<?php
$db = mysql_connect("localhost", "root","");
mysql_select_db("learnerdb",$db);
$sql = "INSERT INTO personnel (firstname, lastname, nick, email, salary) VALUES ('$first','$last','$nickname','$email','$salary','$$result = mysql_query($sql)'";
echo "information entered succesifully. \n";

isuue is with the update to the data base

Reply
3/15/2017 16:00
where there is will there is a way
Avatar
Replies to lawrence njoroge
David Capka Hartinger:3/15/2017 16:22

There are so many mistakes in the code, it also uses very dangerous and obsolete techniques. Some functions you're using even aren't a part of the lastest versions of the PHP language anymore. Why don't you learn from our free database course? Just visit https://www.ict.social/php/database and see how to do this correctly.

Up Reply
3/15/2017 16:22
You can walk through a storm and feel the wind but you know you are not the wind.
Avatar
Replies to David Capka Hartinger
lawrence njoroge:3/16/2017 4:41

well i tried that but the db.php file is complicated i can't understand it

Up Reply
3/16/2017 4:41
where there is will there is a way
Avatar
Replies to lawrence njoroge
David Capka Hartinger:3/16/2017 5:55

From the article:

As you can see there is almost no way to work with databases in PHP without objects. However, what you can do is use a wrapper. Basically, someone wrapped the object-oriented functions in the PDO driver for you in a way that you can understand them. In other words, you will be able to use them even if you have no clue what an object actually is. This is the approach we are going to use in this course.

PHP functions are complicated inside as well and you use them. Just use it as a part of the language. There is currently no way to work with databases in PHP efficiently without a wrapper.

Up Reply
3/16/2017 5:55
You can walk through a storm and feel the wind but you know you are not the wind.
To maintain the quality of discussion, we only allow registered members to comment. Sign in. If you're new, Sign up, it's free.

4 messages from 4 displayed.