doutui6644 2012-11-15 10:04
浏览 32

无法从MySQL DB检索文本

i've created a simple blog system which connects to my DB and retrives information from a db named login and a table named news. The problem is that it doesn't post the info even though it connects. Heres my code:

<html>
<?php
$host = '127.0.0.1';
$user = 'root';
$password = 'ascent';
$webdb = 'login';
$newstable = 'news';

$con = mysql_connect($host,$user,$password); 
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

if (isset($_GET['newsid']))
{
    $id = (int)$_GET['newsid'];
    mysql_select_db($webdb);

    $result = mysql_query("SELECT * FROM news WHERE id='".$id."'");
    $row = mysql_fetch_assoc($result); ?>
    <div class='box_two_title'><?php echo $row['title']; ?></div>

    <?php 
    echo $row['body'];
    }
    ?>
Hello
</html>

Thank you for all your helpful answers so far but it still doesn't post :S

  • 写回答

4条回答 默认 最新

  • dousi2029 2012-11-15 10:09
    关注

    Is your error reporting off?? connect::selectDB('webdb') should throw an error. And additionally, you set host,db name in variables and while connecting you put them in quotes. Why?

    connect::selectDB('webdb'); 
    

    should be

    mysql_select_db($webdb);
    

    And

    $con = mysql_connect("$host","$user","$password");
    

    should be

    $con = mysql_connect($host,$user,$password); 
    
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法