Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOtherTutorials

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
  #1  
Old March 30th, 2003, 05:11 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
Tutorial Codes Does NOT Work

This code, from a Tutorial, does NOT work in PHP 'register_globals off' ---

-------------------
Putting it together
Now let's merge the code into one file. We will call it input.php

<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
{
?>
<form method="post" action="input.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>
-------

Can anyone help fix it?

BTW, it would be extremely helpful to all us 'Newbies' if ALL PHP Code sites would e-mail their authors with a request to update ALL code snippets to work in the new "Standard Environment" of 'register_globals off' within 30 days or NUKE THE CODE from the web repositories.

Thank you.


Reply With Quote
  #2  
Old March 30th, 2003, 05:14 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Tutorial Codes Does NOT Work

with globals off change your variables to


$_POST['varname']


leave them alone in the actual form.


Reply With Quote
  #3  
Old March 30th, 2003, 05:16 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Tutorial Codes Does NOT Work

guess I should make that a little clearer just change the variables that you are passing from the form for instance you would leave $db as is.

Reply With Quote
  #4  
Old March 31st, 2003, 07:39 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Tutorial Codes Does NOT Work

Thank you. So you are saying then:

if($submit) *should now be* if($_POST['submit'])

???

I appreciate your response.

Reply With Quote
  #5  
Old March 31st, 2003, 07:47 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Tutorial Codes Does NOT Work

Umh, I just tried the change but still get:

Notice: Undefined index: submit - and it won't add to the DB.

ARRRGGGHHHHHH!!!

Reply With Quote
  #6  
Old March 31st, 2003, 07:54 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Tutorial Codes Does NOT Work

I even tried also doing: $_POST['firstname'] etc., etc.

ARRRRGGHHHHHHHHH!!!!!!!!!!!!!!!!

Reply With Quote
  #7  
Old March 31st, 2003, 02:32 PM
SeanGleeson SeanGleeson is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Wichita, Kansas, USA
Posts: 92 SeanGleeson 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 SeanGleeson Send a message via Yahoo to SeanGleeson
RE: Tutorial Codes Does NOT Work

Hi. I don't know if this is the source of your trouble, but you see that tag where you've got
Code:
<input type="Submit"name="submit" etc.

Well, there should be a space before the name attribute, like this.
Code:
<input type="Submit" name="submit" etc.

Also, your query has a typo. Where you've got
Code:
'$ last'

I think you meant
Code:
'$last'

Or, with register globals off, that would be
Code:
'$_POST['last']'

or even better
Code:
'".$_POST['last']."'


More advice:
You might also want to strip slashes and escape all the strings, like this
Code:
'".mysql_real_escape_string(stripslashes($_POST['last']))."'

I know, it's a lot longer than '$last', but it will save you trouble in the long run, from folks with funny characters in their names, and from malicious MySQL hackers.


Reply With Quote
  #8  
Old March 31st, 2003, 02:41 PM
crisp crisp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Holland
Posts: 336 crisp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Tutorial Codes Does NOT Work

if ($_POST['submit']) should at least give you a warning when you open the page the first time (offcourse we all code with error_reporting set to E_ALL ;) )
Furthermore I have some comments about using this method and giving your submit button a name="submit"
In the first place a form has a javascript method named submit(); now when you name a form element "submit" this will override the javascript method. If you ever plan to submit the form using javascript you will get the infamous "object doesn't support this method" error.
Secondly you have to keep in mind that submitting a form using the enter key does NOT sent the value of the submit button in the postvars.

I always advice to use:

if ($_SERVER['REQUEST_METHOD'] == 'POST')

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > Tutorial Codes Does NOT Work


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

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway