Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Newbie looking for some help and tips

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Newbie looking for some help and tips

Postby Mattyp77 » Sun Oct 21, 2012 3:28 pm

Hello. Im Matt and I am just discovering the world of PHP and of coarse just registered to this forum.
Although PHP is new to me, coding in general is not. I learned HTML on my own and in school took classes for QBasic. The language is not completely foreign to me. Although QBasic is ancient a lot of the code is very similar. This stuff comes naturally to me.
Im so glad I discovered what PHP is all about. It allows me to do all the things I never though I would be able to do.

Now that I introduce myself Ill get down to the problems Im having. I feel that the code I wrote is in proper syntax. I dont understand why it isnt working. Im sure it is spagetti code but Im still learning and experiment..

Im having trouble getting functions and $_GET to work properly or at all really...

function gofoward()
{ echo "NEXT"; }
function goback()
{ echo "BACK"; }

$action = $_GET['action'];

if ($action = "next")
{ gofoward(); }
elseif ($action = "back")
{ goback(); }
else {}
<! -------HTML CODE-Website-Content----->
<a href="samepage.php?action=back">Back</a>
<a href="samepage.php?action=next">Next</a>
**The goal is to display a new image on the page by clicking "Next" or Back"
**But this is only test code to see if its working properly and its not.
**The page automatically displays "NEXT" from inside the function regardless of the value of
**the $action var which I do not believe is even being assigned its value from $_GET at all
**Another issue Im having and dealing with a 3 digit variable to correspond with my image gallery.
**EX: 000.jpg + 005.jpg + 010.jpg + 115.jpg
**I want to be able to add/subtract the number in a variable while always keeping it at 3 digits.
$dig1 = 0;
$dig2 = 0;
$dig3 = 0;
$img = $dig1. $dig2. $dig3;
**This was my solution but seams sloppy and unconventional.
**Is there a way to have a var = 000 and change it to 001 then 002 and so on?
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Oct 20, 2012 8:12 pm

Re: Newbie looking for some help and tips

Postby simplypixie » Sun Oct 21, 2012 11:29 pm

Firstly I would simplify your code by removing the functions (not needed as such a simple if else) and remove the last empty else as not required. The reason it is not working though is because you need to use == to compare variable values, not just =.
Code: Select all

$action = $_GET['action'];

if ($action == "next")
{ echo 'NEXT'; }
elseif ($action == "back")
{ echo 'BACK'; }
User avatar
php-forum Active User
php-forum Active User
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Re: Newbie looking for some help and tips

Postby Mattyp77 » Mon Oct 22, 2012 12:06 am

Awesome. Thanks so much!
I knew that the function wasnt necessary. I just wanted to learn how to use it.
And the else I only put there when I saw the code wasnt working. I thought maybe it was necessary to complete the if statement.
But anyway it works now, thats all that matters.
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Oct 20, 2012 8:12 pm

Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.