数据检索不起作用 [英] Data retrieval not working
本文介绍了数据检索不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用php从MySql数据库中检索数据,但只提取了检索字段的第一个单词。在检索数据后,我想在textarea(html)控件中显示它。我已经尝试了两种,但似乎没有任何工作。
我的代码是:
<? php
$ con = mysql_connect( 本地主机 根, PRIT am);
if (!$ con)
< span class =code-summarycomment> {
die(可以 不 connect: 。 mysql_error());
}
mysql_select_db(new_blog,$ con);
if(isset($ _ POST ['update']))
{
< span class =code-summarycomment>
< span class =code-summarycomment> $ UpdateQuery = UPDATE user_posts SET title ='$ _ POST [title]',body ='$ _ POST [body]'其中post_id ='$ _ POST [hidden]' ;
< span class =code-summarycomment> < span class =code-summarycomment> mysql_query($ UpdateQuery, $ con);
echo < script type =' text / javascript' > alert('成功修改后发布')< / script > ;
};
if(isset($ _ POST ['delete']))
{
$ DeleteQuery =DELETE FROM user_posts where post_id ='$ _ POST [hidden]';
mysql_query($ DeleteQuery,$ con);
echo< script 类型 =' text / javascript' > alert('发布成功删除')< / script > ;
};
$ sql =SELECT * FROM user_posts;
$ myData = mysql_query($ sql,$ con);
echo< table id = blog_post >
< tr >
< th style =' font-size:25px;' > 标题< / th >
< th < span class =code-attribute> style =' font-size:25px;' > 正文< / th >
< th colspan = 2 style =' font-size:25px;' > 操作< / th >
< / tr > ;
while($ record = mysql_fetch_array($ myData))
{
echo< 表格 action = Add_Update_Delete_Post.php 方法 = 发布 > ;
echo< tr > < /跨度>;
echo< td > 。 < 输入 type =' text' 样式 =' width: 300px;高度:30px;字体大小:18px;' 名称 =' title' 值 = 。 $ record ['title']。 / > < / td > ;
echo< td > 。 < textarea 行 = 10 cols = 60 名称 =' body' value = 。 $ record ['body']。 / > < / textarea > < / td > ;
echo< td > 。 < 输入 type =' submit' 名称 =' update' value =' < span class =code-keyword>修改' style =' width:200px; height:35px; font-size:16px;' > ; 。 < / td > ;
echo< td > 。 < 输入 type =' submit' 名称 =' delete' value =' < span class =code-keyword>删除' style =' width:200px; height:35px; font-size:16px;' > ; 。 < / td > ;
echo< td > 。 < 输入 type =' hidden' 样式 =' border: 0;' 名称 =' hidden' value = 。 $ record ['post_id']。 < / td > < /跨度>;
echo< / tr > 跨度>;
echo< / form > 跨度>;
}
echo< / table > 跨度>;
mysql_close($ con);
?>
解决方案
con = mysql_connect( localhost,root,pritam);
if < span class =code-summar ycomment> (!
con)
{
die(可以 < span class =code-summarycomment> not connect: 。 mysql_error());
}
< span class =code-summarycomment> mysql_select_db(new_blog,
>
con);
如果(isset(
I am trying to retrieve data from MySql database using php but only the first word of the retrieved field is extracted. Also after retrieving the the data I want to display it in the textarea(html) control. I've tried both but nothing seems to be working.
My code is:
<?php
$con= mysql_connect("localhost","root","pritam");
if (!$con)
{
die("Can not connect: " . mysql_error());
}
mysql_select_db("new_blog",$con);
if(isset($_POST['update']))
{
$UpdateQuery = "UPDATE user_posts SET title='$_POST[title]', body='$_POST[body]' where post_id='$_POST[hidden]'";
mysql_query($UpdateQuery, $con);
echo "<script type='text/javascript'> alert('Post Successfully Modified') </script>";
};
if(isset($_POST['delete']))
{
$DeleteQuery = "DELETE FROM user_posts where post_id='$_POST[hidden]'";
mysql_query($DeleteQuery, $con);
echo "<script type='text/javascript'> alert('Post Successfully Deleted') </script>";
};
$sql = "SELECT * FROM user_posts";
$myData = mysql_query($sql,$con);
echo "<table id=blog_post >
<tr>
<th style='font-size:25px;'>Title</th>
<th style='font-size:25px;'>Body</th>
<th colspan=2 style='font-size:25px;'>Operation</th>
</tr>";
while($record = mysql_fetch_array($myData))
{
echo "<form action=Add_Update_Delete_Post.php method=post>";
echo "<tr>";
echo "<td>" . "<input type='text' style='width:300px; height:30px; font-size:18px;' name='title' value=" . $record['title'] . "/> </td>";
echo "<td>" . "<textarea rows=10 cols=60 name='body' value=" . $record['body'] . " /></textarea></td>";
echo "<td>" . "<input type='submit' name='update' value='Modify' style='width:200px; height:35px; font-size:16px;'>" . " </td>";
echo "<td>" . "<input type='submit' name='delete' value='Delete' style='width:200px; height:35px; font-size:16px;'>" . " </td>";
echo "<td>" . "<input type='hidden' style='border:0;' name='hidden' value=" . $record['post_id'] . " </td>";
echo "</tr>";
echo "</form>";
}
echo "</table>";
mysql_close($con);
?>
解决方案
con= mysql_connect("localhost","root","pritam"); if (!
con) { die("Can not connect: " . mysql_error()); } mysql_select_db("new_blog",
con); if(isset(
这篇关于数据检索不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文