|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
|||
|
|||
|
if statement
I tried to use this and get these errors --
Notice: Undefined variable: submit in c:inetpubwwwrootaddedit.php on line 3 Notice: Undefined variable: update in c:inetpubwwwrootaddedit.php on line 12 this is what I am typing in - actually I am copying it from your tutorials http://codewalkers.com/tutorials/9/14.html why do I have this issue with if statements and else statements and else if? Is there a problem with the script? Is there a setting I dont have setup on my php.ini file correctly? I am new to this whole thing and would like some info on what I am doing wrong. BTW On this tutorial page http://codewalkers.com/tutorials/9/12.html there is more errors of script that needs to be fixed. On the script you have : $result = mysql_ query("SELECT * FROM personnel",$db); Should be $result = mysql_query("SELECT * FROM personnel",$db); I mean I know you all may be pros at this and spot it quickly but some of us like me - who has never used PHP before and is learning this took me like 2 hours to figure out that there was a typo on your part. Is this else and if statements typos???? |
|
#2
|
|||
|
|||
|
RE: if statement
There is nothing wrong with the code. Author only assumes you have register_globals=on in your php.ini:
Quote:
That's why you variables are not defined. Newbie can easily skip this little notice. That option was set to off by default in versions above 4.1 or so. In other words, instead of $variable use $_GET['variable']. Or you can add following loop at the beginning of your script. The loop will neccessary assingments for you. |
|
#3
|
|||
|
|||
|
RE: if statement
Ok, how do you initialize the variables with $_GET like $first=$_GET[first];
register_globals is set to on , I had changed this way earlier. I dont know how to initialize variables. Do I put this into a php webpage? help |
|
#4
|
|||
|
|||
|
RE: if statement
It should work if you set the register_globals to on.
By initialization he means simply this assignment: $submit = $_GET['submit']; |
|
#5
|
|||
|
|||
|
RE: if statement
To test it, create a new file.
Then copy this text: <?php if (isset($_GET['name'])) { echo "used GET".$_GET['name']; } else { echo "without GET $name"; } ?> Save it as test.php. In your browser call it like this: http://yourserver/test.php?name=Joe See which method works. |
|
#6
|
|||
|
|||
|
RE: if statement
I did it and it came up with "used GETJoe" on a webpage without the quotes.
If its all working then why am I getting this error then when I run a php with an if statement in there or else statement? This is strange. Im running a php VB bullentin BB on the server too and am writing this to you from the server and the bb runs great and I know there is if statements all within it. But I was doing the tutorial and I get errors when I run the page that has if statements and else statements. The tutorial is helpful but I cant run that one page. http://codewalkers.com/tutorials/9/14.html here is the code thats on the page <HTML> <?php if($submit) { $db = mysql_connect("localhost", "root",""); mysql_select_db("learndb",$db); $sql = "INSERT INTO personnel (firstname, lastname, nick, email, salary) VALUES ('$first','$last','$nickname','$email','$salary')"; $result = mysql_query($sql); echo "Thank you! Information entered.n"; } else if($update) { $db = mysql_connect("localhost", "root",""); mysql_select_db("learndb",$db); $sql = "UPDATE personnel SET firstname='$first', lastname='$last', nick='$nickname', email='$email', salary='$salary' WHERE id=$id"; $result = mysql_query($sql); echo "Thank you! Information updated.n"; } else if($id) { $db = mysql_connect("localhost", "root", ""); mysql_select_db("learndb",$db); $result = mysql_query("SELECT * FROM personnel WHERE id=$id",$db); $myrow = mysql_fetch_array($result); ?> <form method="post"action="<?php echo $PHP_SELF?>"> <input type="hidden"name="id"value="<?php echo $myrow["id"]?>"> First name:<input type="Text"name="first"value="<?php echo $myrow["firstname"]?>"><br> Last name:<input type="Text" name="last" value="<?php echo $myrow["lastname"]?>"><br> Nick Name:<input type="Text" name="nickname" value="<?php echo $myrow["nick"]?>"><br> E-mail:<input type="Text" name="email" value="<?php echo $myrow["email"]?>"><br> Salary:<input type="Text" name="salary" value="<?php echo $myrow["salary"]?>"><br> <input type="Submit" name="update" value="Update information"></form> <? } else { ?> <form method="post" action="<?php echo $PHP_SELF?>"> First name:<input type="Text" name="first"><br> Last name:<input type="Text" name="last"><br> Nick Name:<input type="Text" name="nickname"><br> E-mail:<input type="Text" name="email"><br> Salary:<input type="Text" name="salary"><br> <input type="Submit" name="submit" value="Enter information"></form> <? } ?> </HTML> |
|
#7
|
|||
|
|||
|
RE: if statement
any ideas??
|
|
#8
|
|||||
|
|||||
|
RE: if statement
I made a few changes.
php Code:
|
![]() |
| Viewing: Codewalkers Forums > Other > Tutorials > if statement |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|