Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 15th, 2003, 12:12 PM
Registered User
 
Join Date: Jun 2003
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);
            }
 
Old July 15th, 2003, 01:12 PM
Friend of Wrox
 
Join Date: Jun 2003
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/
 
Old August 14th, 2003, 01:44 AM
Authorized User
 
Join Date: Aug 2003
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.