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
 
Unread Codewalkers Forums Sponsor:
  #1  
Old March 30th, 2003, 06: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: 25
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, 06: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: 25
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, 06: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: 25
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, 08: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: 25
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, 08: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: 25
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, 08: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: 25
RE: Tutorial Codes Does NOT Work

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

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

Reply With Quote
  #7  
Old March 31st, 2003, 03: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: 3
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, 03: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: 3
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!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

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




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek