PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
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  
Old June 22nd, 2002, 08:01 AM
lgetreu lgetreu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Melbourne, VIC, Australia
Posts: 56 lgetreu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to lgetreu
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

Reply With Quote
  #2  
Old June 22nd, 2002, 08:17 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
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.

Reply With Quote
  #3  
Old June 22nd, 2002, 03:54 PM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
RE: Variables giving me trouble!

the code should be fine, it worked for me

Reply With Quote
  #4  
Old June 23rd, 2002, 10:01 AM
lgetreu lgetreu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Melbourne, VIC, Australia
Posts: 56 lgetreu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to lgetreu
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!!!!

Reply With Quote
  #5  
Old June 23rd, 2002, 02:39 PM
Stupidnick Stupidnick is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: "i got stoned and i missed it"
Posts: 10 Stupidnick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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")

Reply With Quote
  #6  
Old June 24th, 2002, 08:56 AM
lgetreu lgetreu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Melbourne, VIC, Australia
Posts: 56 lgetreu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to lgetreu
RE: Variables giving me trouble!

No, I tried that, but nothing seems to work .

Reply With Quote
  #7  
Old June 24th, 2002, 09:06 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
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.

Reply With Quote
  #8  
Old June 24th, 2002, 09:38 AM
lgetreu lgetreu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Melbourne, VIC, Australia
Posts: 56 lgetreu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to lgetreu
RE: Variables giving me trouble!

NOPE, again!

I'm such a trouble maker!

My mySQL version is 3.23.49

Any help? Thanks.

Reply With Quote
  #9  
Old June 24th, 2002, 09:52 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
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!

Reply With Quote
  #10  
Old June 24th, 2002, 10:11 AM
lgetreu lgetreu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Melbourne, VIC, Australia
Posts: 56 lgetreu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to lgetreu
RE: Variables giving me trouble!

Nope, still no luck.

P.S. My PHP version is 4.0.0

Thanks.

Reply With Quote
  #11  
Old June 24th, 2002, 10:20 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
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!

Reply With Quote
  #12  
Old June 25th, 2002, 09:22 AM
lgetreu lgetreu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Melbourne, VIC, Australia
Posts: 56 lgetreu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to lgetreu
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!

Reply With Quote
  #13  
Old June 25th, 2002, 09:32 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
RE: Variables giving me trouble!

Just like the movie "Pay it forward", help 3 people with their PHP code/install/etc.

Reply With Quote
  #14  
Old June 26th, 2002, 09:06 AM
lgetreu lgetreu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Melbourne, VIC, Australia
Posts: 56 lgetreu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to lgetreu
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!

Reply With Quote
  #15  
Old June 26th, 2002, 09:13 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
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.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Variables giving me trouble!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump