Jump to content

Update MySQL database record one bye one, but ................


Kiongkavi

Recommended Posts

Dear all,

        my PHP aims to update a MySQL database by selecting record

one by one and modify then save. let's begin from the very beginning, current behavior is that if initial value from id=99, the UpdMySQL of id=99 will be perform OK

with row 99, but the $cat/$ori in row 100 will also be changed to the

same as row 99.then content("body") of row 99 will be shown

again(thepage keep no change ), although in fact, row 100's id2=1;

then when DelMySQL/UpdMySQL/AgrMySQL is performed, the update fields

go to the next row of the row which content("body") is shown on the

website. In other words, in front end, #K-th record is shown but the update will

go to #(K+1)-th record.

 

<?php

 

//Connect to database

 

        $connect = mysql_connect("andy","kiong","Password")or

die("Could not connect : " . mysql_error()); ;

        mysql_select_db("kiong_userinfo",$connect)or die("Could not

connect : " . mysql_error());

 

// select a record

 

        $result = mysql_query("SELECT * FROM putonServer where id2=1",

$connect);

                $newline = "<br />";

                $row = mysql_fetch_array($result) or die(mysql_error());

                $this_id=mysql_result($result,0,"id");

                $this_body=mysql_result($result,0,"body");

 

//show the content of the record

 

                echo $this_id;

                echo $newline;

                echo $this_body;

?>

 

<HTML>.

<!--Show the webpage, where the content(body field of putonServer) in

the record will be shown,

Three button: Discard(B0),Agree(B1) and Update(B0) will be shown as

well -->

.....<HTML>

 

<?php

 

//Make a deleted mark for the record which should be deleted from the

database

 

function DelMySQL($this_id,$connect)

  {

                $next_id=$this_id+1;

                $query_B0="update putonServer SET id2=7 where id='$this_id'";

        $query_B0_2="update putonServer SET id2=1 where

id='$next_id'";

        $result_B0=mysql_query($query_B0,$connect);

        if (!$result_B0) {

                        die ('Puke, Wrong2 ' . mysql_error());

                        }

        $result_B0_2=mysql_query($query_B0_2,$connect);

        if (!$result_B0_2) {

                        die ('Puke, Wrong ' . mysql_error());

                        }

  }

 

//Make an agree mark for the record which should be kept no change in

the database

 

function AgrMySQL($this_id,$connect)

        {

                $next_id=$this_id+1;

                $query_B0="update putonServer SET id2=7 where id='$this_id'";

        $query_B0_2="update putonServer SET id2=1 where

id='$next_id'";

        $result_B0=mysql_query($query_B0,$connect);

        if (!$result_B0) {

                        die ('Puke, Wrong2 ' . mysql_error());

                        }

        $result_B0_2=mysql_query($query_B0_2,$connect);

        if (!$result_B0_2) {

                        die ('Puke, Wrong ' . mysql_error());

                        }

            echo "Processoooo".$newline;

                echo $this_id;

        }

 

//modify the selected row in a database

function UpdMySQL($this_id,$connect,$cate,$orie)

        {

                $next_id=$this_id+1;

        $query_B2 ="UPDATE putonServer SET

category='$cate',orientation='$orie' where id='$this_id'";

        echo $this_id.$newline;

        $result_B2=mysql_query($query_B2,$connect);

        if (!$result_B2) {

                die ('Puke, Wrong2 ' . mysql_error());

                }

        $query_B2_1="update putonServer SET id2=4 where

id='$this_id'";

        echo $this_id.$newline;

        $query_B2_2="update putonServer SET id2=1 where

id='$next_id'";

        echo $this_id.$newline;

        $result_B2_2=mysql_query($query_B2_2,$connect);

        if (!$result_B2_2) {

                        die ('Puke, Wrong ' . mysql_error());

                        }

        $result_B2_1=mysql_query($query_B2_1,$connect);

        if (!$result_B2_1) {

                        die ('Puke, Wrong2 ' . mysql_error());

                        }

        }

 

// When different button is clicked, do different action on the

database

 

if($_POST[b0]){

        DelMySQL($this_id,$connect);

        }

if($_POST[b1]){

        AgrMySQL($this_id,$connect);

        }

if($_POST[b2]){

        UpdMySQL($this_id,$connect,$_POST[R2],$_POST[sliderinput22]);

        }

?>

 

<Description for the database>

+-------------+------------------+------+-----+---------

+----------------+

| Field      | Type            | Null | Key | Default |

Extra          |

+-------------+------------------+------+-----+---------

+----------------+

| id          | int(11)          |      | PRI | NULL    |

auto_increment |

| id2        | int(11)          |      |    | 0

|                |

| users      | int(10) unsigned |      |    | 0

|                |

| date        | text            | YES  |    | NULL

|                |

| time        | text            | YES  |    | NULL

|                |

| docuname    | text            | YES  |    | NULL

|                |

| body        | text            | YES  |    | NULL

|                |

| orientation | int(11)          |      |    | 0

|                |

| category    | int(11)          |      |    | 0

|                |

+-------------+------------------+------+-----+---------

+----------------+

 

 

Link to comment
Share on other sites

Try printing out your queries.

 

I notice that you print out the values for your queries, but it's much MUCH better to print the queries themselves.  I am particularly suspicious of this code:

 

        $query_B2_2="update putonServer SET id2=1 where
id='$next_id'";
        echo $this_id.$newline;

 

The query uses $next_id, but you echo out $this_id (for debugging?)

Link to comment
Share on other sites

now, at the beginning, it update OK when it initially starts from Record #99,

but after update Record #99 and refresh page,  the content of Record #99 will still be there(shown on the webpage), and in the back end(MySQL database) it is Record #100 where id2=1..

 

the situation following is same:

 

front end(Webpage): Record #K,

back end(MySQL database): Record # K+1,

and the update still on row Record # K+1,

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.