问题
I am writing PHP code for a web page that displays the first and last name of someone and the prayer request that was submitted for them. The idea of the page is that an admin can come in and edit the prayer request to correct typos, misspelled words, etc. I am getting the database to populate the fields no problem. The problem I am having is that when I click the "Approve Prayer Request" button I receive a "page not found" error and the info that I edited does not update within the database. Any suggestions would be extremely helpful. Thanks.
This file is named ApproveDenyPrayerRequest.
<?php
$username="XXXXX";
$password="XXXXX";
$database="XXXXX";
$link = mysqli_connect('XXXXXXX', $username, $password, $database);
if (!$link) {
die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
}
echo 'Success... ' . mysqli_get_host_info($link) . "\n";
$query = "SELECT * FROM Request";
$result = mysqli_query($link,$query); //<----- Added link
$row = mysqli_fetch_array($result);
?>
<form method="post" action="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="phone" value="<? echo "$row[Reg_Request]" ?>"></td>
</tr>
</table>
<input name="add" type="submit" id="add" value="Approve Prayer Request">
</form>
Here's the second CGI file which contains the actual mySQLi calls. This file is named PrayerRequest
<?php
$username="XXXX";
$password="XXXXXXX";
$database="prayer";
mysqli_connect('hostname',$username,$password,$database);
@mysqli_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM Request";
$query2="UPDATE Request (Reg_F_Name,Reg_L_Name,Reg_Request)";
VALUES ("$row[Reg_F_Name]","$row[Reg_L_Name]","$row[Reg_Request]")
$result = mysqli_query($query);
$row = mysqli_fetch_array($result);
?>
<form method="post" action="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="phone" value="<? echo "$row[Reg_Request]" ?>"></td>
</tr>
</table>
</form>
回答1:
We need to know to directory structure. For this script to be working you need to create a folder called "cgi-bin" at the same level as this script file and then you need to place "ApproveDenyPrayerRequest.php" in that folder.
if cgi-bin is already exist you need to supply the correct path i.e. if it is one lvl up try: "../cgi-bin/ApproveDenyPrayerRequest.php" or just use the absolute URL
来源:https://stackoverflow.com/questions/23036868/button-that-makes-changes-to-information-within-database