megz90 Posted March 8, 2008 Share Posted March 8, 2008 hi having problem with a UPDATE records in table if anyone can help please. have a page called view_me.php it just takes a single record from the a MYSQL table and lists off the entry in a html table (<tr><td>... next stage edit_me.php performs a similar task to above but instead of putting entry's in table tr/td it puts it back in a form. ive done this by doing echo "<td><input type=\"text\" name=\"dbFname\" maxlength=\"20\" value=\"{$row['dbFname']}\"/></td>"; its taking the information without any issue but when i update thats where the problem is... when i change the values and press the button to update. if i change a value to a number it is fine, no problem, but if a change a value to a actual name with letters and stuff it spits out a error.. " Unknown column 'me' in 'field list' " 'me' is just what i put in the first name field in the update table. form basic content of the file with the form... <?php include('../db_connection.php'); if (!isset($_SESSION["sess_loggedon"])) { session_start(); } else{ header ('location: index.html'); } $query = ("SELECT * FROM xowner WHERE dbOwnerId='".$_SESSION['sess_loggedon']."'"); $result = mysql_query($query); ?> <div id="main"><p>UPDATE MY DETAILS </p> <?php while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<form name=\"update\" method=\"post\" action=\"update.php\">"; echo "<table align=\"center\">"; echo "<tr>"; echo "<td width=\"50%\">User Name </td>"; echo "<td width=\"50%\">{$row['dbOwnerId']} </td>"; echo "</tr>"; echo " <tr>"; echo " <th>DbFname:</th>"; echo " <td><input type=\"text\" name=\"dbFname\" maxlength=\"20\" value=\"{$row['dbFname']}\"/></td>"; echo " </tr>"; echo " <tr>"; echo " <th>DbLname:</th>"; echo " <td><input type=\"text\" name=\"dbLname\" maxlength=\"20\" value=\"{$row['dbLname']}\"/></td>"; echo " </tr>"; echo " <tr>"; echo " <th>Dbemail:</th>"; echo " <td><input type=\"text\" name=\"dbemail\" maxlength=\"30\" value=\"{$row['dbemail']}\"/></td>"; echo " </tr>"; echo " <tr>"; echo " <th>Dbmainphone:</th>"; echo " <td><input type=\"text\" name=\"dbmainphone\" maxlength=\"11\" value=\"{$row['dbmainphone']}\"/></td>"; echo " </tr>"; echo " <tr>"; echo " <th>Dbotherphone:</th>"; echo " <td><input type=\"text\" name=\"dbotherphone\" maxlength=\"11\" value=\"{$row['dbotherphone']}\"/></td>"; echo " </tr>"; echo " <tr>"; echo " <th>Dbaddress:</th>"; echo " <td><input type=\"text\" name=\"dbaddress\" maxlength=\"40\" value=\"{$row['dbaddress']}\"/></td>"; echo " </tr>"; echo " <tr>"; echo " <th>Dbaddress1:</th>"; echo " <td><input type=\"text\" name=\"dbaddress1\" maxlength=\"40\" value=\"{$row['dbaddress1']}\"/></td>"; echo " </tr>"; echo " <tr>"; echo " <th>Dbcity:</th>"; echo " <td><input type=\"text\" name=\"dbcity\" maxlength=\"20\" value=\"{$row['dbcity']}\"/></td>"; echo " </tr>"; echo " <tr>"; echo " <th>Dbpostcode:</th>"; echo " <td><input type=\"text\" name=\"dbpostcode\" maxlength=\"9\" value=\"{$row['dbpostcode']}\"/></td>"; echo " </tr>"; echo " <tr>"; echo " <th>notes:</th>"; echo " <td><input type=\"notes\" name=\"dbnotes\" size=\"70\" value=\"{$row['dbnotes']}\"></td>"; echo " </tr>"; echo " <tr>"; echo " <th>Dbpassword:</th>"; echo " <td><input type=\"password\" name=\"dbpassword\" value=\"{$row['dbpassword']}\"></td>"; echo " </tr>"; echo " <tr>"; echo " <td width=\"116\"></td>"; echo " <td width=\"156\"><input type=\"submit\" name=\"submit\" value=\"Update\">"; echo " </td>"; echo " </tr>"; echo " </table>"; echo " </form> "; } ?> </div><!-- end id main --> the actual update.php file <?php include('../db_connection.php'); if (!isset($_SESSION["sess_loggedon"])) { session_start(); } else{ header ('location: index.html'); } //$dbOwnerId = $_POST['dbOwnerId']; $dbFname = $_POST['dbFname']; $dbLname = $_POST['dbLname']; $dbemail = $_POST['dbemail']; $dbmainphone = $_POST['dbmainphone']; $dbotherphone = $_POST['dbotherphone']; $dbaddress = $_POST['dbaddress']; $dbaddress1 = $_POST['dbaddress1']; $dbcity = $_POST['dbcity']; $dbpostcode = $_POST['dbpostcode']; $dbnotes = $_POST['dbnotes']; $dbpassword = $_POST['dbpassword']; $query2 = ("UPDATE xowner SET dbFname=$dbFname, dbLname=$dbLname, dbemail=$dbemail, dbmainphone=$dbmainphone, dbotherphone=$dbotherphone, dbaddress=$dbaddress, dbaddress1=$dbaddress1, dbcity=$dbcity, dbpostcode=$dbpostcode, dbnotes=$dbnotes WHERE dbOwnerId='".$_SESSION['sess_loggedon']."'"); //, , dbpassword=$dbpassword mysql_query($query2) or die(mysql_error()); mysql_close(); echo "You have updated your record <a href=\"view_me.php\">Continue</a>"; ?> ive tried a reading a number of tutorials which havent helped in this case. anyone who can take a look please.. thanks. edit: at the mo theres is no validation in the form, should accept any letters or numbers. if u think im going about this wrong please point me in the direction of a decent tutorial (im quite new to php) Link to comment https://forums.phpfreaks.com/topic/95105-phpmysql-update-query-strange-problem/ Share on other sites More sharing options...
Barand Posted March 8, 2008 Share Posted March 8, 2008 string variables in a query should be enclosed in single quotes otherwise SQL treats them as column names ("UPDATE xowner SET dbFname='$dbFname', dbLname='$dbLname', ... etc If numeric, quotes are optional with MySQL Link to comment https://forums.phpfreaks.com/topic/95105-phpmysql-update-query-strange-problem/#findComment-487178 Share on other sites More sharing options...
megz90 Posted March 8, 2008 Author Share Posted March 8, 2008 Barand your a star! ive been staring at this for AGES! thank you very much. i need to make sure the entry validates now. if u have any tips it let me know i was thinking of putting some functions in a function.php and calling it with includes at the top. that way i can use the same function for both the register and this update. is this a good way? Link to comment https://forums.phpfreaks.com/topic/95105-phpmysql-update-query-strange-problem/#findComment-487187 Share on other sites More sharing options...
Barand Posted March 8, 2008 Share Posted March 8, 2008 yes Link to comment https://forums.phpfreaks.com/topic/95105-phpmysql-update-query-strange-problem/#findComment-487208 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.