Jump to content
Larry Ullman's Book Forums

sonal

Members
  • Posts

    121
  • Joined

  • Last visited

  • Days Won

    2

Posts posted by sonal

  1. Hi,

     

    I was excited to upload my bunch of scripts, as they were working fine on my own computer and browsers. I uploaded index page and its related include files, just to see what happens. And there it goes.. the headers already sent errors dropping in my email boxes. And the browser shows following error too..

    Fatal error: Cannot redeclare my_error_handler() (previously declared in /home/myreadin/includes/configr.inc.php:20) in /home/myreadin/public_html/configr.inc.php on line 53

     

    I'm using chapter 15 and 16 examples to write register, login and logout scripts. So I don't understand why and how these errors are showing up? Help please...

  2. Well, it feels good to read your comment and suggestion. I am taking your advice literally to move forward one at a time, and will keep learning.

     

    Now there is one new problem. I wanted to check form input values with regular expressions. They work fine with English language, but not with Gujarati. I'm using one simple regular expression as Larry has shown to check a name in the registration script.

  3. 'HartleySan'

     

    Thanks a lot for your detailed reply.

    For the following method, I got idea from this link: http://devzone.zend.com/article/1300#comment_form

     

     

    1) Use the method I think you used before, which involves using PHP to place values in JavaScript variables. I find this to be the most broke-ass (i.e., the worst) method. Nevertheless, it works. An example of this can be seen in the following:

     

     

    I wish I could learn all the technologies required to make a website, but right now I'm stuck with php. This particular part is not working today, as it was working a day before.

    Any how, thanks a lot again..

  4. Well, Now I can understand what you said. My script sometimes run well and some other time does not work the way it should. So I definitely need to change it to javascript. So I was looking at js cookies section. Now my problem is this. I am using php session from the start of the website, where it sets userid and his language. Now I don't understand how can I use this values to get them work in the js cookies.

    The user is looking the site in his language, and for this one page how can I ask again to choose his language? The page should detect the language. Please guide me.

     

    thanks

  5. HartleySan

     

    Thank you very much. But, I was trying to figure out how to do that and I changed my php script as follows. And it works.. Now, I am a beginner to PHP, I don't know javascript or Ajax. So, I tried finding a tutorial to pass php variable to javascript variable and used it in my script. It's working fine on my computer. It means that if a user has selected gujarati language, then he can type in gujarati fonts, otherwise he can type in English.

    I wonder, will my script really work over the internet? It is working fine in my browser windows.

     

    Here I have pasted only that part of the script which checks the session variable and then calls js function.

     

    <?php

    //Check for language gujarati:

    //If language is Gujarati then call Javascript function.

     

    if($_SESSION['lid'] == 11)

    {

    $lang = 11;

    //If it ran ok.

    // echo $lang;

    ?>

    <script language="javascript" type="text/javascript">

    jslid = "<?php echo $lang; ?>";

    if (jslid == 11)

    {

    document.write(jslid);

    pph = new PramukhPhoneticHandler();

    pph.convertToIndicIME("title", document.getElementById('title'),'gujarati');

    pph.convertToIndicIME("author", document.getElementById('author'),'gujarati');

    pph.convertToIndicIME("review", document.getElementById('review'),'gujarati');

    }

    </script>

    <?php

     

    } //End of if gujarati check.

    else {

    //echo "other than gujarati ";

    //echo $_SESSION['lid'];

    }

    ?>

    <p><input type="submit" name="submit" value="Add" /></p>

    <p><input type="hidden" name="submitted" value="TRUE" /></p>

  6. How to use javascript function into php script? I am trying to change input language of the form as follow:

    If session language id is gujarati, then I want to use the javascript function. But my form does not show submit button, or it seems script does not run after checking for language.

     

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

     

    <meta name="copyright" content="Copyright © Vishal Monpara">

    <script type="text/javascript" src="js/pramukhlib.js"></script>

    <script language="javascript">

     

    // Main object for phonetic processing

    var pph;

     

    </script>

    </head>

     

    <body>

     

    <?php #script 2.5 - Add_book.php

     

    //This script allows to add a new book detail into the database.

     

    $page_title = 'Add book details';

     

    require_once('../includes/configr.inc.php');

     

    include('../includes/head.html');

     

    require_once(MYSQL);

     

    //Only display this form if the user is logged in:

     

    echo '<h1>Welcome';

     

    if(isset($_SESSION['first_name']))

    {

    echo ", {$_SESSION['first_name']}!";

    }

     

    echo '<h1>Add your book details.</h1>';

     

    //Language specific words:

    $t1 = $words['book_title'];

    $a1 = $words['author'];

    $r1 = $words['book_review'];

     

    $l = $_SESSION['lid'];

    $u = $_SESSION['user_id'];

     

     

     

    if(isset($_POST['submit']) && isset($_SESSION['user_id']))

    { //Handle the form:

     

    //Trim all the incoming data:

    $trimmed = array_map('trim', $_POST);

     

    //Assume invalid values:

    $t = $a = $r = FALSE;

     

    //check for a title:

     

    if(!empty($_POST['title']))

    {

    $t = mysqli_real_escape_string($dbc, $trimmed['title']);

    }

    else {

    echo '<p class="error">Please enter the book title.</p>';

    }

     

    //check for an author name:

    if(!empty($_POST['author']))

    {

    $a = mysqli_real_escape_string($dbc, $trimmed['author']);

    }

    else {

    echo '<p class="error">Please enter author name.</p>';

    }

     

     

    $r = mysqli_real_escape_string($dbc, trim($_POST['review']));

     

    // echo $t ;

    if($t && $a)

    { //If all is OK..

     

    $q = "INSERT INTO books(lang_id, user_id,title, author, review, date) VALUES ($l, $u, '$t', '$a', '$r', now())";

     

    $r = mysqli_query($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));

     

    if(mysqli_affected_rows($dbc) == 1)

    {

    //If it ran OK..

     

    echo 'The book is added.';

    }

    }

    }

    mysqli_close($dbc);

     

    ?>

     

    <form action="addbook.php" method="post" accept-charset="utf-8">

    <p><?php echo $t1; ?><input type="text" id="title" name="title" size="80" value="<?php if(isset($_POST['title'])) echo $_POST['title']; ?>" /></p>

    <p><?php echo $a1; ?>:<input type="text" id="author" name="author" size="80" value="<?php if(isset($_POST['author'])) echo $_POST['author'] ?>" /></p>

     

    <p><?php echo $r1; ?>:<textarea id="review" name="review" rows="20" cols="50" value="<?php if(isset($_POST['type'])) echo $_POST['type']; ?>" /></textarea></p>

     

     

     

    <?php

    //Check for language gujarati:

     

     

    //If language is Gujarati then call Javascript function.

     

    if($_SESSION['lid'] == 'Gujarati')

    {

    echo 'Gujarati';

    //If it ran ok.

    ?>

    <script language="javascript" type="text/javascript">

     

    pph = new PramukhPhoneticHandler();

    pph.convertToIndicIME("title", document.getElementById('title'),'gujarati');

    pph.convertToIndicIME("author", document.getElementById('author'),'gujarati');

    pph.convertToIndicIME("review", document.getElementById('review'),'gujarati');

     

    </script>

     

    <p><input type="submit" name="submit" value="Add" /></p>

    <p><input type="hidden" name="submitted" value="TRUE" /></p>

     

     

    <?php

     

    } //End of if gujarati check.

     

    ?>

  7. Hi Josee,

    A little update. Now I am able to insert data through the PHP form. I have done nothing special other than instructions given in Larry's book, as in message board example. I tried typing gujarati words in the form using online IME tool and also with Windows change keyboard facility. I set it for gujarati language, and it lets me add new record in mysql through php form. So, it seems you helped me to get right (unicode) characters, so now they are showing up. My script is similar to the example of the book. Do you want me to paste it here?

  8. Well, I got something to dig in. There is a ray of success. I have more than one fonts for the language Gujarati. When I was looking them at charmap utility, I went into advanced view. I listed all fonts using unicode subrange in Group by list box. Unicode subrange box lists my languages like devnagari and gujarati. There I can see character map for a font for devnagari language. I copied some of them in my table, and it shows exactly same as this. But there is no character map for any fonts of gujarati language. (Although they are installed, and I checked them properly in fonts folder.) So, we can say that my computer is ready to show devnagari fonts, but not gujarati. I hope this helps you (you will get what I'm trying to say). And if you get anything from this, then let me know how to insert gujarati language in that unicode character map...

  9. Thank you Josee.

     

    The sites you gave are useful. I come to know that my language (Gujarati) is UTF-8 unicode characters, and the browsers test runs good on my computer. I have fonts installed on my computer. But I can't see them right from my database. I tried to type a word in charmap, and then paste it in column value. I also tried typing in word processor, and then copy-paste it in column value. But no result. still trying..

  10. I am trying to learn multi-language support of php and mysql. I want to insert non-english characters into one of the table, in mysql. My system setup is as follow:

     

    MySQL charset: UTF-8 Unicode (utf8)

    Web server

     

    Microsoft-IIS/7.5

    MySQL client version: mysqlnd 5.0.8-dev

     

    php version 5.3.6

     

    I used windows charmap to type and then insert the value in the table. But when I see them in the browser, they are garbage(just english plain text of those other fonts). What extra care should I take? I have indicated specific encoding (UTF-8 charset) in all the scripts as and when require.

    My table is same as language table of Ch. 15. I am trying to add another language. All other languages given in the insert query for this table in this book, shows off properly in the browser. But my new language is not showing as it should be. How can I add it?

    Does Indian languages need other than UTF-8 charset?

  11. Thanks for the great book.

    Now, I'm a newbee to PHP and trying to learn pagination concept. I got another problem. I am trying to list out books from database, on page by page. The first page shows perfect result (list of 5 books), with navigation buttons. When I click 2 (or any next page), the script throws an error.. saying, undefined variable dbc. If it gets "dbc" variable for the first 5 records, how come it becomes undefined for next pages?

    Here is my code:

     

    <?php #Script 1.6 - view_books.php

     

    //This script retrieves all books from the books table.

    //This version paginates the results.

     

    $page_title = 'View all books';

     

    require_once('../includes/configuration.inc.php');

     

    include('../includes/headpart.html');

     

    echo '<h1>Books List</h1>';

     

    //Number of records to show per page.

     

    $display = 5;

     

    //Determine how many pages are there...

     

    if(isset($_GET['p']) && is_numeric($_GET['p']))

    {

    //Already been determined.

     

    $pages = $_GET['p'];

     

    }

    else { //Need to be determine.

     

    require_once(MYSQL);

     

    //count the number of records:

     

    $q = "SELECT COUNT(bookid) FROM books";

     

    $r = @mysqli_query($dbc, $q);

     

    $row = @mysqli_fetch_array($r, MYSQLI_NUM);

     

    $records = $row[0];

     

     

    //calculate the number of pages..

     

    if($records > $display)

    { //More than one page.

     

    $pages = ceil($records/$display);

     

    }

    else {

    $pages = 1;

    }

    } //End of p IF.

     

    //Determine where in the database to start returning results...

     

    if(isset($_GET['s']) && is_numeric($_GET['s']))

    {

    $start = $_GET['s'];

    } else {

    $start = 0;

    }

     

    //Make the query.

     

    $q = "SELECT bookid, title, author, price, category FROM books order by title ASC LIMIT $start, $display";

     

    $r = @mysqli_query($dbc, $q);

     

    //Table header:

     

    echo '<table align="center" cellspacing="0" cellpadding="5" width="75%">

    <tr>

    <td align="left"><b>Title</b></td>

    <td align="left"><b>Author</b></td>

    <td align="left"><b>Price</b></td>

    <td align="left"><b>Category</b></td>

    </tr>';

     

    //Fetch and print all records:

     

    $bg = '#eeeeee'; //set the initial background color.

     

    if(mysqli_num_rows($r) > 0 )

    {

    while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))

    {

    $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); //Switch the background color.

     

    echo '<tr bgcolor="' . $bg .'">

    <td align="left">' . $row['title'] . '</td>

    <td align="left">' . $row['author'] . '</td>

    <td align="left">' . $row['price'] . '</td>

    <td align="left">' . $row['category'] . '</td>

    </tr>';

     

    }

    } //End of while loop.

    echo '</table>';

     

    mysqli_free_result($r);

    mysqli_close($dbc);

     

    //Make the links to other pages, if necessary.

     

    if($pages > 1)

    {

    //Add some spacing and start a paragraph.

     

    echo '<br /><p>';

     

    //Determine what page the script is on:

     

    $current_page = ($start/$display) + 1;

     

    //IF it is not the first page, make a previous button:

     

    if($current_page != 1)

    {

    echo '<a href="view_books.php?s=' . ($start - $display) . '&p=' . $pages . '"> Previous</a>';

    }

     

    //Make all the numbered pages.

     

    for($i = 1; $i <= $pages; $i++)

    {

    if($i != $current_page)

    {

    echo '<a href="view_books.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a>';

    }

    else {

    echo $i . ' ';

    }

    } //End of for loop.

     

    //If it's not the last page, make a next button.

     

    if($current_page != $pages)

    {

    echo '<a href="view_books.php?s=' . ($start + $display) . '&p=' . $pages . '">Next</a>';

    }

     

    echo '</p>';

    }

    ?>

  12. Sounds like an issue with the LIMIT BY clause in the query.

     

    The LIMIT BY clause requires two values to properly paginate results.

     

    I recommend checking Larry's book again for the details.

    Thanks for your reply.

    Now, I tried it again and I have another problem. I am trying to list out books from database, on page by page. The first page shows perfect result, with navigation buttons. When I click 2 (or any next page), the script throws an error.. saying, undefined variable dbc. If it gets dbc variable for the first 5 records, how come it becomes undefined for next pages?

    Here is my code:

     

    <?php #Script 1.6 - view_books.php

     

    //This script retrieves all books from the books table.

    //This version paginates the results.

     

    $page_title = 'View all books';

     

    require_once('../includes/configuration.inc.php');

     

    include('../includes/headpart.html');

     

    echo '<h1>Books List</h1>';

     

    //Number of records to show per page.

     

    $display = 5;

     

    //Determine how many pages are there...

     

    if(isset($_GET['p']) && is_numeric($_GET['p']))

    {

    //Already been determined.

     

    $pages = $_GET['p'];

     

    }

    else { //Need to be determine.

     

    require_once(MYSQL);

     

    //count the number of records:

     

    $q = "SELECT COUNT(bookid) FROM books";

     

    $r = @mysqli_query($dbc, $q);

     

    $row = @mysqli_fetch_array($r, MYSQLI_NUM);

     

    $records = $row[0];

     

     

    //calculate the number of pages..

     

    if($records > $display)

    { //More than one page.

     

    $pages = ceil($records/$display);

     

    }

    else {

    $pages = 1;

    }

    } //End of p IF.

     

    //Determine where in the database to start returning results...

     

    if(isset($_GET['s']) && is_numeric($_GET['s']))

    {

    $start = $_GET['s'];

    } else {

    $start = 0;

    }

     

    //Make the query.

     

    $q = "SELECT bookid, title, author, price, category FROM books order by title ASC LIMIT $start, $display";

     

    $r = @mysqli_query($dbc, $q);

     

    //Table header:

     

    echo '<table align="center" cellspacing="0" cellpadding="5" width="75%">

    <tr>

    <td align="left"><b>Title</b></td>

    <td align="left"><b>Author</b></td>

    <td align="left"><b>Price</b></td>

    <td align="left"><b>Category</b></td>

    </tr>';

     

    //Fetch and print all records:

     

    $bg = '#eeeeee'; //set the initial background color.

     

    if(mysqli_num_rows($r) > 0 )

    {

    while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))

    {

    $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); //Switch the background color.

     

    echo '<tr bgcolor="' . $bg .'">

    <td align="left">' . $row['title'] . '</td>

    <td align="left">' . $row['author'] . '</td>

    <td align="left">' . $row['price'] . '</td>

    <td align="left">' . $row['category'] . '</td>

    </tr>';

     

    }

    } //End of while loop.

    echo '</table>';

     

    mysqli_free_result($r);

    mysqli_close($dbc);

     

    //Make the links to other pages, if necessary.

     

    if($pages > 1)

    {

    //Add some spacing and start a paragraph.

     

    echo '<br /><p>';

     

    //Determine what page the script is on:

     

    $current_page = ($start/$display) + 1;

     

    //IF it is not the first page, make a previous button:

     

    if($current_page != 1)

    {

    echo '<a href="view_books.php?s=' . ($start - $display) . '&p=' . $pages . '"> Previous</a>';

    }

     

    //Make all the numbered pages.

     

    for($i = 1; $i <= $pages; $i++)

    {

    if($i != $current_page)

    {

    echo '<a href="view_books.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a>';

    }

    else {

    echo $i . ' ';

    }

    } //End of for loop.

     

    //If it's not the last page, make a next button.

     

    if($current_page != $pages)

    {

    echo '<a href="view_books.php?s=' . ($start + $display) . '&p=' . $pages . '">Next</a>';

    }

     

    echo '</p>';

    }

    ?>

  13. View_users script shows the concept of pagination. It is not working as it should be on my browser. It shows first 10 records on the first load, and also shows navigation button. But when I click to see the second page, it shows next rows plus previous rows too. I have total 17 records in the table, so on the second page it shows all 17 records. And this second page does not show Previous button either.

    I thought may be I made some mistake, so I copied the entire script from this site's downloads, and it is still shows the same result.

×
×
  • Create New...