if/else button switch

  • (2 Pages)
  • +
  • 1
  • 2

24 Replies - 914 Views - Last Post: 12 April 2013 - 11:42 AM Rate Topic: -----

#1 Shado3225  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 325
  • Joined: 23-February 10

if/else button switch

Posted 12 April 2013 - 09:47 AM

Evening all

I'm hoping for some assistance on a script, seems I've taken a wrong turn some where and even though I've made progress I now have the following issue.

I have a button in a if/else statement:

<a class="trigger" href="'.$_SERVER["PHP_SELF"].'?Act=Edit&id='.$info["id"].'" />Edit</a>


when it is clicked the block of code in .row changes to allow the data to be editable in an input field and the edit button changes to submit.

Everything works perfectly except when I click the edit button it does not only change the fields in the row it was clicked on but all the rows.

Any ideas as to how I can rectify this?

if($_GET["id"] !='' && $_GET["Act"] == "Edit"){
// this is what the block of text turns into when the edit button is clicked
<div class="row">
<div>'.$info["id"].'</div>
<input type="hidden" name="id" value="'.$info["id"].'" />
<div><input type="text" name="data_update" value="'.$info["data"].'" /></div>
<div><input name="submit" type="submit" value="Submit" /></div>
</div>				
} else {
// this is the block of code that is shown on the page
<div class="row">
<div>'.$info["id"].'</div>
<div>'.$info["data"].'</div>
<div><a class="trigger" href="'.$_SERVER["PHP_SELF"].'?Act=Edit&id='.$info["id"].'" />Edit</a></div>
</div>				
} 



Thank you ;)

Is This A Good Question/Topic? 0
  • +

Replies To: if/else button switch

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,226
  • Joined: 08-June 10

Re: if/else button switch

Posted 12 April 2013 - 10:00 AM

is there any reason why you don’t do that in Javascript?

other than that, check the HTML and dump $_GET.

EDIT: that code shouldn’t work at all. instead it should cause a Parse Error.

This post has been edited by Dormilich: 12 April 2013 - 10:01 AM

Was This Post Helpful? 0
  • +
  • -

#3 Shado3225  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 325
  • Joined: 23-February 10

Re: if/else button switch

Posted 12 April 2013 - 10:10 AM

View PostDormilich, on 12 April 2013 - 07:00 PM, said:

is there any reason why you don’t do that in Javascript?

other than that, check the HTML and dump $_GET.

EDIT: that code shouldn’t work at all. instead it should cause a Parse Error.


Lol, it works ;)/> I just have not included the whole thing as it is rather big.

Thank you for the suggestions, I will look into it.

I might be wrong but I doubt it's in my html, I have a feeling it might be in the

if($_GET["id"] !='' && $_GET["Act"] == "Edit")


It's suppose to only apply the change to the row that was clicked but some how its applying it to the correct ID.

This post has been edited by Shado3225: 12 April 2013 - 10:17 AM

Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,226
  • Joined: 08-June 10

Re: if/else button switch

Posted 12 April 2013 - 10:13 AM

View PostShado3225, on 12 April 2013 - 07:10 PM, said:

I might be wrong but I doubt it's in my html,

if the HTML is malformed (which I cannot tell from the PHP), the parameters may not be passed correctly.

how come it’s "cid" now?

This post has been edited by Dormilich: 12 April 2013 - 10:14 AM

Was This Post Helpful? 0
  • +
  • -

#5 Shado3225  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 325
  • Joined: 23-February 10

Re: if/else button switch

Posted 12 April 2013 - 10:19 AM

View PostDormilich, on 12 April 2013 - 07:13 PM, said:

View PostShado3225, on 12 April 2013 - 07:10 PM, said:

I might be wrong but I doubt it's in my html,

if the HTML is malformed (which I cannot tell from the PHP), the parameters may not be passed correctly.

how come itís "cid" now?


Sorry typo!

If you have the time I can send you the link to the live version then you can see how it works?
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,226
  • Joined: 08-June 10

Re: if/else button switch

Posted 12 April 2013 - 10:20 AM

canít you post the link here? two pairs of eyes certainly see more than one.
Was This Post Helpful? 0
  • +
  • -

#7 Shado3225  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 325
  • Joined: 23-February 10

Re: if/else button switch

Posted 12 April 2013 - 10:26 AM

Sure thing ;)
I know some forums don't like link posting as the links never stay relevant to the post.

my test file
Was This Post Helpful? 0
  • +
  • -

#8 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,226
  • Joined: 08-June 10

Re: if/else button switch

Posted 12 April 2013 - 10:32 AM

well, the Edit button has a "cid" Ö
Was This Post Helpful? 0
  • +
  • -

#9 Shado3225  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 325
  • Joined: 23-February 10

Re: if/else button switch

Posted 12 April 2013 - 10:35 AM

View PostDormilich, on 12 April 2013 - 07:32 PM, said:

well, the Edit button has a "cid" Ö


Yes yes, on the file it is cid but in the post it is id - I thought it would help make it clearer that cid stood for ID.
Was This Post Helpful? 0
  • +
  • -

#10 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,226
  • Joined: 08-June 10

Re: if/else button switch

Posted 12 April 2013 - 10:38 AM

well, $_GET["cid"] and $_GET["id"] are two different things. you explicitly test if there is a value for "id", no "id" (but "cid"), no value, no condition.
Was This Post Helpful? 0
  • +
  • -

#11 Shado3225  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 325
  • Joined: 23-February 10

Re: if/else button switch

Posted 12 April 2013 - 10:46 AM

Ok, but on the actual file I cant use $_GET["id"] cause the column in the mysql is named cid or am I misunderstanding you?
Was This Post Helpful? 0
  • +
  • -

#12 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,226
  • Joined: 08-June 10

Re: if/else button switch

Posted 12 April 2013 - 10:55 AM

a bit, though it has nothing to do with MySQL.

if your URL is /myStudies/test/test.php?Act=Edit&cid=21 then $_GET["id"] != "" will be false.

though I would recommend the use of filter functions:
$cid = filter_input(INPUT_GET, "cid", FILTER_VALIDATE_INT, array('options' => array('min_range' => 1)) );
// if cid is incorrect (not passed, not a valid number), $cid will be falsy

Was This Post Helpful? 0
  • +
  • -

#13 Shado3225  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 325
  • Joined: 23-February 10

Re: if/else button switch

Posted 12 April 2013 - 11:00 AM

Ok, now I'm with you.

The only problem, if I change the cid to id my submit button turns into a delete button.
Was This Post Helpful? 0
  • +
  • -

#14 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,226
  • Joined: 08-June 10

Re: if/else button switch

Posted 12 April 2013 - 11:00 AM

and what if you change the id to cid?
Was This Post Helpful? 0
  • +
  • -

#15 Shado3225  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 325
  • Joined: 23-February 10

Re: if/else button switch

Posted 12 April 2013 - 11:06 AM

If I change the id to cid then it also deletes.

Not sure if you can see it but I am using a SELECT, UPDATE, INSERT and DELETE in one form. The delete uses the id and the update uses the cid.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2