Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 13

Discussione: php e mysql

  1. #1

    php e mysql


    ho installato un guestbook con mysql su xyz...
    però mi da errore....

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\Inetpub\webs\rosannatursiit\public\guestbook\in dex.php on line 76

    lo script index è il seguente

    <?php

    require('inc/config.php');
    $result = mysql_query('SELECT `id`, `name`, `message`, `time` FROM `posts` ORDER BY id DESC');
    ++$queries;

    function splitString($string) {
    $stringArray = explode(' ', $string);
    foreach ($stringArray as $word) {
    $newString .= chunk_split($word, 50);
    }
    return $newString;
    }

    ?>

    <!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>Ajax PHP/MySQL Guestbook</title>
    <link href="inc/style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">

    function toggle(str, str2) {
    document.getElementById(str).style.display = 'none';
    document.getElementById(str2).style.display = 'block';
    }

    function checkPost() {
    var ajax = new XMLHttpRequest();
    ajax.onreadystatechange=function() {
    if (ajax.readyState==4) {
    var buffer = document.getElementById('messageWrap').innerHTML;
    if (ajax.responseText.search('&&error') != -1) {
    document.getElementById('error').innerHTML = ajax.responseText;
    } else {
    document.getElementById('messageWrap').innerHTML = ajax.responseText + buffer;
    document.getElementById('error').innerHTML = '';
    }
    }
    }
    ajax.open('GET', 'check.php?name=' + document.getElementById('name').value + '&message=' + document.getElementById('message').value, true);
    ajax.send(null);
    }

    </script>
    </head>

    <body>

    <div id="header">
    Ajax PHP/MySQL Guestbook
    </div>

    <div id="main">

    <div id="addMessage">


    Add a message!</p>
    </div>

    <div id="inputBox">
    <form action="" method="post" name="go">


    <input id="name" name="name" type="text" /> <label for="name">Name</label>*</p>


    <textarea id="message" name="message" type="textarea" cols="60" rows="3"></textarea> <label for="message">Message</label>*</p>


    <input type="button" value="Post" onclick="javascript:checkPost()" /> * = Required <div id="notice"></div></p>
    </form>
    </div>

    <div id="error"></div>

    <div id="messageWrap">

    <?php

    if (mysql_num_rows($result) == 0) {

    ?>

    <div class="messageBox" style="padding: 10px 10px;">
    No messages have been posted. Why not post one!
    </div>

    <?php

    } else {
    while ($row = mysql_fetch_assoc($result)) {

    ?>

    <div class="messageBox">

    <div class="name">
    Posted by <?php echo stripslashes(htmlentities($row['name'])) ?> on <?php echo date('d/m/Y', $row['time']) . ' at ' . date('H:i:s', $row['time']) . ($_SESSION['admin'] === 1 ? ' [Delete]' : '') ?>
    </div>

    <div class="message">


    <?php echo splitString(stripslashes(htmlentities($row['message']))) ?></p>
    </div>

    </div>

    <?php

    }
    }

    ?>

    </div>

    </div>

    <div id="footer">
    Ajax PHP/MySQL Guestbook | Log in | Execution time: <?php echo (microtime() - $start) ?> seconds. MySQL Queries: <?php echo $queries ?>
    </div>

    </body>
    </html>






    dove sto sbagliando????

    chi può controllarmi lo script??? dove devo fare delle modifiche????

    grazie per l'aiuto....

  2. #2
    Utente di HTML.it L'avatar di neroux
    Registrato dal
    Aug 2009
    Messaggi
    1,973
    Cosa contiene config.php?

    www.sitemeer.com » Quando un sito pare irraggiungibile

    Se ti piace ci puoi trovare anche su Facebook

  3. #3

    config.php

    <?php

    // don't touch
    $start = microtime();
    session_start();
    $queries = 0;

    // your MySQL connection settings
    mysql_connect('62.149.150.104', 'xxxxxxx', 'xxxxxxx');
    // your MySQL database name
    mysql_select_db('Sql291315_1');

    // your login username
    $username = '';
    // your login password
    $password = '';

    // some default posting settings
    // minimum length for their name
    $minNameLength = 4;
    //maximum length for their name (limited to 40 by the database)
    $maxNameLength = 20;
    // minimum length for the message
    $minMessageLength = 10;
    // maximum length for the message (limited to 255 by the database)
    $maxMessageLength = 200;

    ?>

  4. #4
    1) If you don't already have one, create a database.

    2) Run the file, "RUN.sql" to create the table required for the posts
    (If you use phpMyAdmin, click on your database,
    followed by "Import" and then locate the included "RUN.sql" file)

    che significa?? che devo fare???

  5. #5
    Utente di HTML.it L'avatar di neroux
    Registrato dal
    Aug 2009
    Messaggi
    1,973
    Okay, allora la connessione ci dovrebbe essere

    Prova

    Codice PHP:
    $result mysql_query('SELECT `id`, `name`, `message`, `time` FROM `posts` ORDER BY id DESC') or exit(mysql_error()); 

    www.sitemeer.com » Quando un sito pare irraggiungibile

    Se ti piace ci puoi trovare anche su Facebook

  6. #6
    Utente di HTML.it L'avatar di neroux
    Registrato dal
    Aug 2009
    Messaggi
    1,973
    Originariamente inviato da montetermiti
    1) If you don't already have one, create a database.

    2) Run the file, "RUN.sql" to create the table required for the posts
    (If you use phpMyAdmin, click on your database,
    followed by "Import" and then locate the included "RUN.sql" file)

    che significa?? che devo fare???
    Ehm, hai creato il database? Quello che hai chiamato Sql291315_1 secondo config.php?

    www.sitemeer.com » Quando un sito pare irraggiungibile

    Se ti piace ci puoi trovare anche su Facebook

  7. #7

    codice php

    dove lo devo inserire questo codice???

    $result = mysql_query('SELECT `id`, `name`, `message`, `time` FROM `posts` ORDER BY id DESC') or exit(mysql_error());


    in index.php????

    a che riga?????

    grazie

  8. #8

    guestbook php

    adesso mi da questo errore...

    Table 'Sql291315_1.posts' doesn't exist

    il file index.php lo ho modificato così...

    <?php

    require('inc/config.php');
    $result = mysql_query('SELECT `id`, `name`, `message`, `time` FROM `posts` ORDER BY id DESC') or exit(mysql_error());
    ++$queries;

    function splitString($string) {
    $stringArray = explode(' ', $string);
    foreach ($stringArray as $word) {
    $newString .= chunk_split($word, 50);
    }
    return $newString;
    }

    ?>

    <!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>Ajax PHP/MySQL Guestbook</title>
    <link href="inc/style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">

    function toggle(str, str2) {
    document.getElementById(str).style.display = 'none';
    document.getElementById(str2).style.display = 'block';
    }

    function checkPost() {
    var ajax = new XMLHttpRequest();
    ajax.onreadystatechange=function() {
    if (ajax.readyState==4) {
    var buffer = document.getElementById('messageWrap').innerHTML;
    if (ajax.responseText.search('&&error') != -1) {
    document.getElementById('error').innerHTML = ajax.responseText;
    } else {
    document.getElementById('messageWrap').innerHTML = ajax.responseText + buffer;
    document.getElementById('error').innerHTML = '';
    }
    }
    }
    ajax.open('GET', 'check.php?name=' + document.getElementById('name').value + '&message=' + document.getElementById('message').value, true);
    ajax.send(null);
    }

    </script>
    </head>

    <body>

    <div id="header">
    Ajax PHP/MySQL Guestbook
    </div>

    <div id="main">

    <div id="addMessage">


    Add a message!</p>
    </div>

    <div id="inputBox">
    <form action="" method="post" name="go">


    <input id="name" name="name" type="text" /> <label for="name">Name</label>*</p>


    <textarea id="message" name="message" type="textarea" cols="60" rows="3"></textarea> <label for="message">Message</label>*</p>


    <input type="button" value="Post" onclick="javascript:checkPost()" /> * = Required <div id="notice"></div></p>
    </form>
    </div>

    <div id="error"></div>

    <div id="messageWrap">

    <?php

    if (mysql_num_rows($result) ==0) {

    ?>

    <div class="messageBox" style="padding: 10px 10px;">
    No messages have been posted. Why not post one!
    </div>

    <?php

    } else {
    while ($row = mysql_fetch_assoc($result)) {

    ?>

    <div class="messageBox">

    <div class="name">
    Posted by <?php echo stripslashes(htmlentities($row['name'])) ?> on <?php echo date('d/m/Y', $row['time']) . ' at ' . date('H:i:s', $row['time']) . ($_SESSION['admin'] === 1 ? ' [Delete]' : '') ?>
    </div>

    <div class="message">


    <?php echo splitString(stripslashes(htmlentities($row['message']))) ?></p>
    </div>

    </div>

    <?php

    }
    }

    ?>

    </div>

    </div>

    <div id="footer">
    Ajax PHP/MySQL Guestbook | Log in | Execution time: <?php echo (microtime() - $start) ?> seconds. MySQL Queries: <?php echo $queries ?>
    </div>

    </body>
    </html>



    install.txt dice così


    1) If you don't already have one, create a database.

    2) Run the file, "RUN.sql" to create the table required for the posts
    (If you use phpMyAdmin, click on your database,
    followed by "Import" and then locate the included "RUN.sql" file)

    3) open the "config.php" file in the "inc" folder, and change the settings to what you prefer

    4) That's it! It should now be working!
    (If not, you can always ask for help by leaving a message at http://ehwtf.com/guestbook/ or emailing me a)






    devo creare qualche tabella nel database???


    come faccio a far partire run.sql????




    lato server devo fare qualcosa per mysql??????



    grazie neurox

  9. #9
    Utente di HTML.it L'avatar di neroux
    Registrato dal
    Aug 2009
    Messaggi
    1,973
    Dove adesso c'è

    $result = mysql_query('SELECT `id`, `name`, `message`, `time` FROM `posts` ORDER BY id DESC');

    www.sitemeer.com » Quando un sito pare irraggiungibile

    Se ti piace ci puoi trovare anche su Facebook

  10. #10
    Utente di HTML.it L'avatar di neroux
    Registrato dal
    Aug 2009
    Messaggi
    1,973

    Re: guestbook php

    Originariamente inviato da montetermiti
    grazie neurox
    :master:


    Ti dirà database non table, no? Devi creare il database con le tabelle dove poi salvi i dati. Se hai phpmyadmin, lo potresti fare eseguendo run.sql con phpmyadmin.

    www.sitemeer.com » Quando un sito pare irraggiungibile

    Se ti piace ci puoi trovare anche su Facebook

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.