Jump to content

web_master

Members
  • Posts

    419
  • Joined

  • Last visited

Posts posted by web_master

  1. Well if you're going to use mysqli then you would obviously need to use the mysqli functions to get info from the db too. Simply connecting with mysqli doesn't mean you can use the standard MySQL functions after that, umm like you are.

    As I see there is a many ways to use mysqli in request data from database. I try simple to "rename" mysql_ to mysqli_ but it not work. Somewhere I need to connect to the database too, $dbConnect. This is a problem, how can I do this... :(

  2. Hi,

     

    I got a problem with pagination. I got a script but the problem is that I use the connection to database with "mysqli" NOT "mysql". Im newbe with mysqli and I dont know how can I change the pagination script to work.

    <?php
    $dbConnect= mysqli_connect('localhost', 'user', 'password') or die('Cant connect');
    mysqli_select_db($dbConnect, 'database') or die('Cant connect to database');
    mysqli_set_charset($dbConnect, "utf8");
    ?>

    And this is a script for pagination

    <?php 
    $limit = 4;
     
    $sql = "select count(c_vesti_id) from c_vesti";
    
    $c = array_shift(mysql_fetch_row(mysql_query($sql)));
     
    $maxpage = ceil($c / $limit);
     
    $page = isset($_GET['page']) ? abs((int)$_GET['page']) : 1;
    if ($page <= 0)
    {
            $page = 1;
    }
    else if ($page >= $maxpage)
    {
            $page = $maxpage;
    }
     
    $offset = ($page-1) * $limit;
     
    $query = mysql_query("select * from c_vesti limit $offset, $limit ");
     
    while ($row = mysql_fetch_assoc($query))
    {
            print $row['c_vesti_naslov']."<br />";
    }
     
    //
    $linklimit = 4;
    $linklimit2 = $linklimit / 2;
    $linkoffset = ($page > $linklimit2) ? $page - $linklimit / 2 : 0;
    $linkend = $linkoffset+$linklimit;
     
    if ($maxpage - $linklimit2 < $page)
    {
            $linkoffset = $maxpage - $linklimit;
            if ($linkoffset < 0)
            {
                    $linkoffset = 0;
            }
            $linkend = $maxpage;
    }
     
    if ($page > 1)
    {
            print "<a href='?page=".($page-1)."'>Back</a>   ";
    }
    for ($i=1+$linkoffset; $i <= $linkend and $i <= $maxpage; $i++)
    {
            $style = ($i == $page) ? "color: black;" : "color: blue;";
            print "<a href='?page=$i' style='$style'>[$i]</a>   ";
    }
    if ($page < $maxpage)
    {
            print "<a href='?page=".($page+1)."'>Forward</a>";
    }
    ?>

    Thanks in advanced for help

    T

  3. Hi,

    I don't know what amI do wrong.

     

    I have 3 tables, (authors, text, kategories). I want to print every group names from database and + 3 text below kategory name. After first record (text) separately two more (next) records. With this code I give only the first category with 3 text...

    Please if You can help me....

    <?php 
    			/* SELECT FROM DATABASE */
    				$QuerySelect = ' SELECT
    				c_kat.c_kat_onoff,
    				c_kat.c_kat_delete,
    				c_kat.c_kat_order,
    				c_autor.c_autor_onoff,
    				c_autor.c_autor_delete,
    				c_autor.c_autor_prezime,
    				c_autor.c_autor_ime,
    				c_autor.c_autor_id,
    				c_kat.c_kat_id,
    				c_kat.c_kat_ime,
    				c_vesti.c_vesti_id,
    				c_vesti.c_vesti_date,
    				c_vesti.c_vesti_sat,
    				c_vesti.c_vesti_min,
    				c_vesti.c_vesti_naslov,
    				c_vesti.c_vesti_text,
    				c_vesti.c_vesti_kat,
    				c_vesti.c_vesti_autor,
    				c_vesti.c_vesti_onoff,
    				c_vesti.c_vesti_delete
    				FROM
    				c_vesti
    				INNER JOIN c_kat ON c_kat.c_kat_id = c_vesti.c_vesti_kat
    				INNER JOIN c_autor ON c_autor.c_autor_id = c_vesti.c_vesti_autor
    				WHERE `c_vesti_onoff` = 1 AND `c_vesti_delete` = 0
    				ORDER BY `c_kat_order` ASC, `c_vesti_date` DESC, `c_vesti_sat` DESC, `c_vesti_min` DESC, `c_vesti_id` ASC LIMIT 3 ';
    				$query_select = mysqli_query($dbConnect, $QuerySelect) or die (mysqli_error($dbConnect));
    				if(!$query_select){ echo mysqli_error($dbConnect); exit; }
    				while($request = mysqli_fetch_array($query_select)) {
    				
    				
    				$group_by_cat[$request['c_kat_ime']][] = $request;
    				
    				}
    				
    				foreach($group_by_cat as $group => $rows) {
    					
    					echo '<div class="catcolor">' . $group . '</div>'; // Category name
    				
    				$first_rec = true;
    					
    					foreach($rows as $row) {
    						if ($first_rec) {
    							// first record
    							echo '<div>First text headline - ', $row['c_vesti_naslov'], '</div>';
    							$first_rec = false;
    						} else {
    							// other records
    							echo '<div>Other text headline -', $row['c_vesti_naslov'], '</div>';
    						}
    					}
    				}
    
    
    ?>
    
  4. Hi,

    I just begin to use msqli and I dont know what am I doing wrong?

     

    The warning message is:

    Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in ...

    $QuerySelect = ' SELECT * FROM `a_slider` WHERE `a_slider_id` = "' . $a_slider_id . '" ';
    
        if(!$QuerySelect){ echo mysqli_error($dbConnect); exit; }
    
        $request = mysqli_fetch_array($QuerySelect);
    

    thanks

     

    T

  5. here is the styles too:

     

     

    body{
    
    font-family: Verdana;
    font-size: 11px;
    background-color: #BFC08D;
    
    }
    
    .tablebottom{
    
    border-bottom: 1px solid #E6E6E6;
    
    }
    
    .middlebox{
    
    border-bottom: 1px solid #E6E6E6;
    border-left: 1px solid #E6E6E6;
    
    }
    
    #maintable{
    
    border: 1px solid #E6E6E6;
    background-color: #C9CCBB;
    
    }
    
    #chatscreen{
    
    width: 850px;
    height: 500px;
    float: left;
    overflow: auto;
    text-align: left;
    
    }
    
    #onlineusers{
    
    height: 500px;
    width: 100px;
    float: right;
    
    }
    
    a{
    
    text-decoration: none;
    color: #000000;
    
    }
    
    a:hover{
    
    text-decoration: none;
    color: #8DBAEB;
    
    }
    
    input{
    
    border: 1px solid #E6E6E6;
    
    }
    
    #submitbutton{
    
    background-color: #FFFFFF;
    font-family: Tahoma;
    
    }
    
    #messagebox{
    
    background-color: #E8E9E2;
    
    }
    
    #userbox{
    
    background-color: #E8E9E2; 
    height: 20px;
    
    }
    
    #usersbox{
    
    text-align: left;
    background-color: #E8E9E2; 
    
    }
    
    .user{
    
    border-bottom: 1px solid #969A7A;
    
    }
    
  6. Hi,

    I fond some script on internet, and the textarea dont work. I cant find what is the problem....

    Nothing is inserted in database, and reloaded from database. The (who is) online users is work perfect.

     

    thnks in advanced

    T

     

    database

    CREATE TABLE IF NOT EXISTS `auth` (
    
    `user` varchar(30) NOT NULL,
    
    `session` varchar(50) NOT NULL
    
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    
    
    
    
    CREATE TABLE IF NOT EXISTS `chat` (
    
    `time` varchar(30) NOT NULL,
    
    `user` varchar(30) NOT NULL,
    
    `text` text NOT NULL
    
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    

    config.php

    <?php
    
    
    
    // Let's connect to our database
    
    // Usually your host is 'localhost'
    
    // But sometimes it might be different so ask your host
    
    // About your database server address
    
    $mysql_con = mysql_connect("localhost", "Username", "Password");
    
    
    
    // Now let's check if everything is good
    
    // If there's something wrong.. let's display an error
    
    if(!$mysql_con){
    
    
    
    die(mysql_error());
    
    
    
    }
    
    
    
    // Let's select our database
    
    $mysql_db = mysql_select_db("DatabaseName", $mysql_con);
    
    
    
    // Let's check here also is everything is okay
    
    // If there's something wrong, let's display an error
    
    if(!$mysql_con){
    
    
    
    die(mysql_error());
    
    
    
    }
    
    
    
    ?>
    

    actions.php

    <?php
    
    
    
    // Let's start our session
    
    session_start();
    
    
    
    // Include the config.php because we are
    
    // Going to start work with our database
    
    include("config.php");
    
    
    
    // First let's make a login form
    
    // Here user sets his/her username that
    
    // He/she will use in this chatroom
    
    function login_form(){
    
    
    
    echo "<br /><br />";
    
    echo "<table width='500' border='0' id='maintable' style='background-color: #F3F3F3' align='center'>"
    
    ."<tr>"
    
    ."<td align='center'><font style='font-size: 20px'>Login</font></td>"
    
    ."</tr>"
    
    ."<tr>"
    
    ."<td align='center'>";
    
    echo "<form action='index.php?act=login' method='post'>"
    
    ."Username: <input type='text' name='username' /> <input type='submit' id='button' value='Login' /><br /><br />"
    
    ."</form>"; 
    
    echo "</td>"
    
    ."</tr>"
    
    ."</table>";
    
    
    
    }
    
    
    
    // Now let's log that user in
    
    function process_login(){
    
    
    
    // Let's get user's username
    
    $username = $_REQUEST['username'];
    
    
    
    // Now let's find if there are records about him/her in database
    
    $sql = "SELECT * FROM auth WHERE user='".mysql_real_escape_string($username)."'";
    
    $query = mysql_query($sql);
    
    
    
    // If there are any records, delete them
    
    if(mysql_num_rows($query)>0){
    
    
    
    $sql = "DELETE FROM auth WHERE user='".mysql_real_escape_string($username)."'";
    
    $query = mysql_query($sql);
    
    
    
    // Check that everything is okay
    
    // If something is wrong, display an error
    
    if(!$query){
    
    
    
    die(mysql_error());
    
    
    
    }
    
    
    
    }
    
    
    
    // Now let's set session with user's name
    
    // And insert it into database so we know that
    
    // He/she is logged in
    
    $_SESSION['user'] = $username;
    
    $sql = "INSERT INTO auth (user, session) VALUES ('".mysql_real_escape_string($username)."', '".session_id()."')";
    
    $query = mysql_query($sql);
    
    
    
    // Check that all things went well
    
    // If something was wrong, display an error
    
    // But if evetrything is good, redirect him/her 
    
    // To the chatroom
    
    if(!$query){
    
    
    
    echo "Can not insert info into database!<br />". mysql_error();
    
    
    
    }else{
    
    
    
    header("Location: index.php");
    
    
    
    }
    
    
    
    }
    
    
    
    // Now let's make a function that logs users our
    
    function logout(){
    
    
    
    // This will delete any traces of him/her
    
    // From database so it will be a clean sheet
    
    // When he/she comes back
    
    $sql = "DELETE FROM auth WHERE session='".mysql_real_escape_string(session_id()). "'";
    
    $query = mysql_query($sql);
    
    
    
    // Little error checking again
    
    if(!$query){
    
    
    
    echo "Can not delete info from database!";
    
    
    
    }else{
    
    
    
    // If everything went well, let's destroy
    
    // Session and redirect to main page also
    
    // Where login form waits him/her
    
    session_destroy();
    
    header("Location: index.php");
    
    
    
    }
    
    
    
    }
    
    
    
    // Now we want to show user's username
    
    // In "Welcome [user]" area
    
    function get_username(){
    
    
    
    // Let's get all info abour our current session from database
    
    $sql = "SELECT * FROM auth WHERE session='".mysql_real_escape_string(session_id()). "'";
    
    $query = mysql_query($sql);
    
    $row = mysql_fetch_array($query);
    
    
    
    // If there aren't any records
    
    // Let's set our user's name to "Guest"
    
    // If there are records let's get the real username
    
    if(mysql_num_rows($query) == "0"){
    
    
    
    $username = "Guest";
    
    
    
    }else{
    
    
    
    $username = $row['user'];
    
    
    
    }
    
    
    
    return $username;
    
    
    
    }
    
    
    
    // Now we want to display "Log In" or "Log Out"
    
    // Link after greeting
    
    function get_link(){
    
    
    
    // Again we check for records from database
    
    $sql = "SELECT * FROM auth WHERE session='".mysql_real_escape_string(session_id()). "'";
    
    $query = mysql_query($sql);
    
    $row = mysql_fetch_array($query);
    
    
    
    // If there are no records about our user
    
    // Let's display "Log In" link
    
    // But if there are records about our user
    
    // Display a "Log Out" link
    
    if(mysql_num_rows($query) == "0"){
    
    
    
    $link = "<a href='index.php?act=login'>Log In</a>";
    
    
    
    }else{
    
    
    
    $link = "<a href='index.php?act=logout'>Log out</a>";
    
    
    
    }
    
    
    
    return $link; 
    
    
    
    }
    
    
    
    // This is the function that posts
    
    // User messages to database
    
    function post_message(){
    
    
    
    // Let's clean our text that user entered
    
    $text = addslashes(htmlentities(htmlspecialchars($_REQUEST['text'])));
    
    
    
    // Now let's insert it into database
    
    $sql = "INSERT INTO chat (time, user, text) VALUES ('".date("H:i")."', '".get_username()."', '".$text."')";
    
    $query = mysql_query($sql);
    
    
    
    // Little error checking and we are done
    
    if(!$query){
    
    
    
    die(mysql_error());
    
    
    
    }
    
    
    
    }
    
    
    
    // Now we have to get messages
    
    // From database to see what other users are writing
    
    function get_messages(){
    
    
    
    // Now let's get all info from "chat" table
    
    $sql = "SELECT * FROM chat";
    
    $query = mysql_query($sql);
    
    
    
    // Some error checking
    
    if(!$query){
    
    
    
    echo "Can not get messages from database.";
    
    
    
    }else{
    
    
    
    // If everything is fine let's display our messages
    
    // First to come is time, it will look like this (12:34)
    
    // Second is user's name and after that comes the text
    
    // For example: (13:54) Jaan: Hey there!
    
    while($row = mysql_fetch_array($query)){
    
    
    
    echo "(".$row[time].") "."<b>".$row['user'].":</b> ".$row['text']."<br />";
    
    
    
    }
    
    
    
    } 
    
    
    
    }
    
    
    
    // Now let's get users that are using this
    
    // Chatroom, so people can see who they are talking
    
    function get_users(){
    
    
    
    // Let's get all info from "auth" table
    
    $sql = "SELECT * FROM auth";
    
    $query = mysql_query($sql);
    
    
    
    // Check that everything is fine
    
    if(!$query){
    
    
    
    echo "Can not get users from database.";
    
    
    
    }else{
    
    
    
    // If everything is fine, let's display all users
    
    while($row = mysql_fetch_array($query)){
    
    
    
    echo "<div class='user'>".$row['user']."</div>";
    
    
    
    }
    
    
    
    }
    
    
    
    }
    
    
    
    // Here's the engine that puts everything to work
    
    // All functions are triggered when they are wanted
    
    // For example we want to log our user out
    
    // We put this link to our page: <a href='index.php?act=logout'>Log out</a>
    
    // And as you see when "act" isn't empty and "act" is "logout"
    
    // Let's trigger logout() function that logs our user out
    
    // Everything works the same with other functions
    
    
    
    $act = addslashes(htmlentities(htmlspecialchars($_GET['act'])));
    
    
    
    if($act != "" && $act == "logout"){
    
    
    
    logout();
    
    
    
    }elseif($act != "" && $act == "login"){
    
    
    
    process_login();
    
    
    
    }elseif($act != "" && $act == "post"){
    
    
    
    post_message();
    
    
    
    }elseif($act != "" && $act == "getmessages"){
    
    
    
    get_messages();
    
    exit;
    
    
    
    }elseif($act != "" && $act == "getusers"){
    
    
    
    get_users();
    
    exit;
    
    
    
    }
    
    
    
    ?>
    

    process.js

    // If page is loaded let's load our functions
    
    $(function(){
    
    
    
    // If submit button has been clicked
    
    $("#submitbutton").click(function(){
    
    
    
    // Let's get what user has entered to the text field
    
    var message = $("#text").val();
    
    
    
    // Now let's post this text
    
    $.post("includes/actions.php?act=post", {
    
    
    
    text: message
    
    
    
    });
    
    
    
    // When user's text is posted
    
    // Remove it from the text field 
    
    $("#text").attr("value", "");
    
    
    
    return false;
    
    
    
    });
    
    
    
    // Now let's load our messages
    
    function load_messages(){
    
    
    
    // Let's use AJAX to get them from our actions file
    
    $.ajax({
    
    
    
    url: "includes/actions.php?act=getmessages",
    
    cache: false,
    
    success: function(html){
    
    
    
    // Let's get old posts from there
    
    // Where user's posts are shown
    
    $("#chatscreen").html(html); 
    
    
    
    // Now let's get this area's height where
    
    // All posts are displayed and then let's animate
    
    // It little bit so the scrollbar is always 
    
    // Scrolled down so you can see the new posts 
    
    var newheight = $("#chatscreen").attr("scrollHeight") - 20;
    
    
    
    $("#chatscreen").animate({ scrollTop: newheight }, 'fast'); 
    
    
    
    },
    
    
    
    });
    
    
    
    }
    
    
    
    // Now let's load chatroom's active users 
    
    function load_users(){
    
    
    
    // Let's use AJAX also to get chatroom's users
    
    $.ajax({
    
    
    
    url: "includes/actions.php?act=getusers",
    
    cache: false 
    
    
    
    });
    
    
    
    }
    
    
    
    // Now let's set the time when we will
    
    // Check for new messages and new users
    
    // First, we set the time of our posts
    
    // setInterval(load_messages, 500) loads our posts every 0.5 seconds
    
    // setInterval(load_users, 5000) loads our posts every 5 seconds
    
    setInterval(load_messages, 500);
    
    setInterval(load_users, 5000); 
    
    
    
    });
    

    index.php

    <?php
    
    
    
    // Let's start session and let's include our files
    
    session_start();
    
    include("includes/config.php"); 
    
    include("includes/actions.php");
    
    
    
    ?>
    
    
    
    <!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" xml:lang="en" lang="en">
    
    
    
    <head>
    
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    
    <title>Sugar Chat 1.0</title>
    
    <script src="includes/jquery.js" type="text/javascript"></script>
    
    <script src="includes/process.js" type="text/javascript"></script>
    
    <link href="includes/style.css" rel="stylesheet" type="text/css" />
    
    </head>
    
    
    
    <body>
    
    
    
    <?php
    
    
    
    // Now if our username is "Guest"
    
    // Let's display the login form
    
    if(get_username() == "Guest"){
    
    
    
    echo "<td>"
    
    .login_form()
    
    ."</td>";
    
    
    
    // If it isn't let's display the chatroom 
    
    }else{
    
    
    
    ?>
    
    
    
    <table width="900" border="0" align="center" id="maintable">
    
    <tr>
    
    <td class="tablebottom" colspan="2" id="userbox">
    
    <?php 
    
    
    
    // Let's say greetings to the user and display the "Log out link"
    
    echo "Welcome: ".get_username()."! (".get_link().")"; 
    
    
    
    ?>
    
    </td>
    
    </tr>
    
    <tr>
    
    <td align="center" class="tablebottom">
    
    <div id="chatscreen">
    
    
    
    <?php
    
    
    
    // Now here is the same thing that is in actions file
    
    // Let's select all info from "chat" table
    
    $sql = "SELECT * FROM chat";
    
    $query = mysql_query($sql);
    
    
    
    // Little error checking again
    
    if(!$query){
    
    
    
    echo "Can not get messages from database.";
    
    
    
    }else{
    
    
    
    // If everything is good let's display
    
    // User's messages
    
    while($row = mysql_fetch_array($query)){
    
    
    
    echo "<div align='left'>(".$row[time].") "."<b>".$row['user'].":</b> ".$row['text']."</div>";
    
    
    
    }
    
    
    
    } 
    
    
    
    ?>
    
    
    
    </div>
    
    </td>
    
    <td class="middlebox" id="usersbox" rowspan="2">
    
    <div id="onlineusers">
    
    
    
    <?php
    
    
    
    // This is also like in actions file
    
    // Get all info from "auth" table
    
    $sql = "SELECT * FROM auth";
    
    $query = mysql_query($sql);
    
    
    
    // Check for errors
    
    if(!$query){
    
    
    
    echo "Can not get users from database. ".mysql_error();
    
    
    
    }else{
    
    
    
    // If everything is fine
    
    // Let's display active users
    
    while($row = mysql_fetch_array($query)){
    
    
    
    echo "<div class='user'>".$row['user']."</div>";
    
    
    
    }
    
    
    
    }
    
    
    
    ?>
    
    
    
    </div>
    
    </td>
    
    </tr>
    
    
    
    <tr>
    
    <td colspan="2" id="messagebox">
    
    <form action="">
    
    <input type="text" size="129" id="text" name="chattxt" /> <input type="submit" id="submitbutton" value="Send" /> 
    
    </form>
    
    </td>
    
    </tr>
    
    </table>
    
    
    
    <?php
    
    
    
    }
    
    
    
    ?>
    
    
    
    </body>
    
    </html>
    
  7. Hi,

     

    I got a "simple" problem. I use the "textarea" - in My case this is the TinyMCE. Is some possibility that when somebody edit the text on one computer the other people on the other computer see that, and thay can't "open" and edit same text.

     

    Like on Word, only one person can edit same text.

     

    In advanced tnahnk You.

     

    T

  8. I write in htaccess file next:

    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ /index.php?route=$1 [QSA]
    </IfModule>

     

    in PHP file is:

     

    $route = explode("/", trim($_GET["route"], " \t\n\r\0\x0B/"));

     

    so how can I split those variables, to make links in php files?

     

    example

     

    domain.com/content/main/header-of-text/155

     

    content is the content file which is included into index.php

    main is a some group of texts (name is stored in database - joined tables)

    header-of-text is a header of the text stored in database - just writed

    155 is the ID of text

     

    without rewriting thats looks like domain.com?route=content&textgroup=7&id=155

     

    ...or am a totaly wrong... :(

  9. I can't find how can I validate (confirm) password width jQuery without submit. Mean, when I type the password confirmation to see immediatly is correct or not.

     

     

    <input type="password" name="password" autocomplete="off" value="password" maxlength="12" />
    <input type="password" name="password" autocomplete="off" value="passwordconfirm" maxlength="12" />

     

     

    I can't find script without submit form....

  10.  

    If you want to convert your array to the database you'll first need to add the username/passwords to the users table. You will also want to encrypt the users password too. 

    // connect to database
    
    $LOGIN_INFORMATION = array(
      'zubrag' => 'password',
      'test' => 'testpass',
      'admin' => 'passwd'
    );
    
    // loop through the $LOGIN_INFORMATION array add each username/password to the users table
    foreach($LOGIN_INFORMATION as $username => $password)
    {
         $username = mysql_real_escape_string($username); // sanitize the username	
         $password = md5($password); // encrypt users password. Never store passwords as plain text
    
         // insert into table
         mysql_query('INSERT INTO users (users_username, users_password) VALUES('$username', '$password');
    }
    

    Once the users have been added to the database you can delete that code.

     

    For logging in the user. The code would be

    $username = mysql_real_escape_string($request['users_username']); // sanitize username
    $password = md5($request['users_password']); // encrypt users password.
    
    // query the database. Find record that matches the username and password hash
    $result = mysql_query("SELECT users_id, users_username FROM `users` WHERE users_username = '$username' AND users_password = '$password' LIMIT 1");
    // check query executed
    if($result)
    {
          // check that the query returned any results
          if(mysql_num_rows($result))
        {
            // username/password matched.
            // set cookie/session so user stays logged in.
        }
        else
        {
            // no rows return. Display login error message
            echo 'Sorry username/password invalid';
        }
    }
    else
    {
        // something wrong. Query didn't execute probably due to an error
        echo 'Database error: ' . mysql_error();
    }

    Thanks Ch0cu3r, very nice explaination! And its work fine.

  11. Hi,

     

    I got a problem. I have an array, list of users (and passwords). But it is an Array and I must enter a names and passwords "manually". I want to change that array to query...

     

    Array is:

     

    $LOGIN_INFORMATION = array(
      'zubrag' => 'password',
      'test' => 'testpass',
      'admin' => 'passwd'
    );

     

    so I want to chage it:

    $QueryReturn = mysql_query(' SELECT * FROM `users` WHERE ORDER BY `users_username` ASC ');
    if(!$QueryReturn){ echo mysql_error(); exit; }
     
    while($request = mysql_fetch_array($QueryReturn))
    {
    ///
    }
    

    $request['users_username']

    $request['users_password']

    this two variables is what can change in array...

    So, I dont know how can I replase with Query the Array.

     

    Thanks in advanced

    T

  12. With firebug I find that the Getlist is working, but the update is not working, in Dreamweaver is a syntax error, but I don't know what is the problem....

     

    Somewhere here....

     

    <script type="text/javascript">
    $(document).ready(function () {
      function reload() {
        $("#content").load("update.php");
      }
      setTimeOut(reload, seconds*1000)
    }
    </script>
    
  13. The first script need to update the update.php file every X second - update from session ( $_SESSION['reg_nick'] )

    and this is a first problem, that don't update, and I don't know where is a problem

     

    javascript:

     

     

    <script type="text/javascript">
    $(document).ready(function () {
      function reload() {
        $("#content").load("update.php");
      }
      setTimeOut(reload, seconds*1000)
    }
    </script>
    

     

    php

     

     

    <?php
    session_start();
    
            mysql_query(' UPDATE `users` SET
            `lastActiveTime` = NOW()
            WHERE
            `reg_nick` = "' . $_SESSION['reg_nick'] . '"
            ') or die(mysql_error());
    
    ?>
    

     

    The second script need to reload from getList.php the users who is online:

     

    javascript:

     

     

    <script type="text/javascript">
        setInterval("getList()", 10000) // Get users-online every 10 seconds
    
    function getList() {
      $.post("getList.php", function(list) {
        $("#listBox").html(list);
      });
    }
    </script>
    

     

    php;

     

     

    <?php
    session_start();
    if (!$_SESSION["reg_nick"]) {
      die; // Don't give the list to anybody not logged in
    } else {
    $users = mysql_query('SELECT * FROM `users` WHERE `lastActiveTime` > NOW()-60 ') or die(mysql_error());
    $output = "<ul>";
    while($row=mysql_fetch_array($users))
    {
    $output .= "<li>".$row["reg_nick"]."</li>";
    }
    $output .= "</ul>";
    print $output;
    }
    ?>
    

     

    So, at the end in index.php file, where is the <div id="listBox"></div> I want to see the list of online users. I didn't say that will be a simple chat, and I didn't do something like this before...

     

    I'm sorry, I'm omitted to put scripts in CODE...

     

  14. The first script need to update the update.php file every X second - update from session ( $_SESSION['reg_nick'] )

    and this is a first problem, that don't update, and I don't know where is a problem

     

    javascript:

     

     

    <script type="text/javascript">
    $(document).ready(function () {
      function reload() {
        $("#content").load("update.php");
      }
      setTimeOut(reload, seconds*1000)
    }
    </script>

     

     

    php

     

     

    <?php
    session_start();

            mysql_query(' UPDATE `users` SET
            `lastActiveTime` = NOW()
            WHERE
            `reg_nick` = "' . $_SESSION['reg_nick'] . '"
            ') or die(mysql_error());

    ?>

     

     

    The second script need to reload from getList.php the users who is online:

     

    javascript:

     

    <script type="text/javascript">
        setInterval("getList()", 10000) // Get users-online every 10 seconds

    function getList() {
      $.post("getList.php", function(list) {
        $("#listBox").html(list);
      });
    }
    </script>

     

     

    php;

     

     

    <?php
    session_start();
    if (!$_SESSION["reg_nick"]) {
      die; // Don't give the list to anybody not logged in
    } else {
    $users = mysql_query('SELECT * FROM `users` WHERE `lastActiveTime` > NOW()-60 ') or die(mysql_error());
    $output = "<ul>";
    while($row=mysql_fetch_array($users))
    {
    $output .= "<li>".$row["reg_nick"]."</li>";
    }
    $output .= "</ul>";
    print $output;
    }
    ?>

     

     

    So, at the end in index.php file, where is the <div id="listBox"></div> I want to see the list of online users. I didn't say that will be a simple chat, and I didn't do something like this before... :(

     

     

  15. Hi,

     

    I want to see who is online in chat, but as I see dont work scripts (mixed Ajax and PHP). I got 3 files.

     

    index.php (in header)

     

    <script type="text/javascript">
    $(document).ready(function () {
      function reload() {
        $("#content").load("update.php");
      }
      setTimeOut(reload, seconds*1000)
    }
    </script>
    
    <script type="text/javascript">
        setInterval("getList()", 10000) // Get users-online every 10 seconds
    
    function getList() {
      $.post("getList.php", function(list) {
        $("#listBox").html(list);
      });
    }
    </script>
     
    (in body)
    <div id="listBox"></div>
     
    

     

     

    update.php

     

    <?php
    session_start();
    
            mysql_query(' UPDATE `users` SET
            `lastActiveTime` = NOW()
            WHERE
            `reg_nick` = "' . $_SESSION['reg_nick'] . '"
            ') or die(mysql_error());
    
    ?>
     
    

     

    getList.php

     

     

    <?php
    session_start();
    if (!$_SESSION["reg_nick"]) {
      die; // Don't give the list to anybody not logged in
    } else {
    $users = mysql_query('SELECT * FROM `users` WHERE `lastActiveTime` > NOW()-60 ') or die(mysql_error());
    $output = "<ul>";
    while($row=mysql_fetch_array($users))
    {
    $output .= "<li>".$row["reg_nick"]."</li>";
    }
    $output .= "</ul>";
    print $output;
    }
    ?>
     
    

     

    Thanks in advanced for help

  16. Hi,

     

    I walt to use a two diffferent form tags with same name. This is a slect tag and input (text) tag. But I dont know how can I do do that.

    Why?

     

    Because if something cant find in selecton to add in "input" tag. Is that posibble somehow?

     

    <fieldset class="input_form">
    <legend>Már bevitt zeneszámok listázása:</legend>
    <?php
    $QueryReturn_selected = mysql_query(' SELECT * FROM `zeneszamok` WHERE `zeneszamok_id` = "' . $zene_id . '" ');
    if(!$QueryReturn_selected){ echo mysql_error(); exit; }
    $request_selected = mysql_fetch_array($QueryReturn_selected);
    
    if($request_selected['zeneszamok_id']) {
    $selected_id = $request_selected['zeneszamok_id'];
    $selected_view = $request_selected['zeneszamok_zeneszam'];
    } else {
    $selected_id = '0';
    $selected_view = 'Válassz egy már beírt zeneszámot';
    }
    ?>
    <article><select name="zeneszamok_zeneszam">
    <option selected="selected" value="<?php echo $selected_id;?>"><?php echo $selected_view;?></option>
    <?php
    $QueryReturn_select = mysql_query(' SELECT * FROM `zeneszamok` WHERE `zeneszamok_datum` = "' . $datum . '" ');
    if(!$QueryReturn_select){ echo mysql_error(); exit; }
    while($request_select = mysql_fetch_array($QueryReturn_select)) {
    ?>
    <option value="<?php echo $request_select['zeneszamok_id'];?>"><?php echo $request_select['zeneszamok_zeneszam'];?></option>
    <?php }?>
    </select></article>
    </fieldset>
    </article>
    
    
    
    <article style="height: 20px;"><!-- distancer --></article>
    
    <!-- UJ ZENESZAM -->
    <article id="auto">
    <fieldset class="input_form">
    <legend>Új zeneszám bevitele:</legend>
    <input style="width: 98%;" type="text" id="zeneszamok_zeneszam" name="zeneszamok_zeneszam" value="<?php echo $vanezeneszam;?>" />
    </fieldset>
    </article>
    <!-- END UJ ZENESZAM -->
    

     

    on simplest way:

     

    <select name="name">
    <option selected="selected"></option>
    <option></option>
    </select>
    
    <input type="text" name="name" />
    

  17. Hi,

    I got a php script (downloaded from some site) and this is the part of scripts to autocomplete results. The result give to me all results in same color. I want to some results to see in other colors. In table I have a row "onoff", where have a 1 (on) and 0 (off) So I want to listed results with 0 (off) to see in red color.

     

    here is the php code:

     

    $result = mysql_query("SELECT `zeneszamok_zeneszam`, `zeneszamok_onoff` FROM `zeneszamok` ");
    while ($row = mysql_fetch_assoc($result)) {
    $finals[]=$row['zeneszamok_zeneszam'];
    
    }
    mysql_free_result($result);
    mysql_close($link);
    
    
    // check the parameter
    if(isset($_GET['part']) and $_GET['part'] != '')
    {
    // initialize the results array
    $results = array();
    
    // search colors
    foreach($finals as $final)
    {
    
    // if it starts with 'part' add to results
    if( strpos($final, $_GET['part']) === 0 ){
    $results[] = $final;
    }
    }
    
    
    // return the array as json with PHP 5.2
    echo json_encode($results);
    }
    

     

     

     

     

    Thanks in advanced

  18. Hi, I got a problem.

    I use the html5 and <video> tag. List 2 videos from database, and happen some interesting thing. Please look at the site, maybe well be easier to explain: http://k23tv.com/index.php?lg=sr&c=list_musorok&slider_none=true

     

    The first video looks like this:

    <video width="286" height="240" class="sublime" controls poster="video_musorok/1_musorok_poster.png">

    <source src="video_musorok/1_musorok.mp4" type="video/mp4" codecs="avc1.42E01E, mp4a.40.2">

    <source src="video_musorok/1_musorok.webm" type="video/webm" codecs="vp8, vorbis">

    <source src="video_musorok/1_musorok.ogv" type="video/ogg" codecs="theora, vorbis">

    </video>

     

    the second:

    <video width="286" height="240" class="sublime" controls poster="video_musorok/2_musorok_poster.png">

    <source src="video_musorok/2_musorok.mp4" type="video/mp4" codecs="avc1.42E01E, mp4a.40.2">

    <source src="video_musorok/2_musorok.webm" type="video/webm" codecs="vp8, vorbis">

    <source src="video_musorok/2_musorok.ogv" type="video/ogg" codecs="theora, vorbis">

    </video>

     

    As You see there is a different sources, but if You play the second video, that will play first the first video, than a second... I cant find where is a problem????

     

    Thanks in advanced.

  19. Hi,

     

    I have a strange problem.

     

    1. When I want to put a text with some quotation marks in database, I have an error message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ...

     

    2. When I use a mysql_real_escape_string() the string (text) goes into database (I see it in phpmyadmin) as quot;TXTquot; - but I can't reload it back.

     

    3. When I put into database like this: quot;TXTquot; - than in phpmyadmin looks like this &quot;TXT&quot; - and I can reload it in format "TXT"

     

    I don't understand what is the problem, why can I put a text simple in format "TXT".

     

    In database I use utf-8bin collation.

     

    thnx.

     

    T

     

     

     

  20. I got another problem. It is a counting characters.

    When I reload text from database, I want to count how many characters are in text. The problem is that I use the timymce, and there is a tags </p> and formats <span> and other formats. How can I count characters without those format, just pure characters entire text? I need a php code. And some plus - text is in utf8 coding in database with utf8 bin.

  21. The code you posted... It has nothing to do with putting stuff into the database. Isn't that where the problem really is? Getting it into the database?

     

     

    You right requinix the code don't work :( I found it somewhere on internet... but it seems not work... Do You have som script to change quotes - "" to „” (ALT + 0132, ALT+0148) and ' to ’ and two spaces to one space and the ALT + 0150 to ALT 0151?

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.