Zaloguj | Zarejestruj | FAQ
Anonymous

PHP Code for retrieve and write data from a table

+ Odpowiedz

Posty: 12 1, 2


PHP Code for retrieve and write data from a table

przez Shanmugalingam » Pn cze 08, 2015 8:11 am

Hi,
I want some php codes to check, the index No in the database, if the index No available again check the registered column to check whether he or she already registered, If not, write to that column "yes" and show his/her details, If that column says yes show a message "You are already registered"
I already created a database with necessary fields. and their is field called status. in that field the program automatically should fill "yes" or a massage like " You are already registered".
Avatar użytkownika

Shanmugalingam

  • Posty: 2
  • Dołączył(a): Śr kwi 08, 2015 6:23 am

Re: PHP Code for retrieve and write data from a table

przez XainPro » Wt cze 09, 2015 1:21 pm

By all of your detail i think you are trying to build a login system
check login system simple tutrial here


http://www.wikihow.com/Create-a-Secure- ... -and-MySQL
Avatar użytkownika

XainPro

  • Posty: 3933
  • Dołączył(a): Pt lut 17, 2012 8:10 pm

Re: PHP Code for retrieve and write data from a table

przez softinx » Pt wrz 25, 2015 11:42 am

Thanks for asking the nice question. I also faced the same problem because at that time I was preparing for my job interview so I go the solution
Kod: Zaznacz cały
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();
?>
from http://www.w3schools.com/php/php_mysql_select.asp
For best interview questions of php with answer I got the help and crack my interview..Hope it will help you also https://intellipaat.com/interview-question/php-interview-questions/
Avatar użytkownika

softinx

  • Posty: 1
  • Dołączył(a): Pt wrz 25, 2015 11:33 am

Re: PHP Code for retrieve and write data from a table

przez tekclasses » Wt gru 27, 2016 11:43 am

Kod: Zaznacz cały
<?php
$connect=mysql_connect('localhost', 'root', 'password');

mysql_select_db("name");
//here u select the data you want to retrieve from the db

$query="select * from tablename";

$result= mysql_query($query);

//here you check to see if any data has been found and you define the width of the table

If($result){

echo "<table width ='340' align='left'>
      <tr color ='#5D9951>";
$i=0;

    If(mysql_num_rows($result)>0)
    {
         //here you fetch the data from the database and print it in the respective columns   
        while($i<mysql_num_fields($result))
        {   
             echo "<th>".mysql_field_name($result, $i)."</th>";
             $i++;
        }
        echo "</tr>";

        $color=1;

        while($rows=mysql_fetch_array($result, MYSQL_ASSOC))
        {   
            If ($color==1){
                echo "<tr color='#'#cccccc'>";

                foreach ($rows as $data){
                    echo "<td align='center'>".$data. "</td>";
                }

                $color=2;
            }
            $color=1;
        }
     } else {
        echo"no results found";
        echo "</table>";
    } else {
        echo "error running query:".MYSQL_error();
}
?>


For More Info https://goo.gl/Qgg02u
Avatar użytkownika

tekclasses

  • Posty: 1
  • Dołączył(a): Wt gru 27, 2016 11:37 am

Re: PHP Code for retrieve and write data from a table

przez vinket » So mar 02, 2019 9:57 am

hi,
good for asking the nice question. I also faced the same problem because at that time I was preparing for my job interview so I go the solution

$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>

I got this from https://www.w3schools.com/php/php_mysql_select.asp
and also help me from other links also to learn more from the best source
https://nipurnkvch.blogspot.com/2019/01/reasons-to-join-best-php-training-in.html
Avatar użytkownika

vinket

  • Posty: 1
  • Dołączył(a): So mar 02, 2019 9:49 am

Re: PHP Code for retrieve and write data from a table

przez horeakaii » Pn maja 06, 2019 11:48 am

How I wish I could post something useful for this issue. I have just learnt linking codes and simple commands. This is interesting! Hope you could also view our site http://rdmedicalproducts.com. Thanks and more power!
Avatar użytkownika

horeakaii

  • Posty: 19
  • Dołączył(a): Pn kwi 29, 2019 1:19 pm

Re: PHP Code for retrieve and write data from a table

przez casseverhart13 » Śr cze 12, 2019 7:15 am

Cheers favorable on the proficient information. Clearly fair-minded when up! Do you have more sources for us? our site
Avatar użytkownika

casseverhart13

  • Posty: 48
  • Dołączył(a): Wt kwi 23, 2019 4:22 am

Re: PHP Code for retrieve and write data from a table

przez casseverhart13 » Cz cze 13, 2019 10:24 am

I just added this web site to my feed reader, excellent stuff.... Your posted an important as mine.... click here
Avatar użytkownika

casseverhart13

  • Posty: 48
  • Dołączył(a): Wt kwi 23, 2019 4:22 am

Re: PHP Code for retrieve and write data from a table

przez samuelddarden » Wt cze 18, 2019 11:37 pm

Thanks for this informative content. It’s really good. Actually, I want to share some thoughts. candy crush
Avatar użytkownika

samuelddarden

  • Posty: 24
  • Dołączył(a): Wt cze 18, 2019 11:35 pm

Re: PHP Code for retrieve and write data from a table

przez Aryanm » Pn cze 24, 2019 5:45 pm

Thanks for all Codes posted. It's really helpful for me. Keep it up!
Aryan - plumber woodbridge va
Avatar użytkownika

Aryanm

  • Posty: 3
  • Dołączył(a): Cz cze 06, 2019 1:00 pm


+ Odpowiedz

1, 2