|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Variables giving me trouble!
Hi,
I have just taken the Dynamic Content tut. I did all the right things, but when it came to adding a row via a form, it doesn't work. I have investigated and figured out that variables don't get passes from one page to another. You see, when I submit the form, only the ID (which is pre-defined anyway) shows up. Why could this be? It has been stumbling me for a while now. Thanks, Liam |
|
#2
|
|||
|
|||
|
RE: Variables giving me trouble!
There are too many reasons to speculate. I haven't read the tutorial but post your code and I am sure someone will be able to help you.
|
|
#3
|
|||
|
|||
|
RE: Variables giving me trouble!
the code should be fine, it worked for me
|
|
#4
|
|||
|
|||
|
RE: Variables giving me trouble!
Here's my code: the form:
<HTML> <BODY> <form method="get" action="datain.php"> 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> Here's the php from (datain.php): <HTML> <?php $db = mysql_connect("localhost", "username","password"); 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."; ?> </HTML> It works (kinda) but only enters a new row (with the id which appears to be coz its "auto_increment") with no info. Why? I think the prob is that it wont pass variables from one page to anther. Any ideas? I am really starting to get FRUSTRATED!!!! |
|
#5
|
|||
|
|||
|
RE: Variables giving me trouble!
Try changing method="get" to method="post" and see what you get ;) Also you may need to add a relative or absolute address in action= for example (action="./datain.php")
|
|
#6
|
|||
|
|||
|
RE: Variables giving me trouble!
No, I tried that, but nothing seems to work
|
|
#7
|
|||
|
|||
|
RE: Variables giving me trouble!
Try this string:
$sql = "INSERT INTO personnel (firstname, lastname, nick, email, salary) VALUES ('".$first."', '".$last."', '".$nickname."','".$email."','".$salary."')"; If that does not work tell us what version of MySQL you are using. Good luck. |
|
#8
|
|||
|
|||
|
RE: Variables giving me trouble!
NOPE, again!
I'm such a trouble maker! My mySQL version is 3.23.49 Any help? Thanks. |
|
#9
|
|||
|
|||
|
RE: Variables giving me trouble!
Sorry about that use this sql string:
$sql = "INSERT INTO personnel (firstname, lastname, nick, email, salary) VALUES ('".$_POST['first']."', '".$_POST['last']."', '".$_POST['nickname']."', '".$_POST['email']."', '".$_POST['salary']."')"; If your form method is not post change it to post, because that is best practice method. This has got to work! |
|
#10
|
|||
|
|||
|
RE: Variables giving me trouble!
Nope, still no luck.
P.S. My PHP version is 4.0.0 Thanks. |
|
#11
|
|||
|
|||
|
RE: Variables giving me trouble!
I will not sleep until you answer with "YEP".
HTTP POST variables: $_POST Note: Introduced in 4.1.0. In earlier versions, use $HTTP_POST_VARS. swap 'em out! |
|
#12
|
|||
|
|||
|
RE: Variables giving me trouble!
EvilivE, you are a legend!
THANK YOU SO MUCH!!!!!! You have no idea the s**t I had to go through to get an answer as good as yours. I am eternally greatful!!!!!1 If there is anything I can do for you, don't hesitate to email me! (lgetreu@hotmail.com). Thanks again for all your help! |
|
#13
|
|||
|
|||
|
RE: Variables giving me trouble!
Just like the movie "Pay it forward", help 3 people with their PHP code/install/etc.
|
|
#14
|
|||
|
|||
|
RE: Variables giving me trouble!
If I want to call a variable via the URL bar ie xyz.php?variable=example
How would I do that considering I need to use this "$HTTP_POST_VARS" thing? Thanks again ... sorry to bother you! |
|
#15
|
|||
|
|||
|
RE: Variables giving me trouble!
One way of doing that is like this (this is not the most proficient way but its easy to follow the logic):
Keep in mind you aleady know what the variable names are. if(isset($HTTP_POST_VARS['variable'])){ $variable = $HTTP_POST_VARS['variable']; } else { // set to default } It is basic but hopefully you get the idea. |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Variables giving me trouble! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|