Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP MYSQL update record from database. odd problems...
Old 03-08-2008, 01:32 PM PHP MYSQL update record from database. odd problems...
mez
Junior Talker

Posts: 4
Location: mez_90@hotmail.com
Trades: 0
RESOLVED
thanks for the help

hi all ive had a look through the existing threads re php updates but
im still having problem with a UPDATE records in table if anyone wants to help...

i thought it was working and was very happy but obviously i didnt test it properly did i...
grr.

i have a page called view_me.php
it just takes a record from the owner table and lists off the entry in a html table (<tr><td>...
..not a problem...

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
PHP Code:
echo "<td><input type=\"text\" name=\"dbFname\" maxlength=\"20\" value=\"{$row['dbFname']}\"/></td>"
it takes the info from a $query2 a few lines up...

this is also working alright...
the problem is when i change the values and press the button to update.
if i change a value to a number 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 'test' in 'field list'
'test' is just what i put in the first name field.

form to take fields from db and put them in the form for update
take a look at the <div id main >
PHP Code:
<?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);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- lots of menu and normal html formatting  to layoout the page... -->
      <div id="lownav">
<?php 
echo ("<p>Current user is " $_SESSION["sess_loggedon"]." </p>");
?>
<ul><li><a href="../logout.php">logout</a></li></ul>

        <!-- show username and date -->
      </div>
      <!-- close id lownav -->
    </div>
    <!-- close id col 1-->
    <div id="main"><p>UPDATE MY DETAILS </p>
    <?php
while($row mysql_fetch_array($resultMYSQL_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 -->
  </div>
  <!-- end content -->
</div>
<!-- end id page -->
<div id="foot">footer</div>
<!-- end id foot -->
<br /><div style="z-index:3" class="smallfont" align="center">Content Relevant URLs by vBSEO 3.0.0 &copy;2007, Crawlability, Inc.</div>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-139461-1";
urchinTracker();
</script>
</body>
</html>
the actual update.php file. its not working tho
PHP Code:
<?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>";

?>
as i said it will update a record if the new values are numbers but only numbers but not if i use letters.

Last edited by mez; 03-08-2008 at 03:58 PM.. Reason: RESOLVED
mez is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-08-2008, 03:12 PM Re: PHP MYSQL update record from database. odd problems...
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
It's because you don't use the DB correctly.
I tend to believe that the dbFname, dbLname and so on are string type, aren't they ?

If they are, you must enclose the value between single quotes.
Only integer, boolean and null values can be used without containing them between '

And by the way, you are open to any case of SQL injection.
You should at least trim() and addslashes() any datas you want to save.
Actually, the addslashes is even mandatory, because any single quote in the value you will try to save will crash your query otherwise.

http://www.php.net/manual/en/functio...ape-string.php
http://www.php.net/manual/en/function.trim.php
http://www.php.net/manual/en/function.addslashes.php

and the query should be:
PHP Code:
$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']."'"); 
I've put every fields between single quotes, except the ID. Remove the quotes on those who are not string related.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 03-08-2008, 03:55 PM Re: PHP MYSQL update record from database. odd problems...
mez
Junior Talker

Posts: 4
Location: mez_90@hotmail.com
Trades: 0
hey thanks so much for the reply, it works now,



thanks
mez is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP MYSQL update record from database. odd problems...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.37386 seconds with 12 queries