PDA

View Full Version : PHP Help


MumbleVoice-Jen
22-07-2009, 03:07
Hey everyone,

Well I'm having some trouble, I can't seem to get this edit script to work.

I found a great tutorial and changed it around a lot, and I simply can't figure out the first.

The error I am getting: Query failed: Unknown column 'name' in 'where clause'

My goal is to have it load the information that is in the database and then post it so I can edit the information, once I have changed what I wanted, have it re-submit to the database making the changes.

Edit_Record.php
<html>
<body>
<form name="update_record" action="update.php" method="post">
<table style="margin-bottom: 1px; padding-left:10px;" border="0" cellpadding="0"
cellspacing="1" width="75%">
<tbody>
<tr>
<td align="right" bgcolor="#e9ece9" >Enter Doctor ID to edit: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;" >
<input name="phone" size="20" maxlength="20" value="<? echo $BNAME; ?>">
</td>
</tr>
</tbody>
</table>


<table style="margin-bottom: 1px; padding-left:455px;" border="0" cellpadding="0" cellspacing="1" width="50%">
<tbody>
<tr>
<td colspan="2" align="right" bgcolor="#dadce1" height="4">
<input name="submit" value="submit" type="submit">
</td>
</tr>
</tbody>
</table>

</body>
</html>
Update.php

<?php
#Form Variables.
$BNAME='';

#Database connection strings.
$usr = "#";
$pwd = "#";
$db = "#";
$host = "localhost";

# connect to database
$cid = mysql_connect($host,$usr,$pwd);
mysql_select_db($db);
if (mysql_error()) { print "Database ERROR: " . mysql_error(); }

if(isset($_POST['submit'])){
extract($_POST);

#A query is written which will extract all information
#from basic_info table based on phone number entered.

$query = "SELECT * FROM INFORMATION where name='".$BNAME."'";
#Execute query and store result into variable $result.
#echo $query;
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
$BNAME=$row["name"];
$FAPPOINTMENT=$row["fappoint"];
$SAPPOINTMENT=$row["sappoint"];
$NOMINATION=$row["nomination"];
$NOMINATIONC=$row["nominationc"];
$FINALIST=$row["finalist"];
$FINALISTV=$row["finalistv"];
$NOTESPS=$row["notesps"];
$NOTESND=$row["notesnd"];
$DATE=$row["date"];

}

echo "<form method=\"post\">";
echo "<table style=\"margin-bottom: 1px;\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"60%\">\n";
echo "\t<tr>\n";
echo "\t\t<td bgcolor=\"#dadce1\" colspan=\"2\">Business Name:\t $BNAME</td>";
echo "\t\t<td bgcolor=\"#dadce1\"> <input type=\"hidden\" value='$BNAME' name=\"name\" size=\"50\" ></td>";

echo "\t</tr>\n";

echo "\t<tr>\n";
echo "\t\t<td bgcolor=\"#dadce1\">First Appointment: </td>";
echo "\t\t<td bgcolor=\"#dadce1\"> <input type=\"text\" value='$FAPPOINTMENT' name=\"fappoint\" size=\"50\" ></td>";
echo "\t</tr>\n";

echo "\t<tr>\n";
echo "\t\t<td bgcolor=\"#dadce1\">Second Appointment: </td>";
echo "\t\t<td bgcolor=\"#dadce1\"> <input type=\"text\" value='$SAPPOINTMENT' name=\"sappoint\" size=\"50\"></td>";
echo "\t</tr>\n";

echo "\t<tr>\n";
echo "\t\t<td bgcolor=\"#dadce1\">Nomination Received: </td>";
echo "\t\t<td bgcolor=\"#dadce1\"> <input type=\"checkbox\" value='$NOMINATIONC' name=\"nomination\"></td>";
echo "\t</tr>\n";

echo "\t<tr>\n";
echo "\t\t<td bgcolor=\"#dadce1\">Nomination Congratulations (Letter/Visit): </td>";
echo "\t\t<td bgcolor=\"#dadce1\"> <input type=\"checkbox\" value='$NOMINATIONC' name=\"nominationc\"></td>";
echo "\t</tr>\n";

echo "\t<tr>\n";
echo "\t\t<td bgcolor=\"#dadce1\">Finalist: </td>";
echo "\t\t<td bgcolor=\"#dadce1\"> <input type=\"checkbox\" value='$FINALIST' name=\"finalist\"></td>";
echo "\t</tr>\n";

echo "\t<tr>\n";
echo "\t\t<td bgcolor=\"#dadce1\">Finalist Congratulations Visit: </td>";
echo "\t\t<td bgcolor=\"#dadce1\"> <input type=\"checkbox\" value='$FINALISTV' name=\"finalistv\"></td>";
echo "\t</tr>\n";

echo "\t<tr>\n";
echo "\t\t<td bgcolor=\"#dadce1\">Products Sold: </td>";
echo "\t\t<td bgcolor=\"#dadce1\"> <textarea value='$NOTESPS' name=\"noteps\" rows=4 cols=30></textarea></td>";
echo "\t</tr>\n";

echo "\t<tr>\n";
echo "\t\t<td bgcolor=\"#dadce1\">New Dollars: </td>";
echo "\t\t<td bgcolor=\"#dadce1\"> <textarea value='$NOTESND' name=\"notend\" rows=4 cols=30></textarea></td>";
echo "\t</tr>\n";

echo "\t<tr>\n";
echo "\t\t<td bgcolor=\"#dadce1\">Date of Last Contact: </td>";
echo "\t\t<td bgcolor=\"#dadce1\"> <input type=\"checkbox\" value='$DATE' name=\"date\"></td>";
echo "\t</tr>\n";

echo "</table>\n";

echo "<table style=\"margin-bottom: 1px;\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"40%\">";
echo "<tr>";
echo "<td colspan=\"2\" align=\"right\" bgcolor=\"#dadce1\" height=\"4\">";
echo "<input name=\"submit02\" value=\"submit\" type=\"submit\">";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</form>";
#Free up Memory for $result.

mysql_free_result($result);
#Close database connection.
mysql_close($link);
}
?>
The Database structure is:

$BNAME - varchar(60)
$FAPPOINTMENT - varchar(60)
$SAPPOINTMENT - varchar(60)
$NOMINATION - varchar(60)
$NOMINATIONC - varchar(60)
$FINALIST - varchar(60)
$FINALISTV - varchar(60)
$NOTESPS - text
$NOTESND - text
$DATE - varchar(60)