doushih06137 2014-04-11 01:38
浏览 86

PHP通过文本框访问数据库

I am having a problem with some PHP code that accesses a database. When I attempt to preview the page with the scripts, I am getting the error "Unable to select database". The purpose of this code is to access a prayer database that (with this portion of the code) enables you to edit prayer requests as they are sent in. The code is in two different CGI files. They can be found below.

First CGI File: ApproveDenyPrayerRequest

<table cellpadding="10">
<tr>
<td>First Name</td>
<td>Last Name</td>
<td>Prayer Request</td>
</tr>

<?php

$username="fbc";
$password="xxxxxxxx";
$database="prayer";

mysql_connect('fbcaltusprayerorg'.ipagemysql.com,$username,$password.prayer);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM Request";
$result=mysql_query($query);
mysql_close();

while ($row=mysql_fetch_array($result)){
echo ("<tr><td>$row[Reg_F_Name]</td>");
echo ("<td>$row[Reg_L_Name]</td>");
echo ("<td>$row[Reg_Request]</td>");
echo ("<td><a href=\"cgi-bin/PrayerRequest.php?id=$row[id]\">Edit</a></td></tr>");
}
echo "</table>";

?>

Second CGI File: PrayerRequest

<?php

$username="fbc";
$password="xxxxxxxx";
$database="prayer";

mysql_connect('fbcaltusprayerorg.ipagemysql.com',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM Request"; 
$result = mysql_query($query);
$row = mysql_fetch_array($result);
?>

<form method="post" action="cgi-bin/ApproveDenyPrayerRequest.php" />

<table>

<tr>
<td>First Name:</td>
<td><input type="text" name="first" value="<? echo "$row[Reg_F_Name]" ?>"></td>
</tr>

<tr>
<td>Last Name:</td>
<td><input type="text" name="last" value="<? echo "$row[Reg_L_Name]" ?>"></td>
</tr>

<tr>
<td>Prayer Request</td>
<td><input type="text" name="request" value="<? echo "$row[Reg_Request]" ?>"></td>
</tr>

</table>

</form>

Thanks all for your responses.

  • 写回答

1条回答 默认 最新

  • douzi1986 2014-04-11 01:47
    关注

    Looks like a simple typo with the quote and a misformed string concatenation at the end:

    mysql_connect('fbcaltusprayerorg'.ipagemysql.com,$username,$password.prayer);
    

    Should probably be:

    mysql_connect('fbcaltusprayerorg.ipagemysql.com',$username,$password);
    

    And you should switch to PDO or mysqli as the mysql_* functions are deprecated.

    And if you posted your real password, you should change it right away.

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料