www.webdeveloper.com
Results 1 to 15 of 15

Thread: unable to fix/locate error in php

  1. #1
    Join Date
    Oct 2012
    Posts
    36

    unable to fix/locate error in php

    the following link is what is displayed when i run it http://omgtechnotes.me.pn/insert.php

    I have removed the user name and password for security reasons

    but i cant figure out what the issue is


    PHP Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <img src="http://omgtechhelp.com/wp/wp-content/themes/OMGTech/images/logo7small.jpg" />
    <center>
    <h1><u>Notes For The Month Of August</u></h1>
    </center>
      <a href="http://www.omgtechnotes.me.pn/index.html">
       <input type="button" value="New Entry" />
    </a>
    <body>
    <?php
    //Protect against mysql_injection
     
    $customername mysql_real_escape_string(trim($_POST["customername"]));
    $phonenumber mysql_real_escape_string(trim($_POST["pnumber"]));
    $email mysql_real_escape_string(trim($_POST["eaddy"]));
    $issue mysql_real_escape_string(trim($_POST["issue"]));
    $result mysql_real_escape_string(trim($_POST["results"]));
    $date mysql_real_escape_string(trim($_POST["Date"]));
     
     
    //Now check form input(Validating the form).
    $errmsg_arr = array(); //Array to store validation errors
    $check_Error false//Validation error flag
     
    if (empty($customername)){
    $errmsg_arr[]= '.Please Enter Your Name';
     
    $check_Error true;
    }
    if (empty(
    $phonenumber)){
    $errmsg_arr[]= '.Please Enter Your Phone Number';
     
    $check_Error true;
    }
    if (empty(
    $email)){
    $errmsg_arr[]= '.Please Enter Your Email';
     
    $check_Error true;
    }
    if (empty(
    $issue)){
    $errmsg_arr[]= '.Please what is your issue';
     
    $check_Error true;
    }
    if (empty(
    $result)){
    $errmsg_arr[]= '.Please what is your issue';
     
    $check_Error true;
    }
      if (empty(
    $date)){
    $errmsg_arr[]= '.Please what is your issue';
     
    $check_Error true;
    }
    //Printing out any error message stored in the array.
    if ($check_Error == true){
      echo 
    '<h1>ERROR: </h1><h3>Please check below for Error Details</h3>';
     
      if( isset(
    $errmsg_arr) && is_array($errmsg_arr) && count($errmsg_arr) > ) {
          echo 
    '<ul><font color="red">';
          foreach(
    $errmsg_arr as $msg) {
            echo 
    '<li><b>Error: &nbsp;&nbsp;&nbsp;'.$msg.'</b></li><br />';
           }
             echo 
    '</font></ul>';
       }
          
    //Please change the a href link to the name of your page.
      
    echo "<p><a href='http://www.omgtechnotes.me.pn/index.html'>Go Back To Register</a></p>";
    }
    //After validating successfully
    else {
    /* Now we will write a query to insert user details into database */
    $host "fdb5.freehostingeu.com"// Host name...change it to your configuration information.
    $username ""// Mysql username...change it to your configuration information.
    $password ""// Mysql password...change it to your configuration information.
    $db_name "usernote"// Database name...change it to your configuration information.
    // Connect to server
    mysql_connect("$host""$username""$password") or die('ERROR: Cannot connect' .mysql_error());
    //connect to database
    mysql_select_db("$db_name") or die ('ERROR: Cannot connect'.mysql_error());
     
    $tbl_name "UserNote";  //Mysql Table name...change it to your configuration information.
     
    $sql="INSERT INTO $tbl_name (CustomerName, Phone, Email, Issue, Result, Date)
            VALUES('
    $customername', '$phonenumber', '$email',  '$issue', '$result', '$date')";
    }
    if (!
    mysql_query($sql)) //notice the "!" it means if the mysql_query($sql)  cannot be executed, then die error. ELSE execute the mysql_querry($sql) to
                                            //insert into table in the database.
    {   
    die(
    'Error in Registration,: ' mysql_error());
    }
    else
    {    
    //Insert User into the database.
    }
    ?>
    <hr/>
        <table border="1">
     
        <tr>
        <th align="center">DATE</th>
        <th align="center">NAME </th>
        <th align="center">EMAIL </th>
        <th align="center">PHONE </th>
        <th align="center">ISSUE </th>
        <th align="center">RESULT </th>
        </tr>
    <?php
     $result
    =mysql_query("SELECT * FROM $tbl_name");  //sql query to call all the record available in database
     
    if ($result) {
      while (
    $fetch mysql_fetch_assoc($result)) {
      
    //Using the WHILE - LOOP TO Display the whole recode in tabular form.
      
    echo '<tr>';
      echo 
    '<td>'.$fetch['Date'] .'</td>';
      echo 
    '<td>'.$fetch['CustomerName'] .'</td>';
      echo 
    '<td>'.$fetch['Email'] .'</td>';
      echo 
    '<td>'.$fetch['Phone'] .'</td>';
      echo 
    '<td>'.$fetch['Issue'] .'</td>';
      echo 
    '<td>'.$fetch['Result'] .'</td>';
      echo 
    '</tr>';
      }
     }
     else {
      die (
    "ERROR: Could not fetch record : ".mysql_error());
     }
    ?>
     
     </table>
    </body>
    </html>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    You have to do a successful mysql_connect() before you can use mysql_real_escape_string().

    (Of course, the "better" solution would be to stop using the deprecated MySQL extension, and instead either use MySQLi or PDO, and then make use of prepared statements and bound parameters instead of manually escaping user inputs. )
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Oct 2012
    Posts
    36
    is there any chance you can kindly show me how to do the successful mysql_connect(), i have my database working, and i've been up for hours and i just can't think straight i would greatly appreciate it in a huge way

  4. #4
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,206
    Basically you are trying to use a MYSQL function before your database has been opened, so you need to move the mysql_connect( and associated elements moved to the top of the pile before the mysql_real_escape_string() functions are used.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  5. #5
    Join Date
    Oct 2012
    Posts
    36
    So are you saying move this section above

    PHP Code:
    mysql_connect("$host""$username""$password") or die('ERROR: Cannot connect' .mysql_error()); 
    //connect to database 
    mysql_select_db("$db_name") or die ('ERROR: Cannot connect'.mysql_error()); 
      
    $tbl_name "UserNote";  //Mysql Table name...change it to your configuration information. 
      
    $sql="INSERT INTO $tbl_name (CustomerName, Phone, Email, Issue, Result, Date) 
            VALUES('
    $customername', '$phonenumber', '$email',  '$issue', '$result', '$date')"

    if (!
    mysql_query($sql)) //notice the "!" it means if the mysql_query($sql)  cannot be executed, then die error. ELSE execute the mysql_querry($sql) to 
                                            //insert into table in the database. 
    {    
    die(
    'Error in Registration,: ' mysql_error()); 

    else 
    {    
    //Insert User into the database. 

    ?> 

    this section?

    PHP Code:
    //Protect against mysql_injection 
      
    $customername mysql_real_escape_string(trim($_POST["customername"])); 
    $phonenumber mysql_real_escape_string(trim($_POST["pnumber"])); 
    $email mysql_real_escape_string(trim($_POST["eaddy"])); 
    $issue mysql_real_escape_string(trim($_POST["issue"])); 
    $result mysql_real_escape_string(trim($_POST["results"])); 
    $date mysql_real_escape_string(trim($_POST["Date"])); 

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,206
    You have to have an open database before you can use any of the mysql functions

    So the bit where you connect to the database and associated conection information like username, etc has to be at the beginning of your script before you call the mysql function that you use to prepare for your sanitizing.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  7. #7
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,206
    That is an affirmative to your post BTW.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  8. #8
    Join Date
    Oct 2012
    Posts
    36
    okay so i have this as my updated code


    now i'm getting the following error

    "Parse error: syntax error, unexpected T_ELSE in /srv/disk9/1487284/www/omgtechnotes.me.pn/insert.php on line 17"

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <img src="http://omgtechhelp.com/wp/wp-content/themes/OMGTech/images/logo7small.jpg" />
    <center>
    <h1><u>Notes For The Month Of August</u></h1>
    </center>
      <a href="http://omgtechnotes.me.pn/index.html">
       <input type="button" value="New Entry" />
    </a>
    <body>
    <?php
      
    //After validating successfully
    else {
    /* Now we will write a query to insert user details into database */
    $host "fdb5.freehostingeu.com"// Host name...change it to your configuration information.
    $username "1487284_mydb"// Mysql username...change it to your configuration information.
    $password "l"// Mysql password...change it to your configuration information.
    $db_name "1487284_mydb"// Database name...change it to your configuration information.
    // Connect to server
    mysql_connect("$host""$username""$password") or die('ERROR: Cannot connect' .mysql_error());
    //connect to database
    mysql_select_db("$db_name") or die ('ERROR: Cannot connect'.mysql_error());
     
    $tbl_name "UserNote";  //Mysql Table name...change it to your configuration information.
     
    $sql="INSERT INTO $tbl_name (CustomerName, Phone, Email, Issue, Result, Date)
            VALUES('
    $customername', '$phonenumber', '$email',  '$issue', '$result', '$date')";
    }
      {
    if (!
    mysql_query($sql)) //notice the "!" it means if the mysql_query($sql)  cannot be executed, then die error. ELSE execute the mysql_querry($sql) to
                                            //insert into table in the database.
    {   
    die(
    'Error in Registration,: ' mysql_error());
    }
    else
    {    
    //Insert User into the database.
    }
    //Protect against mysql_injection
     
    $customername mysql_real_escape_string(trim($_POST["customername"]));
    $phonenumber mysql_real_escape_string(trim($_POST["pnumber"]));
    $email mysql_real_escape_string(trim($_POST["eaddy"]));
    $issue mysql_real_escape_string(trim($_POST["issue"]));
    $result mysql_real_escape_string(trim($_POST["results"]));
    $date mysql_real_escape_string(trim($_POST["Date"]));
     
     
    //Now check form input(Validating the form).
    $errmsg_arr = array(); //Array to store validation errors
    $check_Error false//Validation error flag
     
    if (empty($customername)){
    $errmsg_arr[]= '.Please Enter Your Name';
     
    $check_Error true;
    }
    if (empty(
    $phonenumber)){
    $errmsg_arr[]= '.Please Enter Your Phone Number';
     
    $check_Error true;
    }
    if (empty(
    $email)){
    $errmsg_arr[]= '.Please Enter Your Email';
     
    $check_Error true;
    }
    if (empty(
    $issue)){
    $errmsg_arr[]= '.Please what is your issue';
     
    $check_Error true;
    }
    if (empty(
    $result)){
    $errmsg_arr[]= '.Please what is your issue';
     
    $check_Error true;
    }
      if (empty(
    $date)){
    $errmsg_arr[]= '.Please what is your issue';
     
    $check_Error true;
    }
    //Printing out any error message stored in the array.
    if ($check_Error == true){
      echo 
    '<h1>ERROR: </h1><h3>Please check below for Error Details</h3>';
     
      if( isset(
    $errmsg_arr) && is_array($errmsg_arr) && count($errmsg_arr) > ) {
          echo 
    '<ul><font color="red">';
          foreach(
    $errmsg_arr as $msg) {
            echo 
    '<li><b>Error: &nbsp;&nbsp;&nbsp;'.$msg.'</b></li><br />';
           }
             echo 
    '</font></ul>';
       }
          
    //Please change the a href link to the name of your page.
          
    echo "<p><a href='http://localhost/site/index.html'>Go Back To Register</a></p>";
    }

    ?>
    <hr/>
        <table border="1">

        <tr>
        <th align="center">DATE</th>
        <th align="center">NAME </th>
        <th align="center">EMAIL </th>
        <th align="center">PHONE </th>
        <th align="center">ISSUE </th>
        <th align="center">RESULT </th>
        </tr>
    <?php
     $result
    =mysql_query("SELECT * FROM $tbl_name");  //sql query to call all the record available in database
     
    if ($result) {
      while (
    $fetch mysql_fetch_assoc($result)) {
      
    //Using the WHILE - LOOP TO Display the whole recode in tabular form.
      
    echo '<tr>';
      echo 
    '<td>'.$fetch['Date'] .'</td>';
      echo 
    '<td>'.$fetch['CustomerName'] .'</td>';
      echo 
    '<td>'.$fetch['Email'] .'</td>';
      echo 
    '<td>'.$fetch['Phone'] .'</td>';
      echo 
    '<td>'.$fetch['Issue'] .'</td>';
      echo 
    '<td>'.$fetch['Result'] .'</td>';
      echo 
    '</tr>';
      }
     }
     else {
      die (
    "ERROR: Could not fetch record : ".mysql_error());
     }
    ?>
     
     </table>
    </body>
    </html>

  9. #9
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,206
    That because you broke an if(){}else{} clause,

    Line 17: else {
    Line 18: /* Now we will write a query to insert user details into database */


    What I said was that you need to MOVE the CONNECTION and Associated elements like the LOGIN information, you don't need to move your query stuff.

    EG.

    PHP Code:
    $host "fdb5.freehostingeu.com"// Host name...change it to your configuration information.
    $username "1487284_mydb"// Mysql username...change it to your configuration information.
    $password "l"// Mysql password...change it to your configuration information.
    $db_name "1487284_mydb"// Database name...change it to your configuration information.
    // Connect to server
    mysql_connect("$host""$username""$password") or die('ERROR: Cannot connect' .mysql_error());
    //connect to database
    mysql_select_db("$db_name") or die ('ERROR: Cannot connect'.mysql_error()); 
    The rest only needed to say put.

    The above elements should really be in an include file of their own and called with a require_once() include.

    You might need to include a variable for your database handler, eg

    $db = mysql_connect("$host", "$username", "$password") or die('ERROR: Cannot connect' .mysql_error());
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  10. #10
    Join Date
    Oct 2012
    Posts
    36
    I think i got it but now i'm getting this error

    Parse error: syntax error, unexpected $end in /srv/disk9/1487284/www/omgtechnotes.me.pn/insert.php on line 129



    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <img src="http://omgtechhelp.com/wp/wp-content/themes/OMGTech/images/logo7small.jpg" />
    <center>
    <h1><u>Notes For The Month Of August</u></h1>
    </center>
      <a href="http://omgtechnotes.me.pn/index.html">
       <input type="button" value="New Entry" />
    </a>
    <body>
    <?php

    $host 
    "fdb5.freehostingeu.com"// Host name...change it to your configuration information.
    $username "1487284_mydb"// Mysql username...change it to your configuration information.
    $password "1"// Mysql password...change it to your configuration information.
    $db_name "1487284_mydb"// Database name...change it to your configuration information.
    // Connect to server
    mysql_connect("$host""$username""$password") or die('ERROR: Cannot connect' .mysql_error());
    //connect to database
    mysql_select_db("$db_name") or die ('ERROR: Cannot connect'.mysql_error());

    //Protect against mysql_injection
     
    $customername mysql_real_escape_string(trim($_POST["customername"]));
    $phonenumber mysql_real_escape_string(trim($_POST["pnumber"]));
    $email mysql_real_escape_string(trim($_POST["eaddy"]));
    $issue mysql_real_escape_string(trim($_POST["issue"]));
    $result mysql_real_escape_string(trim($_POST["results"]));
    $date mysql_real_escape_string(trim($_POST["Date"]));
     
     
    //Now check form input(Validating the form).
    $errmsg_arr = array(); //Array to store validation errors
    $check_Error false//Validation error flag
     
    if (empty($customername)){
    $errmsg_arr[]= '.Please Enter Your Name';
     
    $check_Error true;
    }
    if (empty(
    $phonenumber)){
    $errmsg_arr[]= '.Please Enter Your Phone Number';
     
    $check_Error true;
    }
    if (empty(
    $email)){
    $errmsg_arr[]= '.Please Enter Your Email';
     
    $check_Error true;
    }
    if (empty(
    $issue)){
    $errmsg_arr[]= '.Please what is your issue';
     
    $check_Error true;
    }
    if (empty(
    $result)){
    $errmsg_arr[]= '.Please what is your issue';
     
    $check_Error true;
    }
      if (empty(
    $date)){
    $errmsg_arr[]= '.Please what is your issue';
     
    $check_Error true;
    }
    //Printing out any error message stored in the array.
    if ($check_Error == true){
      echo 
    '<h1>ERROR: </h1><h3>Please check below for Error Details</h3>';
     
      if( isset(
    $errmsg_arr) && is_array($errmsg_arr) && count($errmsg_arr) > ) {
          echo 
    '<ul><font color="red">';
          foreach(
    $errmsg_arr as $msg) {
            echo 
    '<li><b>Error: &nbsp;&nbsp;&nbsp;'.$msg.'</b></li><br />';
           }
             echo 
    '</font></ul>';
       }
          
    //Please change the a href link to the name of your page.
          
    echo "<p><a href='http://localhost/site/index.html'>Go Back To Register</a></p>";
    }
    //After validating successfully
    else {
    /* Now we will write a query to insert user details into database */

     
    $tbl_name "UserNote";  //Mysql Table name...change it to your configuration information.
     
    $sql="INSERT INTO $tbl_name (CustomerName, Phone, Email, Issue, Result, Date)
            VALUES('
    $customername', '$phonenumber', '$email',  '$issue', '$result', '$date')";
    }
      {
    if (!
    mysql_query($sql)) //notice the "!" it means if the mysql_query($sql)  cannot be executed, then die error. ELSE execute the mysql_querry($sql) to
                                            //insert into table in the database.
    {   
    die(
    'Error in Registration,: ' mysql_error());
    }
    else
    {    
    //Insert User into the database.
    }
    ?>
    <hr/>
        <table border="1">

        <tr>
        <th align="center">DATE</th>
        <th align="center">NAME </th>
        <th align="center">EMAIL </th>
        <th align="center">PHONE </th>
        <th align="center">ISSUE </th>
        <th align="center">RESULT </th>
        </tr>
    <?php
     $result
    =mysql_query("SELECT * FROM $tbl_name");  //sql query to call all the record available in database
     
    if ($result) {
      while (
    $fetch mysql_fetch_assoc($result)) {
      
    //Using the WHILE - LOOP TO Display the whole recode in tabular form.
      
    echo '<tr>';
      echo 
    '<td>'.$fetch['Date'] .'</td>';
      echo 
    '<td>'.$fetch['CustomerName'] .'</td>';
      echo 
    '<td>'.$fetch['Email'] .'</td>';
      echo 
    '<td>'.$fetch['Phone'] .'</td>';
      echo 
    '<td>'.$fetch['Issue'] .'</td>';
      echo 
    '<td>'.$fetch['Result'] .'</td>';
      echo 
    '</tr>';
      }
     }
     else {
      die (
    "ERROR: Could not fetch record : ".mysql_error());
     }
    ?>
     
     </table>
    </body>
    </html>

  11. #11
    Join Date
    Oct 2012
    Posts
    36
    still getting issues, what is supposed to happen is that when i click on submit it opens another page and has a table with the submitted information dont know what we did but now its not working the way it should be


    PHP Code:
    .
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
      
      <img src="http://omgtechhelp.com/wp/wp-content/themes/OMGTech/images/logo7small.jpg" alt="OMG"/>
        
    <center>
    <h1><u>Notes For The Month Of August</u></h1>
    </center>
      <a href="http://omgtechnotes.me.pn/index.html">
       <input type="button" value="New Entry" />
    </a> 
      
    <?php

    $host 
    "fdb5.freehostingeu.com"// Host name...change it to your configuration information.
    $username "1487284_mydb"// Mysql username...change it to your configuration information.
    $password "lezbianz69"// Mysql password...change it to your configuration information.
    $db_name "1487284_mydb"// Database name...change it to your configuration information.
    // Connect to server
    mysql_connect("$host""$username""$password") or die('ERROR: Cannot connect' .mysql_error());
    //connect to database
    mysql_select_db("$db_name") or die ('ERROR: Cannot connect'.mysql_error());

    //Protect against mysql_injection
     
    $customername mysql_real_escape_string(trim($_POST["customername"]));
    $phonenumber mysql_real_escape_string(trim($_POST["pnumber"]));
    $email mysql_real_escape_string(trim($_POST["eaddy"]));
    $issue mysql_real_escape_string(trim($_POST["issue"]));
    $result mysql_real_escape_string(trim($_POST["results"]));
    $date mysql_real_escape_string(trim($_POST["Date"]));
     
     
    //Now check form input(Validating the form).
    $errmsg_arr = array(); //Array to store validation errors
    $check_Error false//Validation error flag
     
    if (empty($customername)){
    $errmsg_arr[]= '.Please Enter Your Name';
     
    $check_Error true;
    }
    if (empty(
    $phonenumber)){
    $errmsg_arr[]= '.Please Enter Your Phone Number';
     
    $check_Error true;
    }
    if (empty(
    $email)){
    $errmsg_arr[]= '.Please Enter Your Email';
     
    $check_Error true;
    }
    if (empty(
    $issue)){
    $errmsg_arr[]= '.Please what is your issue';
     
    $check_Error true;
    }
    if (empty(
    $result)){
    $errmsg_arr[]= '.Please what is your issue';
     
    $check_Error true;
    }
      if (empty(
    $date)){
    $errmsg_arr[]= '.Please what is your issue';
     
    $check_Error true;
    }
    //Printing out any error message stored in the array.
    if ($check_Error == true){
      echo 
    '<h1>ERROR: </h1><h3>Please check below for Error Details</h3>';
     
      if( isset(
    $errmsg_arr) && is_array($errmsg_arr) && count($errmsg_arr) > ) {
          echo 
    '<ul><font color="red">';
          foreach(
    $errmsg_arr as $msg) {
            echo 
    '<li><b>Error: &nbsp;&nbsp;&nbsp;'.$msg.'</b></li><br />';
           }
             echo 
    '</font></ul>';
       }
          
    //Please change the a href link to the name of your page.
          
    echo "<p><a href='http://localhost/site/index.html'>Go Back To Register</a></p>";
    }
    //After validating successfully
    else {
    /* Now we will write a query to insert user details into database */

     
    $tbl_name "UserNote";  //Mysql Table name...change it to your configuration information.
     
    $sql="INSERT INTO $tbl_name (CustomerName, Phone, Email, Issue, Result, Date)
            VALUES('
    $customername', '$phonenumber', '$email',  '$issue', '$result', '$date')";
    }
      {
    if (!
    mysql_query($sql)) //notice the "!" it means if the mysql_query($sql)  cannot be executed, then die error. ELSE execute the mysql_querry($sql) to
                                            //insert into table in the database.
    {   
    die(
    'Error in Registration,: ' mysql_error());
    }
    else
    {    
    //Insert User into the database.
      
    }
    ?>
    <hr/>
        <table border="1">

        <tr>
        <th align="center">DATE</th>
        <th align="center">NAME </th>
        <th align="center">EMAIL </th>
        <th align="center">PHONE </th>
        <th align="center">ISSUE </th>
        <th align="center">RESULT </th>
        </tr>
    <?php
     $result
    =mysql_query("SELECT * FROM $tbl_name");  //sql query to call all the record available in database
     
    if ($result) {
      while (
    $fetch mysql_fetch_assoc($result)) {
      
    //Using the WHILE - LOOP TO Display the whole recode in tabular form.
      
    echo '<tr>';
      echo 
    '<td>'.$fetch['Date'] .'</td>';
      echo 
    '<td>'.$fetch['CustomerName'] .'</td>';
      echo 
    '<td>'.$fetch['Email'] .'</td>';
      echo 
    '<td>'.$fetch['Phone'] .'</td>';
      echo 
    '<td>'.$fetch['Issue'] .'</td>';
      echo 
    '<td>'.$fetch['Result'] .'</td>';
      echo 
    '</tr>';
      }
     }
     else {
      die (
    "ERROR: Could not fetch record : ".mysql_error());
     }
    ?>
     
     </table>
    </body>
    </html>

  12. #12
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,206
    You appear to have a period at the beginning of your script. That won'r help matters.

    To break things down, your script with a database...

    1. start any sessions
    2. include any external scripts
    3. make database connections before using any database functions
    4. process script


    So seeing as you are not using any sessions, you can ignore point 1

    You are not currently using any external scripts, you can ignore point 2

    You are using a database, set up the connections...

    PHP Code:
    <?php
        
    // Host name...change it to your configuration information.
        
    $host "fdb5.freehostingeu.com"

        
    // Mysql username...change it to your configuration information.
        
    $username "1487284_mydb"
        
        
    // Mysql password...change it to your configuration information.
        
    $password "lezbianz69"
        
        
    // Database name...change it to your configuration information.
        
    $db_name "1487284_mydb"

        
    // Connect to server
        
    $handle mysql_connect("$host""$username""$password") or die('ERROR: Cannot connect' .mysql_error());

        
    //connect to database
        
    mysql_select_db("$db_name") or die ('ERROR: Cannot connect'.mysql_error());
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>...
    Then continue with the rest of your production, regarding point 4...

    I did notice a few things that can be improved on but first off you need to get a working script.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  13. #13
    Join Date
    Oct 2012
    Posts
    36
    Okay i seem to got almost everything working but there appears to be an issue with line 50

    which is this line "$result=mysql_query("SELECT * FROM $tbl_name");"

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <?php
        
    // Host name...change it to your configuration information.
        
    $host "fdb5.freehostingeu.com"

        
    // Mysql username...change it to your configuration information.
        
    $username "1487284_mydb"
        
        
    // Mysql password...change it to your configuration information.
        
    $password "lezbianz69"
        
        
    // Database name...change it to your configuration information.
        
    $db_name "1487284_mydb"

        
    // Connect to server
        
    $handle mysql_connect("$host""$username""$password") or die('ERROR: Cannot connect' .mysql_error());

        
    //connect to database
      
    mysql_select_db("$db_name") or die ('ERROR: Cannot connect'.mysql_error());
        
        
    //After Validating Successfully
      
    {
        
    /* Now we will write a query to insert user details into datebase */
        
    $tbl_name"usernote"//Mysql Table Name...Change It To Your Configuration Information. 
      
    $sql="INSERT INTO $tbl_name (CustomerName, Phone, Email, Issue, Result, Date)
            VALUES('
    $customername', '$phonenumber', '$email',  '$issue', '$result', '$date')";
    }
    if (!
    mysql_query($sql)) //notice the "!" it means if the mysql_query($sql)  cannot be executed, then die error. ELSE execute the mysql_querry($sql) to
                                            //insert into table in the database.
    {   
    die(
    'Error in Registration,: ' mysql_error());
    }
    else
    {    
    //Insert User into the database.
    }
    ?>
    <hr/>
        <table border="1">

        <tr>
        <th align="center">DATE</th>
        <th align="center">NAME </th>
        <th align="center">EMAIL </th>
        <th align="center">PHONE </th>
        <th align="center">ISSUE </th>
        <th align="center">RESULT </th>
        </tr>
    <?php
     $result
    =mysql_query("SELECT * FROM $tbl_name");  //sql query to call all the record available in database
     
    if ($result) {
      while (
    $fetch mysql_fetch_assoc($result)) {
      
    //Using the WHILE - LOOP TO Display the whole recode in tabular form.
      
    echo '<tr>';
      echo 
    '<td>'.$fetch['Date'] .'</td>';
      echo 
    '<td>'.$fetch['CustomerName'] .'</td>';
      echo 
    '<td>'.$fetch['Email'] .'</td>';
      echo 
    '<td>'.$fetch['Phone'] .'</td>';
      echo 
    '<td>'.$fetch['Issue'] .'</td>';
      echo 
    '<td>'.$fetch['Result'] .'</td>';
      echo 
    '</tr>';
      }
     }
     else {
      die (
    "ERROR: Could not fetch record : ".mysql_error());
     }
      
    ?> 
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
      
    <img src="http://omgtechhelp.com/wp/wp-content/themes/OMGTech/images/logo7small.jpg" />
      <body>
        <center>
    <h1><u>Notes For The Month Of August</u></h1>
    </center>
        <a href="http://www.omgtechnotes.me.pn/index.html">
       <input type="button" value="New Entry" />
    </a>
        <?php
      
    //Protect against mysql_injection.
      
    $customername mysql_real_escape_string(trim($post["customername"]));
      
    $phonenumber mysql_real_escape_string(trim($post["pnumber"]));
      
    $email mysql_real_escape_string(trim($post["eaddy"]));
      
    $issue mysql_real_escape_string(trim($_POST["issue"]));
      
    $result mysql_real_escape_string(trim($_POST["results"]));
      
    $date mysql_real_escape_string(trim($_POST["Date"]));
      
      
    //Now check form input(Validating the form).
      
    $errmsg_arr = array(); //Array to store validation erros
      
    $check_Error false//Validtion error flag
      
      
    if (empty($customername)){
        
    $errmsg_arr[]= 'Please Enter Your Name';
        
    $check_Error true;
      }
      if (empty(
    $phonenumber)){
        
    $errmsg_arr[]= 'Please Enter Your Phone Number';
        
    $check_Error true;
      }
      if (empty(
    $email)){
        
    $errmsg_arr[]= 'Please Enter Your E-Mail';
        
    $check_Error true;
      }
      if (empty(
    $issue)){
        
    $errmsg_arr[]= 'Please Enter The Issue';
        
    $check_Error true;
      }
      if (empty(
    $result)){
        
    $errmsg_arr[]= 'Please Enter The Result';
        
    $check_Error true;
      }
      if (empty(
    $date)){
        
    $errmsg_arr[]= 'Please Enter The Date';
        
    $check_Error true;
      }
      
    //Printing out any error message stored in the array.
      
    if ($check_Error true){
        echo 
    "<h1>Error: </h1><h3>Please Check Below For Error Details</h3>";}
      
      if( isset(
    $errmsg_arr) && is_array($errmsg_arr) && count($errmsg_arr) > ) {
        echo 
    '<ul><font color="red">';}
          foreach(
    $errmsg_arr as $msg) {
            echo 
    '<li><b>Error: &nbsp;&nbsp;&nbsp;'.$msg.'</b></li><br />';}
      {        
            echo 
    '</font></ul>';}
      
    //Please Change The A Href Link To The Name OF Your Page.
      
    echo "<p><a href='http://www.omgtechnotes.me.pn/index.html'>Go Back</a></p>";
    Last edited by spudly1987; 08-19-2013 at 09:03 AM.

  14. #14
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,206
    You need to have $handle as one of the parameters in the mysql_query function

    PHP Code:
    $result=mysql_query("SELECT * FROM $tbl_name",$handle); 
    http://php.net/manual/en/function.mysql-query.php

    while the examples, and many of them do show no link identifier to a resource, you do need to have a link resource.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  15. #15
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    FYI, it *should* get the most recent handle (I think that's the logic) if you don't specify it, but specifying it certainly make your code more robust, so is a good idea* (in case some part of your application code opens up a separate DB handle).

    Anyway, what is the exact error you are getting? Is it outputting the result of mysql_error() when it fails?

    ___________
    * A better idea might be to upgrade to the MySQLi extension or even PDO, so that you are not using the deprecated MySQL PHP extension.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles