SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php data not show in output table

    i am making a simple php discussion forum.But when i intert data into database using form input the output data is not shown in output table.i verified that data is enter into database tables sucessfully.on output page the rows increas as data enter but data is not show on that rows...here is the output page code
    PHP Code:
    $host="localhost"; // Host name
    $username=""; // Mysql username
    $password=""; // Mysql password
    $db_name="itinsight"; // Database name
    $tbl_name="forum_question"; // Table name

    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    $sql="SELECT * FROM $tbl_name ORDER BY id DESC";
    // OREDER BY id DESC is order result by descending

    $result=mysql_query($sql);
    ?>

    <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
    <td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
    <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
    <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
    <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
    </tr>

    <?php

     

    // Start looping table row
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
    <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
    <td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td>
    <td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td>
    <td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td>
    <td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td>
    </tr>

    <?php
    // Exit looping and close connection
    }
    mysql_close();
    ?>

    <tr>
    <td colspan="5" align="right" bgcolor="#E6E6E6"><a href="create_topic.php"><strong>Create New Topic</strong> </a></td>
    </tr>


    here is the code of add new discussion

    PHP Code:
    <?php

    $host
    ="localhost"// Host name
    $username=""// Mysql username
    $password=""// Mysql password
    $db_name="itinsight"// Database name
    $tbl_name="forum_question"// Table name

    // Connect to server and select database.
    mysql_connect("$host""$username""$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    // get data that sent from form
    $topic=$_POST['topic'];
    $detail=$_POST['detail'];
    $name=$_POST['name'];
    $email=$_POST['email'];

    $datetime=date("d/m/y h:i:s"); //create date time

    $sql="INSERT INTO $tbl_name(topic, detail, name, email, datetime)VALUES('$topic', '$detail', '$name', '$email', '$datetime')";
    $result=mysql_query($sql);

    if(
    $result){
    echo 
    "Successful<BR>";
    echo 
    "<a href=forum.html>View your topic</a>";
    }
    else {
    echo 
    "ERROR";
    }
    mysql_close();
    ?>
    Last edited by Mittineague; Jun 20, 2014 at 06:31. Reason: reformatting bbcode tags

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,077
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Please be aware that the mysql_* extension is now deprecated as of the current version of PHP and will very likely be removed from the next 5.x version and will likely not be in PHP 6.x (when it eventually is released). You should migrate over to either the mysqli_* extension or to PDO. PDO is a better choice as it doesn't tie you down so much to a particular database server software.

    Once you have migrated you should use Prepared Statements to prevent SQL Injection attacks. Have a read of this article from the PHP manual, it shows how to use prepared statements with PDO and also explains the principle.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i know but at this time i only need to correct this one...please help me

  4. #4
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    772
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    You have short tags in your display table.
    PHP Code:
    <? echo $rows['id']; ?>
    Use full tags.
    PHP Code:
    <?php echo $rows['id']; ?>

  5. #5
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Quote Originally Posted by Drummin View Post
    You have short tags in your display table.
    PHP Code:
    <? echo $rows['id']; ?>
    Use full tags.
    PHP Code:
    <?php echo $rows['id']; ?>
    thanks solved

  6. #6
    SitePoint Member
    Join Date
    Jun 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i created a jike table in my database but my my UPDATE query isnt working what could be the problem it keeps showing syntax error unexpected $affectedrows
    <?php
    try
    { $pdo = new PDO('mysql:host=localhost;dbname=ijdb', 'root', 'googliness');
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->exec('SET NAMES "utf8"');
    $sql = '┌PDATE joke SET jokedate="2014-05-01" WHERE joketext LIKE "%chicken%"'
    $affectedRows = $pdo->exec($sql);
    $ouput = "updated $affectedRows rows.";
    include 'output.html.php';

    }
    catch (PDOException $e)
    {
    $output = 'Error performing update: ' . $e->getMessage();
    include 'output.html.php';
    exit();
    }
    $output= "updated $affectedRows rows.";
    include 'output.html.php';

  7. #7
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    772
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    See if this version works for you.
    PHP Code:
    <?php
    try

        
    $pdo = new PDO('mysql:host=localhost;dbname=ijdb''root''googliness');
        
    $pdo->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
        
    $pdo->exec('SET NAMES "utf8"');
        
        
    $jokedate "2014-05-01";
        
    $joketext "%chicken%";
        
        
    $sql "┌PDATE joke SET jokedate = :jokedate WHERE joketext LIKE :joketext"
        
    $query $pdo->prepare($sql);
        
    $query->bindParam(":jokedate"$jokedate); 
        
    $query->bindParam(":joketext"$joketext); 
        
    $query->execute();             
        
    $affectedRows $query->rowCount();    
        
    $ouput "updated $affectedRows rows.";
        include 
    'output.html.php';

    }
        catch (
    PDOException $e)
    {
        
    $output 'Error performing update: ' $e->getMessage();
        include 
    'output.html.php';
        exit();
    }
        
    $output"updated $affectedRows rows.";
        include 
    'output.html.php';
    ?>


Bookmarks

Posting Permissions

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