Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 15th, 2003, 12:12 PM
Registered User
 
Join Date: Jun 2003
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default updating mysql

I am attempting to update a mysql database using a form in php. The variable doesn't seem to be holding any value or doesn't write anything to the field when (if) the statement is executed. Can someone suggest something?

echo"<tr><td colspan='2'><input type='text' name='accat1' size='20'> $data->accat1</td></tr>";
            if ($accat1 != "")
            {
             $sqlquery = "UPDATE vform_account SET accat1='$accat1' WHERE account_id='$data->account_id'";
                $execute = mysql_query($sqlquery);
                if(!$execute) error_message(sql_error);
            }
Reply With Quote
  #2 (permalink)  
Old July 15th, 2003, 01:12 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are you sure the query is running? What's the error you're getting from MySQL? Have you tried echoing out the query as a debugging measure to see it's what you expect?

I don't see where you set $data->account_id, $data->accat1, or $accat1. It looks like there's an input form that sets $_GET['accat1'] or $_POST['accat1'].


Problems like these are much more likely to be answered when you can give as much information as possible, including any warning/error messages, what debugging steps have you already tried, etc.


Take care,

Nik
http://www.bigaction.org/
Reply With Quote
  #3 (permalink)  
Old August 14th, 2003, 01:44 AM
Authorized User
 
Join Date: Aug 2003
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

as you might already know, the problem of php is that it allows you to write down code almost like you want... but sometimes its behaviour can get erratic for those reasons. to avoid that, you should rather write :

<tr>
  <td colspan="2">
    <input type="textfield" name="accat1" size="20">
    <? echo $data->accat1; ?>
  </td>
</tr>

<?
if ($accat1 != "") {
  $sqlquery = "UPDATE vform_account SET accat1='".$accat1."' WHERE account_id='".$data->account_id."'";
etc.

then, depending on your configuration, you might use the if ($accat1 != "") or will have to use a $_POST['accat1'] (what you should in fact use to avoid people overwriting the value directly in URLs as a $_GET .
note that if you use $_POST, you cannot just test it is != "", but :
if ( ( isset( $_POST['accat1] ) ) && ( $_POST['accat1'] != "" ) ) { ...
i also assume that somewhere in your code before writing down $data->accat1 you have written some $data->setAccat1($accat1) having of course a setAccat1 method in your data class.

from that point, you should be able to at least display your query ( echo $sqlquery ) and test it directly in your db; this will really be helpful for debugging.

besides, although it can work this way, you shouldn't get access to $data->accat1 directly, but really should always use a method to access properties of your classes :
$data->getAccat1()

the two functions would be declared this way in your class:

function getAccat1() { return $this->accat1; }
function setAccat1(theAccat) { $this->accat1 = theAccat; }

hope that will help

php/java developer
NTIC engineer
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MYSQL Prepared Statements for updating failed!? Magi BOOK Beginning Linux Programming, 3rd Edition 1 December 9th, 2007 09:53 AM
updating a text coloum in mysql mark jonas MySQL 2 January 30th, 2007 06:40 AM
updating running changes cs8271506 SQL Server 2005 1 January 11th, 2006 12:49 AM
updating many to many whyulil Classic ASP Databases 4 March 11th, 2004 12:58 PM
Updating dmurray Access 1 June 25th, 2003 05:41 PM



All times are GMT -4. The time now is 09:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.