Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Apr 2014
    Location
    Memphis, Tennessee
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Retrieving data from the database

    Hello everybody,

    I'm wondering if anybody could help me out real quick. I need to make a page that will let me type in the First name and last name that is stored in a database and basically have the database show the phone number that is associated with that first and last name.

    Code:
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Online Application</title>
    <script type = "text/javaScript">
    function validateForm()
    {
    var x=document.forms["capstone"]["firstname"].value;
    if (x==null || x=="")
      {
      alert("First name must be filled out.");
      return false;
      }
    var x=document.forms["capstone"]["lastname"].value;
    if (x==null || x=="")
      {
      alert("Last name must be filled out.");
      return false;
      }
    var x = Number(document.forms["capstone"]["year"].value) || 0;
    if ((x <1900) || (x >2014)) {
    alert ("Year between 1900 and 2014 must be filled in the following format: YYYY");
    return false;
    }
    var x=document.forms["capstone"]["street"].value;
    if (x==null || x=="")
      {
      alert("Street must be filled out.");
      return false;
      }
    var x=document.forms["capstone"]["city"].value;
    if (x==null || x=="")
      {
      alert("City must be filled out.");
      return false;
      }
    var x=document.forms["capstone"]["state"].value;
    if (x==null || x=="")
      {
      alert("State must be filled out.");
      return false;
      }
    var x=document.forms["capstone"]["zip"].value;
    if (x==null || x=="")
      {
      alert("Zip must be filled out.");
      return false;
      }
    var x=document.forms["capstone"]["phone"].value;
    if (x==null || x=="")
      {
      alert("You must input your phone number.");
      return false;
      } 
    var phonechk = /^[0-9]{3}[-]{1}[0-9]{3}[-]{1}[0-9]{4}$/;
    	if (document.getElementById("phone").value.match(phonechk))
    	{ 
    		return true; 
    	} else {
    		alert("Enter the phone number in proper form: XXX-XXX-XXXX");
    		return false;
    	}	
    }
    
    </script>
    <style type="text/css">
    fieldset {
    	width: 800px;
    	margin-top: 20px;
    	border: 1px solid #d6d6d6;
    	background-color: #ffffff;
    	line-height: 1.6em;
    	}
    input[type="text"] {
    	width: 120px;
    	border: 1px solid #d6d6d6;
    	padding: 2px;
    	outline: none;
    	}
    input[type="text"]:focus,
    input[type="text"]:hover {
    	background-color: #d0e2f0;
    	border: 1px solid #999999;
    	}
    input[type="submit"] {
    	border: 1px solid #006633;
    	background-color: #9900FF;
    	color: #ffffff;
    	border-radius: 5px;
    	padding: 5px;
    	margin-top: 10px;
    	}
    input[type="submit"]:hover {
    	border: 1px solid #006633;
    	background-color: #000000;
    	color: #ffffff;
    	cursor: pointer;
    	}
    .title {
    	float: left;
    	width: 230px;
    	clear: left;
    	}
    .submit {
    	width: 310px;
    	text-align: right;
    	}
    </style>
    </head>
    
    <body>
    <h1> Instruction for Application - Academic Year 2014-2015</h1>
    <ol>
    <li>The deadline for 2014-2015 scholarship application is March 30, 2014.</li>
    <li>All fields with asterik (*) sign must be filled out.</li>
    </ol><br />
    
    <form name="capstone" action="2ndstep.php" method="post" onsubmit="return validateForm()">
    
    <fieldset>
    <legend>
    Personal Information
    </legend>
    
    
    <label class="title" for="firstname">*First Name:</label>
    <input type="text" name="firstname" id="firstname"><br />
    <label class="title" for="lastname">*Last name:</label>
    <input type="text" name="lastname" id="lastname"><br />
    <span class="title">*Select your gender:</span> 
    <label><input type="radio" name="sex" value="male" checked/>Male</label>
    <label><input type="radio" name="sex" value="female" />Female</label><br />
    
    <label class="title" for="birthday">*Select your date of birth:</label>
    <select name="month" id="month">
    <option value="January">January</option>
    <option value="February">February</option>
    <option value="March">March</option>
    <option value="April">April</option>
    <option value="May">May</option>
    <option value="June">June</option>
    <option value="July">July</option>
    <option value="August">August</option>
    <option value="September">September</option>
    <option value="October">October</option>
    <option value="November">November</option>
    <option value="December">December</option>
    </select>
    <select name="day" id="day">
    <option value="1.">1</option>
    <option value="2.">2</option>
    <option value="3.">3</option>
    <option value="4.">4</option>
    <option value="5.">5</option>
    <option value="6.">6</option>
    <option value="7.">7</option>
    <option value="8.">8</option>
    <option value="9.">9</option>
    <option value="10.">10</option>
    <option value="11.">11</option>
    <option value="12.">12</option>
    <option value="13.">13</option>
    <option value="14.">14</option>
    <option value="15.">15</option>
    <option value="16.">16</option>
    <option value="17.">17</option>
    <option value="18.">18</option>
    <option value="19.">19</option>
    <option value="20.">20</option>
    <option value="21.">21</option>
    <option value="22.">22</option>
    <option value="23.">23</option>
    <option value="24.">24</option>
    <option value="25.">25</option>
    <option value="26.">26</option>
    <option value="27.">27</option>
    <option value="28.">28</option>
    <option value="29.">29</option>
    <option value="30.">30</option>
    <option value="31.">31</option>
    </select>
    <input type="text" name="year" id="year"><br />
    <label class="title" for="street">*Street:</label>
    <input type="text" name="street" id="street"><br />
    <label class="title" for="city">*City:</label>
    <input type="text" name="city" id="city"><br />
    <label class="title" for="state">*State:</label>
    <input type="text" name="state" id="state"><br />
    <label class="title" for="zip">*Zip:</label>
    <input type="text" name="zip" id="zip"><br />
    <label class="title" for="phone">*Phone number:</label>
    <input type="text" name="phone" id="phone"><br />
    <label for="major" class="title">*Intended major:</label>
    <select name="major" id="major">
    <option value="Information Technology">Information Technology</option>
    <option value="Computer Science">Computer Science</option>
    </select><br />
    <label class="title" for="ssn">Social Security Number: </label>
    <input type="text" name="ssn" id="ssn"><br />
    </fieldset>
    <div class="submit"><input type="submit" value="Next Page" /></div>
    </form>
    
    </body>
    </html>
    PHP Code:
    <?php
       setcookie
    ("firstname"$_POST["firstname"], time()+60*60*24*365);
       
    setcookie("lastname"$_POST["lastname"], time()+60*60*24*365);
       
    setcookie("sex"$_POST["sex"], time()+60*60*24*365);
       
    setcookie("month"$_POST["month"], time()+60*60*24*365);
       
    setcookie("day"$_POST["day"], time()+60*60*24*365);
       
    setcookie("year"$_POST["year"], time()+60*60*24*365);
       
    setcookie("lastname"$_POST["lastname"], time()+60*60*24*365);
       
    setcookie("street"$_POST["street"], time()+60*60*24*365);
       
    setcookie("city"$_POST["city"], time()+60*60*24*365);
       
    setcookie("state"$_POST["state"], time()+60*60*24*365);
       
    setcookie("zip"$_POST["zip"], time()+60*60*24*365);
       
    setcookie("phone"$_POST["phone"], time()+60*60*24*365);
       
    setcookie("major"$_POST["major"], time()+60*60*24*365);
       
    setcookie("ssn"$_POST["ssn"], time()+60*60*24*365);
    ?>
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Online Application</title>
    <script type = "text/javaScript">
    function validateForm()
    {
    var x=document.forms["capstone2.1"]["highschool"].value;
    if (x==null || x=="")
      {
      alert("High school attended must be filled out.");
      return false;
      }
    var x=document.forms["capstone2.1"]["graddate"].value;
    if (x==null || x=="")
      {
      alert("Graduation date must be filled out.");
      return false;
      }
    var x=document.forms["capstone2.1"]["gpa"].value;
    if (x==null || x=="")
      {
      alert("GPA must be filled out.");
      return false;
      }
    }
    </script>
    <style type="text/css">
    fieldset {
        width: 800px;
        margin-top: 20px;
        border: 1px solid #d6d6d6;
        background-color: #ffffff;
        line-height: 1.6em;}
    input[type="text"] {
        width: 120px;
        border: 1px solid #d6d6d6;
        padding: 2px;
        outline: none;}
    input[type="text"]:focus,
    input[type="text"]:hover {
        background-color: #d0e2f0;
        border: 1px solid #999999;}
    input[type="submit"] {
        border: 1px solid #006633;
        background-color: #9900FF;
        color: #ffffff;
        border-radius: 5px;
        padding: 5px;
        margin-top: 10px;
    }
    input[type="submit"]:hover {
        border: 1px solid #006633;
        background-color: #000000;
        color: #ffffff;
        cursor: pointer;
    }
    .title {
        float: left;
        width: 250px;
        clear: left;}
    .submit {
        width: 310px;
        text-align: right;}
    input[type="button"] {
        border: 1px solid #006633;
        background-color: #9900FF;
        color: #ffffff;
        border-radius: 5px;
        padding: 5px;
        margin-top: 10px;
    }
    input[type="button"]:hover {
        border: 1px solid #006633;
        background-color: #000000;
        color: #ffffff;
        cursor: pointer;
    }
    .button {
        width: 310px;
        text-align: right;}
    </style>
    </head>

    <body>
    <h1> High School Information</h1>

    <p> Enter your information about your high school</p> 


    <form name="capstone2.1" action="3rdstep.php" method="post" onsubmit="return validateForm()">
    <fieldset>
    <legend>
    High School Information
    </legend>

    <label class="title" for="highschool">*High School attended: </label>
    <input type="text" name="highschool" id="highschool"><br />
    <label class="title" for="graddate">*Graduation Date: </label>
    <input type="text" name="graddate" id="graddate"><br />
    <label class="title" for="gpa">*GPA: </label>
    <input type="text" name="gpa" id="gpa"><br />
    <label class="title" for="rank">Ranking in graduating class (%):</label>
    <input type="text" name="rank" id="rank"><br />
    </fieldset>
    <div class="submit">
      <input type="submit" value="Next Page" />
      <input type="button" value="Back" onClick="history.go(-1);return true;" />
     </div>

    </form>
    </body>
    </html>
    PHP Code:
    <?php
       setcookie
    ("highschool"$_POST["highschool"], time()+60*60*24*365);
       
    setcookie("graddate"$_POST["graddate"], time()+60*60*24*365);
       
    setcookie("gpa"$_POST["gpa"], time()+60*60*24*365);
       
    setcookie("rank"$_POST["rank"], time()+60*60*24*365);
       
    ?>
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Online Application</title>
    <style type="text/css">
    fieldset {
        width: 800px;
        margin-top: 20px;
        border: 1px solid #d6d6d6;
        background-color: #ffffff;
        line-height: 1.6em;}
    input[type="text"] {
        width: 120px;
        border: 1px solid #d6d6d6;
        padding: 2px;
        outline: none;}
    input[type="text"]:focus,
    input[type="text"]:hover {
        background-color: #d0e2f0;
        border: 1px solid #999999;}
    input[type="submit"] {
        border: 1px solid #006633;
        background-color: #9900FF;
        color: #ffffff;
        border-radius: 5px;
        padding: 5px;
        margin-top: 10px;
    }
    input[type="submit"]:hover {
        border: 1px solid #006633;
        background-color: #000000;
        color: #ffffff;
        cursor: pointer;
    }
    .title {
        float: left;
        width: 328px;
        clear: left;}
    .submit {
        width: 310px;
        text-align: right;}
    input[type="button"] {
        border: 1px solid #006633;
        background-color: #9900FF;
        color: #ffffff;
        border-radius: 5px;
        padding: 5px;
        margin-top: 10px;
    }
    input[type="button"]:hover {
        border: 1px solid #006633;
        background-color: #000000;
        color: #ffffff;
        cursor: pointer;
    }
    .button {
        width: 310px;
        text-align: right;}
    </style>
    </head>

    <body>
    <h1> Previously Attended College </h1>

    <p> Enter previously attended colleges if any </p>

    <form name="capstone2.2" action="confirmation.php" method="post">
    <fieldset>
    <legend>
    College Information
    </legend>
    <label class="title" for="college1"> Previous college attended: </label>
    <input type="text" name="college1" id="college1"><br />
    <label class="title" for="college2"> Previous college attended: </label>
    <input type="text" name="college2" id="college2"><br />
    <label class="title" for="college3"> Previous college attended: </label>
    <input type="text" name="college3" id="college3"><br />
    <label class="title" for="collegeyear"> Year last attended: </label>
    <input type="text" name="collegeyear" id="collegeyear"><br />
    <label class="title" for"credits"> Number of credits earned: </label>
    <input type="text" name="credits" id="credits"><br />

    <label class="text" for="classification">*Classification entering The LeMoyne-Owen College: </label>
    <select name="classification" id="classification">
    <option value="Freshmen">Freshmen</option>
    <option value="Sophomore">Sophomore</option>
    <option value="Junior">Junior</option>
    <option value="Senior">Senior</option>
    </select>
    </fieldset>
    <div class="submit">
        <input type="submit" value="Complete" />
        <input type="button" value="Back" onClick="history.go(-1);return true;" />
    </div>

    </form>
    </body>
    </html>
    PHP Code:
    <html>
    <?php
    $dsn 
    "mysql:dbname=jpopovic";
    $username "jpopovic";
    $password "******";

    try {
      
    $conn = new PDO$dsn$username$password );
      
    $conn->setAttributePDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION );
    } catch ( 
    PDOException $e ) {
      echo 
    "Connection failed: " $e->getMessage();
    }

    $firstname $_COOKIE[firstname];
    $lastname $_COOKIE[lastname];
    $sex $_COOKIE[sex];
    $month "$_COOKIE[month] $_COOKIE[day] $_COOKIE[year]";
    $street $_COOKIE[street];
    $city $_COOKIE[city];
    $state $_COOKIE[state];
    $zip $_COOKIE[zip];
    $phone $_COOKIE[phone];
    $major $_COOKIE[major];
    $ssn $_COOKIE[ssn];
    $highschool $_COOKIE[highschool];
    $graddate $_COOKIE[graddate];
    $gpa $_COOKIE[gpa];
    $rank $_COOKIE[rank];
    $college1 $_COOKIE[college1];
    $college2 $_COOKIE[college2];
    $college3 $_COOKIE[college3];
    $collegeyear $_COOKIE[collegeyear];
    $credits $_COOKIE[credits];
    $classification $_COOKIE[classification];

    if (
    $qry $conn->prepare("INSERT INTO onlineapp (firstname, lastname, sex, birthday, street, city, state, zip, phone, major, ssn, highschool, graddate, gpa, rank, college1, college2, college3, collegeyear, credits, classification) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"))
    {
        if (
    $qry->execute(array($firstname$lastname$sex$month$street$city$state$zip$phone$major$ssn$highschool$graddate$gpa$rank$college1$college2$college3$collegeyear$credits$classification)))
        {echo 
    "Your record was added into our database";}
        else
        {
            
    $err $qry->errorInfo();
            die(
    $err[2]);
        }
    }  
    ?>
    <body>
    </body>
    </html>
    PHP Code:
    <?php
       setcookie
    ("college1"$_POST["college1"], time()+60*60*24*365);
       
    setcookie("college2"$_POST["college2"], time()+60*60*24*365);
       
    setcookie("college3"$_POST["college3"], time()+60*60*24*365);
       
    setcookie("collegeyear"$_POST["collegeyear"], time()+60*60*24*365);
       
    setcookie("credits"$_POST["credits"], time()+60*60*24*365);
       
    setcookie("classification"$_POST["classification"], time()+60*60*24*365);
    ?>
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Entered Data</title>
    <style>
    table, tr, td     {
        border: 1px solid #d6d6d6;
        background-color: #ffffff;
        line-height: 1.6em;
        width:30%;
        padding: 5px;
                    }
    .right     {
        text-align: left;
            }
    .left     {
        text-align: left;
        margin-left: 1em;
              }
    input[type="submit"] {
        border: 1px solid #006633;
        background-color: #9900FF;
        color: #ffffff;
        border-radius: 5px;
        padding: 5px;
        margin-top: 10px;
        }
    input[type="submit"]:hover {
        border: 1px solid #006633;
        background-color: #000000;
        color: #ffffff;
        cursor: pointer;
        }
    input[type="button"] {
        border: 1px solid #006633;
        background-color: #9900FF;
        color: #ffffff;
        border-radius: 5px;
        padding: 5px;
        margin-top: 10px;
        }
    input[type="button"]:hover {
        border: 1px solid #006633;
        background-color: #000000;
        color: #ffffff;
        cursor: pointer;
        }

    </style>
    </head>
    <body>
    <form name="capstone2.3" action="insert.php" method="post">
    <fieldset>
    <legend>Entered data</legend>
    <table>
      <tr>
        <td class="left">First name</td>
        <td class="right"><?php echo $_COOKIE["firstname"?></td>
      </tr>
      <tr>
        <td class="left">Last name</td>
        <td class="right"><?php echo $_COOKIE["lastname"?></td>
      </tr>
      <tr>
        <td class="left">Gender</td>
        <td class="right"><?php if($_COOKIE["sex"] == "female")
                                echo 
    "Female";
                                else
                                echo 
    "Male";?></td>
      </tr>
      <tr>
        <td class="left">D.O.B.</td>
        <td class="right"><?php echo $_COOKIE["month"] ; echo $_COOKIE["day"]; echo $_COOKIE["year"?></td>
      </tr>
      <tr>
        <td class="left">Street</td>
        <td class="right"><?php echo $_COOKIE["street"?></td>
      </tr>
      <tr>
        <td class="left">City</td>
        <td class="right"><?php echo $_COOKIE["city"?></td>
      </tr>
      <tr>
        <td class="left">State</td>
        <td class="right"><?php echo $_COOKIE["state"?></td>
      </tr>
      <tr>
        <td class="left">Zip</td>
        <td class="right"><?php echo $_COOKIE["zip"?></td>
      </tr>
      <tr>
        <td class="left">Phone</td>
        <td class="right"><?php echo $_COOKIE["phone"?></td>
      </tr>
      <tr>
        <td class="left">Major</td>
        <td class="right"><?php echo $_COOKIE["major"?></td>
      </tr>
      <tr>
        <td class="left">SSN</td>
        <td class="right"><?php echo $_COOKIE["ssn"?></td>
      </tr>
      <tr>
        <td class="left">High School</td>
        <td class="right"><?php echo $_COOKIE["highschool"?></td>
      </tr>
      <tr>
        <td class="left">Graduation Date</td>
        <td class="right"><?php echo $_COOKIE["graddate"?></td>
      </tr>
      <tr>
        <td class="left">GPA</td>
        <td class="right"><?php echo $_COOKIE["gpa"?></td>
      </tr>
      <tr>
        <td class="left">Rank</td>
        <td class="right"><?php echo $_COOKIE["rank"?></td>
      </tr>
      <tr>
        <td class="left">Previous College</td>
        <td class="right"><?php echo $_POST["college1"]; ?></td>
      </tr>
      <tr>
        <td class="left">Previous College</td>
        <td class="right"><?php echo $_POST["college2"]; ?></td>
      </tr>
      <tr>
        <td class="left">Previous College</td>
        <td class="right"><?php echo $_POST["college3"]; ?></td>
      </tr>
      <tr>
        <td class="left">Year last attended</td>
        <td class="right"><?php echo $_POST["collegeyear"]; ?></td>
      </tr>
      <tr>
        <td class="left">Number of credits earned</td>
        <td class="right"><?php echo $_POST["credits"]; ?></td>
      </tr>
      <tr>
        <td class="left">Classification</td>
        <td class="right"><?php echo $_POST["classification"]; ?></td>
      </tr>
    </table>
    </fieldset>
    <div class="submit">
        <input type="submit" value="Complete" />
        <input type="button" value="Back" onClick="history.go(-1);return true;" />
    </div>
    </form>
    </body>
    </html>
    This is the code I have!

  • #2
    Regular Coder Linux_Sage's Avatar
    Join Date
    Mar 2014
    Location
    Sterling,VA
    Posts
    106
    Thanks
    0
    Thanked 10 Times in 10 Posts
    Any encoutering any errors? What's the problem?

  • #3
    New Coder
    Join Date
    Apr 2014
    Location
    Memphis, Tennessee
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Nah everything works perfectly! I need to make a new page that will request entrance of First Name and Last Name and if that first name and last name exists in the database it will "spit out" the phone number associated with that record and if there isn't it should tell record with that first and last name does not exist.

    I'm just confused how to go about it.

  • #4
    New Coder
    Join Date
    Apr 2014
    Location
    Memphis, Tennessee
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I might have worded my request wrong. This is what I'm trying to do.

    I want to make a page that will be a form. It will require user to enter First and Last name. When he/she clicks the submit button it will display the phone numbers in database that match the first and last name they have entered. If there is no entry in database with that first and last name it will just display the message that there are is no such person in the database.

  • #5
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,877
    Thanks
    2
    Thanked 164 Times in 159 Posts
    It sounds like you have a good grasp on what you want to accomplish. Now all you have to do is start writing the code and if/when you get stuck, post your code, any/all errors/warnings that it generates and a specific question on the part that's giving you trouble.

  • #6
    New Coder
    Join Date
    Apr 2014
    Location
    Memphis, Tennessee
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I've got it to work, only thing that befuddled me was that I was trying to do everything in one file lol. Here are my codes:

    Code:
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Phone Number</title>
    <script type = "text/javaScript">
    function validateForm()
    {
    var x=document.forms["phone"]["firstname"].value;
    if (x==null || x=="")
      {
      alert("First name must be filled out.");
      return false;
      }
    var x=document.forms["phone"]["lastname"].value;
    if (x==null || x=="")
      {
      alert("Last name must be filled out.");
      return false;
      }
    }
    </script>
    <style type="text/css">
    h1 {
    	font-size:26px;
    }
    
    h2 {
    	font-size:22px;
    }
    
    fieldset {
    	width: 800px;
    	margin-top: 20px;
    	border: 1px solid #d6d6d6;
    	background-color: #ffffff;
    	line-height: 1.6em;
    	}
    input[type="text"] {
    	width: 120px;
    	border: 1px solid #d6d6d6;
    	padding: 2px;
    	outline: none;
    	}
    input[type="text"]:focus,
    input[type="text"]:hover {
    	background-color: #d0e2f0;
    	border: 1px solid #999999;
    	}
    input[type="submit"] {
    	border: 1px solid #006633;
    	background-color: #9900FF;
    	color: #ffffff;
    	border-radius: 5px;
    	padding: 5px;
    	margin-top: 10px;
    	}
    input[type="submit"]:hover {
    	border: 1px solid #006633;
    	background-color: #000000;
    	color: #ffffff;
    	cursor: pointer;
    	}
    .title {
    	float: left;
    	width: 130px;
    	clear: left;
    	}
    .submit {
    	width: 200px;
    	text-align: right;
    	}
    </style>
    </head>
    
    <body>
    
    <h1>Do you need an applicants phone number?</h1>
    <h2>Enter his/hers first name</h2>
    
    <form name="phone" action="phone.php" method="post" onsubmit="return validateForm()">
    <fieldset>
    
    <label class="title" for="firstname">First Name:</label>
    <input type="text" name="firstname" id="firstname"><br />
    <label class="title" for="lastname">Last Name:</label>
    <input type="text" name="lastname" id="lastname"><br />
    </fieldset>
    <div class="submit"><input type="submit" value="Submit" /></div>
    </form>
    
    </body>
    </html>
    And PHP:

    PHP Code:
    <html>
    <?php
    // Connection data (server_address, database, name, poassword)
    $dsn "mysql:dbname=jpopovic";
    $username "jpopovic";
    $password "*****";

    try {
      
    // Connect and create the PDO object
      
    $conn = new PDO$dsn$username$password );
      
    $conn->exec("SET CHARACTER SET utf8");      // Sets encoding UTF-8

    $fname $_POST["firstname"];
    $lname $_POST["lastname"];
      
      
    // Define and perform the SQL query
      
    $sql "SELECT `phone` FROM `onlineapp` WHERE firstname = '$fname' AND lastname = '$lname' ";
      
    $result $conn->query($sql);

      
    // If the SQL query is succesfully performed ($result not false)
      
    if($result !== false) {
        
    // Create the beginning of HTML table, and the first row with colums title
        
    $html_table '<table border="1" cellspacing="1" cellpadding="1"><tr><th>First Name</th><th>Last Name</th><th>Phone</th></tr>';

        
    // Parse the result set, and adds each row and colums in HTML table
        
    foreach($result as $row) {
          
    $html_table .= '<tr><td>' .$fname'</td><td>' .$lname'</td><td>' .$row['phone']. '</td></tr>';
        }
      }

      
    $conn null;        // Disconnect

      
    $html_table .= '</table>';           // ends the HTML table

      
    echo $html_table;        // display the HTML table
    }
    catch(
    PDOException $e) {
      echo 
    $e->getMessage();
    }
    ?>
    <head>
    <style>
    table, tr, td     {
        border: 1px solid #d6d6d6;
        background-color: #ffffff;
        line-height: 1.6em;
        width:20%;
        padding: 5px;
        text-align:center;
                    }
    .right     {
        text-align: left;
            }
    .left     {
        text-align: left;
        margin-left: 1em;
              }
    </style>
    </head>
    </html>

  • #7
    New Coder
    Join Date
    Apr 2014
    Location
    Memphis, Tennessee
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Only thing that I'm missing now is the if statement that will echo a statement: No such record in our database in case the first and last name doesn't match to a database entry.

  • #8
    New to the CF scene
    Join Date
    Apr 2014
    Location
    Belgium
    Posts
    7
    Thanks
    0
    Thanked 1 Time in 1 Post
    if name and firstname are found do this else do that

    PHP Code:
    if (condition) {
      
    code to be executed if condition is true;
    } else {
      
    code to be executed if condition is false;


  • #9
    New Coder
    Join Date
    Apr 2014
    Location
    Memphis, Tennessee
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I'm pretty sure I know the concept of if statement... Thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •