LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-10-2014, 08:20 AM   #16
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872

Quote:
Originally Posted by rjo98 View Post

Using ... ]makes the page not display anything
Check for errors in logs (tail /var/log/httpd/error_log) while trying your script
 
1 members found this post helpful.
Old 09-10-2014, 09:27 AM   #17
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
In a nutshell Register_Global directive was on which automatically assigned your form values to variables when submitted by default. Since this directive is now depreciated your variables are not automatically defined. This is why your script does not work.

However, if php recognised $work as a not defined variable it should of displayed nothing instead of "$work" There could be a syntax error in your old code that is now causing problems with the current php version. Form values are now available using $_POST['xxxx'] or $_REQUEST['xxxx'].
 
Old 09-10-2014, 09:35 AM   #18
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
OK. Now not being a php programmer, are there syntax checkers out there I can run my file through? I did the command line php check -l, and it didn't report any errors.
 
Old 09-10-2014, 10:25 AM   #19
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Try changing <? to <?php.
Change all your form post variables i.e. $work to $_POST['work'].

Will get the form working first before adding other stuff.
 
1 members found this post helpful.
Old 09-10-2014, 10:49 AM   #20
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
ok, changed my one <? to <?php

but for the other suggestion, do I just change that in my if ($send != "no") section? or do I change that every spot there's a $work for example? I think just in that if section, but want to make sure.
 
Old 09-10-2014, 11:05 AM   #21
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Also, is taking out all the VALUE= parts in the form_block part the right thing to do so the text boxes aren't populated with stuff like
\"$work\"
 
Old 09-10-2014, 11:07 AM   #22
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Did you try running the script? Did the $work disappear?

I'm not the best programmer either... Others might suggest a better method.

Actually in your (send==no) if then block you could add
$word=$_POST['word'] (i.e.for each form variable)
..
echo "form_block"

P.S not if you want to redisplay those values that were first posted.
 
Old 09-10-2014, 11:15 AM   #23
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Actually, just tried to run it after my <? to <?php change, and that eliminated all the garbage from the text boxes! so I guess that question is void now. but when I click the submit button, it just clears all the forms out and I don't get the email.

I'm still confused on where I need to "Change all your form post variables i.e. $work to $_POST['work']" though? do I change it on the INPUT lines, where it's checking to make sure it's filled in, or where it's adding it into $msg? Sorry, feeling really dense on this part.

but wow, that first change made the form look identical to how it was on the old server, pretty amazing!
 
Old 09-10-2014, 12:41 PM   #24
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
There have been changes from php v.4 to php 5

$PHP_SELF becomes $_SERVER['PHP_SELF']

All your post form variables are now in $_POST array

eg:
$employee becomes $_POST['employee']
$department becomes $_POST['department']

etc

PS: the errors can be seen in /var/log/httpd/error_log

Last edited by keefaz; 09-10-2014 at 12:43 PM.
 
Old 09-10-2014, 12:54 PM   #25
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
ok, I see where I have $PHP_SELF
<FORM METHOD=\"post\" ACTION=\"$PHP_SELF\">
so am I simply manually doing a find and replace of those 2 phrases to change it?

So sounds like every time I see a $employee for example that should become $_POST['employee']

I do see the errors with line numbers in error_log, but how to correct them (or how not to make things worse) i'm still struggling with. it complains of undefined variables PHP_SELF, employee, department, work, cell, home, pager, message, op.

Could someone show me what the line for PHP_SELF and maybe employee should look like, then i can try to fix the others myself?

really appreciate you guys barring with me here

Last edited by anon091; 09-10-2014 at 01:08 PM.
 
Old 09-10-2014, 02:53 PM   #26
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
You can use isset function to see of $op is set to remove that error. If not set then
you can define your form variables to equal "". This will not cause errors when you echo the form block string when first run. Then when you display errors you use the $_POST to get the form data.

If (!isset($op)) {
$message=""; // include all form variables
...
echo form_block;
}
if ($send=='no') {
$message=$_POST['message'];// assigns variables. include all form variables.
...
echo form_block;
}
 
1 members found this post helpful.
Old 09-10-2014, 03:09 PM   #27
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Maybe use a function to simplify things...

PHP Code:
<?php
function myIsset($str) {
  return isset(
$_POST[$str]) ? trim($_POST[$str]) : '';
}

$form_block "
<FORM METHOD=\"post\" ACTION=\"
{$_SERVER["PHP_SELF"]}\">
<p><strong>Employee name: <font size=\"-1\"><em>(Exactly as it should be listed)</em></font>  <font color=\"#FF0000\">**Required</font></strong><br>
<INPUT TYPE=\"text\" NAME=\"employee\" VALUE=\""
.myIsset("employee")."\" SIZE=\"75\" MAXLENGTH=\"100\"></p>

<p><strong>Department: <font size=\"-1\"><em>(Exactly as it should be listed)</em></font>  <font color=\"#FF0000\">**Required</font></strong><br>
<INPUT TYPE=\"text\" NAME=\"department\" VALUE=\""
.myIsset("department")."\" SIZE=\"75\" MAXLENGTH=\"50\"></p>";

/* script continue */
?>
Now, I think it's better to use single quotes for $form_block value imo

PHP Code:
<?php
function myIsset($str) {
  return isset(
$_POST[$str]) ? trim($_POST[$str]) : '';
}

$form_block '
<FORM METHOD="post" ACTION="'
.$_SERVER['PHP_SELF'].'">
<p><strong>Employee name: <font size="-1"><em>(Exactly as it should be listed)</em></font>  <font color="#FF0000">**Required</font></strong><br>
<INPUT TYPE="text" NAME="employee" VALUE="'
.myIsset('employee').'" SIZE="75" MAXLENGTH="100"></p>

<p><strong>Department: <font size="-1"><em>(Exactly as it should be listed)</em></font>  <font color="#FF0000">**Required</font></strong><br>
<INPUT TYPE="text" NAME="department" VALUE="'
.myIsset('department').'" SIZE="75" MAXLENGTH="50"></p>';

/* script continue */

?>
Also myIsset() function should do more tests on posted variables to sanitize user inputs

Last edited by keefaz; 09-10-2014 at 03:20 PM.
 
1 members found this post helpful.
Old 09-11-2014, 08:06 AM   #28
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Thanks guys. will try to implement what you said.
 
Old 09-11-2014, 09:27 AM   #29
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Frankly, if it's a script for learning forms in PHP, I would try another one, more recent

If it's a script that will run in real production server environment, I am afraid but it has to be rebuilt from scratch

A modern example for php5, html5
PHP Code:
 <!DOCTYPE HTML>
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>

<?php
// define variables and set to empty values
$nameErr $emailErr $genderErr $websiteErr "";
$name $email $gender $comment $website "";

if (
$_SERVER["REQUEST_METHOD"] == "POST") {
   if (empty(
$_POST["name"])) {
     
$nameErr "Name is required";
   } else {
     
$name test_input($_POST["name"]);
     
// check if name only contains letters and whitespace
     
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
       
$nameErr "Only letters and white space allowed";
     }
   }
  
   if (empty(
$_POST["email"])) {
     
$emailErr "Email is required";
   } else {
     
$email test_input($_POST["email"]);
     
// check if e-mail address is well-formed
     
if (!filter_var($emailFILTER_VALIDATE_EMAIL)) {
       
$emailErr "Invalid email format";
     }
   }
    
   if (empty(
$_POST["website"])) {
     
$website "";
   } else {
     
$website test_input($_POST["website"]);
     
// check if URL address syntax is valid (this regular expression also allows dashes in the URL)
     
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
       
$websiteErr "Invalid URL";
     }
   }

   if (empty(
$_POST["comment"])) {
     
$comment "";
   } else {
     
$comment test_input($_POST["comment"]);
   }

   if (empty(
$_POST["gender"])) {
     
$genderErr "Gender is required";
   } else {
     
$gender test_input($_POST["gender"]);
   }
}

function 
test_input($data) {
   
$data trim($data);
   
$data stripslashes($data);
   
$data htmlspecialchars($data);
   return 
$data;
}
?>

<h2>PHP Form Validation Example</h2>
<p><span class="error">* required field.</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
   Name: <input type="text" name="name" value="<?php echo $name;?>">
   <span class="error">* <?php echo $nameErr;?></span>
   <br><br>
   E-mail: <input type="text" name="email" value="<?php echo $email;?>">
   <span class="error">* <?php echo $emailErr;?></span>
   <br><br>
   Website: <input type="text" name="website" value="<?php echo $website;?>">
   <span class="error"><?php echo $websiteErr;?></span>
   <br><br>
   Comment: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea>
   <br><br>
   Gender:
   <input type="radio" name="gender" <?php if (isset($gender) && $gender=="female") echo "checked";?>  value="female">Female
   <input type="radio" name="gender" <?php if (isset($gender) && $gender=="male") echo "checked";?>  value="male">Male
   <span class="error">* <?php echo $genderErr;?></span>
   <br><br>
   <input type="submit" name="submit" value="Submit">
</form>

<?php
echo "<h2>Your Input:</h2>";
echo 
$name;
echo 
"<br>";
echo 
$email;
echo 
"<br>";
echo 
$website;
echo 
"<br>";
echo 
$comment;
echo 
"<br>";
echo 
$gender;
?>

</body>
</html>
http://www.w3schools.com/php/php_form_complete.asp
 
1 members found this post helpful.
Old 09-11-2014, 09:29 AM   #30
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
I think you're probably right. at this point, i'll take this example you provided and try to tweak as a replacement for mine.

Thanks for the help everybody. I'm going to close this thread.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
odbc (php output not displaying in web browser,but it displaying in terminal) manu@vssc Red Hat 1 06-29-2011 01:33 AM
[SOLVED] multiple slack boxes not posting to forms -- had to use winxp just to post this globaltree Slackware 6 10-09-2009 02:30 AM
php page displaying text that is supposed to be part of php code DragonM15 Programming 9 07-31-2008 04:58 PM
GTK 2.0 problems in displaying dialog boxes stephenwalter Programming 1 01-20-2006 01:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration