Google Answers Logo
View Question
 
Q: Programing PHP & MySQL ( No Answer,   4 Comments )
Question  
Subject: Programing PHP & MySQL
Category: Computers > Programming
Asked by: patarok-ga
List Price: $40.00
Posted: 10 Jul 2003 15:02 PDT
Expires: 16 Jul 2003 12:30 PDT
Question ID: 227579
Hello,
I am trying to make and process forms using PHP and My SQL. I have
downloaded everything I need (Apache, My SQL, PHP) and I think I have
set them all right. I have configured the Apache configuration file. I
have also configured PHP.ini as follows:

; php.ini for PEAR tests
include_path=..

[mail function]
SMTP= localhost ; for Win32 only
sendmail_from= me@localhost.com ; for Win32 only

[Session]
session.save_path= C:\PHP\sessiondata    ; argument passed to
save_handler

[PHP]
error_reporting= E_ALL; display all errors, warnings and notices

extension_dir = c:/php/extensions; Path to directory containing
php-xxx.dll

extension = php_gd.dll; add support from Tom Boutell's gd graphics
library

To do this I have used a book called PHP & MYSQL for DUMMIES. 

When I got done with configuring everything I tested it using this
file that I wrote in the notepad:

<html>
<head>
<title>
</title>
</head>
<body>


<?php echo "<p>Hello World!" ?>


</body>
</html>

After I got done writing it I opened it up using Internet Explorer and
all I saw was a blank screen even though the book says that it should
say:

<p>Hello World!

I have tried every kind of other script in the book and none of them
work.

I don't know what I have done wrong but please tell me if you need any
other information or file to locate the problem so I can give it to
you asap.


Thank you for your help and have a nice day!

Clarification of Question by patarok-ga on 13 Jul 2003 13:54 PDT
Hello,
I am trying to make a processing form that will check for any mistakes
in the way the e-mail was written by the client. I have written the
script below(it is only part of it) but it will say there was an error
on one of the lines below. Please check and tell me what the problem
may be.


Here is part of the script about the e-mail:
    elseif ($key == "email")
    {
        if (!ereg("^.+@.+\.(com|net|org)$",$HTTP_POST_VARS[$key]) )
        (
             $bad_format[$key] = "bad";
        }
    }

Thank you and have a great day!

Request for Question Clarification by sycophant-ga on 15 Jul 2003 04:01 PDT
Hi patarok, 

I'd be more than happy top help you solve your problem - I see you
have solved your initial issue, and are not having coding
difficulties. It might be best if you closed this question, and opened
a new question for you programming difficulties.

Looking at the lines you included, I can see no obvious errors, but
the way PHP parses it's files can mean that sometimes an error can be
reported on a line somewhat further down than the actual mistake is
on. To accurately diagnose the error, the error message should be
included, and probably a larger section of code, or a link to where
the full code can be viewed.

Also, depending on your application, you may find that your email
validation code it somewhat limited. Many people have email addresses
ending in things other than .com/net/org - and also, it will allow
illegal characters like space. There are many handy open-source code
snippets available for that sort of thing - I tend to find them
preferable to reinventing wheels - try the following sites:
http://php.resourceindex.com/
http://www.hotscripts.com/PHP/

Regards,
Sycophant-ga

Clarification of Question by patarok-ga on 15 Jul 2003 14:01 PDT
Hello,
Thank you for answering my question.I know I should close this
question but to tell you the truth I don't feel I have gotten my
$40.00 worth and I promise when I feel satisfied I will close it.

Here is the whole script:

<html>
<head><title>Empty fields</title></head>
<body>
<?php
$user="patarok";
$host="43.webmasters.com";
$password="siklonezoom";
$database="patarok";
$connection = mysql_connect($host,$user,$password)
or die ("Couldn't connect to server!");
$db = mysql_select_db($database,$connection)
or die ("Couldn't execute query!");


  /* set up array of field labels */
  $label_array = array ( "first_name" => "First Name",
                         "last_name" => "Last Name",
                         "country" => "Country",
                         "address1" => "Address1",
				 "address2" => "Address2",
				 "city" => "City",
				 "state" => "State",
                         "zip" => "Zip",
                         "zip2" => "Zip2",
                         "area_code1" => "Area Code1",
                         "phone_number" => "Phone Number",
                         "area_code2" => "Area Code2",
                         "cell_number" => "Cell Number",
                         "phone_outside_us" => "Phone Outside U.S",
                         "email" => "E-mail",
                         "DOB" => "Date of Birth",
                         "gender" => "Gender",
                         "eye_color" => "Eye Color",
                         "hair_color" => "Hair Color",
                         "weight" => "Weight",
                         "height" => "Height",
                         "shoe_size" => "Shoe Size",
				 "agent" => "Agent",
				 "sag" => "Sag");
  foreach ($HTTP_POST_VARS as $key => $value)
  {
    /* check each field except middle name for blank fields */
    if ( $value == "" )
    {
       if ($key != "address2" and $key != "email" and $key !=
"area_code2" and $key != "cell_number" and $key != "phone_outside_us"
and $key != "zip2")
       {
          $blank_array[$key] = "blank";
       }
    }
        elseif ($key == "first_name" or $key == "last_name" or $key ==
"country" or $key == "city" or $key == "state" or $key == "eye_color"
or $key == "hair_color")

    {
        if (!ereg("^[A-Za-z' -]{1,50}$",$HTTP_POST_VARS[$key]) )
        {
             $bad_format[$key] = "bad";
        }
    }
        elseif ($key == "phone_number" or $key == "cell_number" or
$key == "phone_outside_us")

    {
        if (!ereg("^[0-9)( -]{7,20}(([xX]|(ext)|(ex))?[
-]?[0-9]{1,7})?$",$HTTP_POST_VARS[$key]) )
        {
             $bad_format[$key] = "bad";
        }
    }
         elseif ($key == "email") 
       {
                    if
(!ereg("^.+@.+\.(com|net|org)$",$HTTP_POST_VARS[$key]) )
                   { 
                         $bad_format[$key] = "bad"; 
                   } 
       } 

}
  /* if any fields were not okay, display error message and form */
  if (@sizeof($blank_array) > 0 or @sizeof($bad_format) > 0)
  {
    if (@sizeof($blank_array) > 0)
    {
        /* display message for missing information */
        echo "<b>You didn't fill in one or more required fields. You
must enter:</b><br>";
        /* display list of missing information */
        foreach($blank_array as $key => $value)
        {
           echo "&nbsp;&nbsp;&nbsp;{$label_array[$key]}<br>";
        }
    }
    if (@sizeof($bad_format) > 0)
    {
        /* display message for bad information */
        echo "<b>One or more fields have information that appears to
be incorrect. Correct the format for:</b><br>";
        /* display list of bad information */
        foreach($bad_format as $key => $value)
        {
           echo "&nbsp;&nbsp;&nbsp;{$label_array[$key]}<br>";
        }
    }
    /* redisplay form */
    echo "<p><hr>
      <form action='CHECKALL2.php' method='post'>
      <center>
      First Name:<input type='text' name='first_name' size=20
value='$first_name'><br><BR>
Last Name:<input type='text' name='last_name' size=20
value='$last_name'><br><BR>
Country:<input type='text' name='country' size=12
value='$country'><br><BR>
Address Line 1:<input type='text' name='address1' size=35
value='$address1'><br><BR>
Address Line 2:<input type='text' name='address2' size=35
value='$address2'><br><BR>
City:<input type='text' name='city' size=15 value='$city'>
State:<input type='text' name='state' size=2 value='$state'
maxlength=2> Zip:<input type='text' name='zip' size=5 value='$zip'
maxlenght=5>-<input type='text name='zip2' size=4 value='$zip2'
maxlength=4><BR><br>
Phone Number:<input type='text' name='area_code1' size=3
value='$area_code1' maxlength=3> <input type='text'
name='phone_number' size=7 value='$phone_number'maxlength=7><br><BR>
Cell Number:<input type='text' name='area_code2' size=3
value='$area_code2' maxlength=3> <input type='text' name='cell_number'
size=7 value='$cell_number' maxlength=7><br><BR>
Phone Number(if outside of U.S.):<input type='text'
name='phone_outside_us' size=10 value='$phone_outside_us'><br><br>
E-mail:<input type='text' name='email' size=15 value='$email'><BR><BR>
Date of Birth:<input type='text' name='DOB' value='mm\dd\yy' size=8 
value='$DOB' maxlenght=8><br><BR>
Gender:<select name='gender' value='$gender'>
<option value='male' selected>male
<option value='female'>female
</select><br><BR>
Do you have an agent?<tab>Yes<input type='radio' name='agent'
value=yes>
No<input type='radio' name='agent' value=no checked><br><BR>
Are you SAG?<tab>Yes<input type='radio' name='sag' value=yes>
No<input type='radio' name='sag' value=no checked><br><br><BR>
Eye Color:<input type='text' name='eye_color' size=5
value='$eye_color'><br><BR>
Hair Color:<input type='text' name='hair_color' size=7
value='$hair_color'><br><BR>
Weight:<input type='text' name='weight' size=3 value='$weight'
maxlength=3><br><BR>
Height:<input type='text' name='height' size=5
value='$height'><br><BR>
Shoe Size:<input type='text' name='shoe_size' size=2
value='$shoe_size' maxlength=2><br><br><br><br>

<input type='submit' value='Proceed'>\n

      </form>
      </center>";
    exit();
  }
  else
    {
$query = "Insert Into Members
(first_name,last_name,country,address1,address2,city,state,zip,zip2,area_code1,phone_number,area_code2,cell_number,phone_outside_us,email,gender,eye_color,hair_color,weight,height,shoe_size,agent,sag,dob)
VALUES ('$first_name','$last_name','$country','$address1','$address2','$city','$state','$zip','$zip2','$area_code1','$phone_number','$area_code2','$cell_number','$phone_outside_us','$email','$gender','$eye_color','$hair_color','$weight','$height','$shoe_size','$agent','$sag','$DOB')";
$result = mysql_query($query)
or die ("Couldn't execute query.");
echo "New member added to database<br>";
    }
?>
</body>
</html>

Please tell me what the problem may be so I can get on it right away.

Also I have taken the websites you told me about in consideration.

Thank you for your time and have a great day!

Request for Question Clarification by sycophant-ga on 16 Jul 2003 03:34 PDT
Hi patarok, 

The reason that I suggest you post the question as a new one and
cancel this one, is that the information you have received here so far
has been free in the form of comments. If I solve your coding problem
now, I will be the only one to recieve payment for the question.

Also, you have posted you database host, username and password in a
public location. I would advise very strongly that you change your
password immediately.

Let me know how you'd like to proceed - I am more than happy to help
you, but I feel that given it's divergence from the original one, it
may be best handled in a new question. If you close this question now,
you will only be billed the listing fee, not the full answer fee. You
can then repost the coding problem with as a new question perhaps with
a revised price.

Regards,
Sycophant-ga
Answer  
There is no answer at this time.

Comments  
Subject: Re: Programing PHP & MySQL
From: alexander-ga on 10 Jul 2003 20:43 PDT
 
It sounds like PHP isn't getting invoked at all. Do a "view source" on
your blank page; I'll bet you'll see exactly what you typed, including
the "<?php ..." bit, which should be processed by PHP.

It wasn't clear from your question how you were opening the file in
IE, but as wrynn notes, you do need to go through Apache with an
"http://" url; if you're seeing "file://" instead, you're not doing it
right.
Subject: Re: Programing PHP & MySQL
From: patarok-ga on 11 Jul 2003 15:58 PDT
 
Hello,
Thank you for your previous help, I fixed everything like the way you
said.
Now I ran into another problem.
I am trying to make a form that would check if the field that was
suppose to be filled in by the customer was really filled in.

The script I am using is below and I don't really know what the
problem may be. You can see what the error says if you visit
www.htauditions.com/signup.php

It says something like this:

Parse error: parse error, expecting `','' or `';'' in
/usr/local/4admin/apache/vhosts/htauditions.com/httpdocs/signup.php on
line 16



Here is the script I am using:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
foreach ($HTTP_POST_VARS as $fullname)
{
if ($fullname == "")
{
echo "you did not fill out your name<br>\n";
}
}
echo "it works<br>\n;

echo "<form action='www.htauditions.com/signup.php' method='post'>\n
<input type='text' name='full name' value='$fullname'>\n
<input type='submit' value='Submit Name'>\n
</form>\n";

?>
</body>
</html>

Also I wanted to know if it matters if the HTML codes go first or the
php codes go first if you know what I mean.

Thank you for your help!
Subject: Re: Programing PHP & MySQL
From: jkman-ga on 12 Jul 2003 13:10 PDT
 
You are missing a quote on one of your lines.  It is the one that says....

echo "it works<br>\n;

It should read....

echo "it works<br>\n";
Subject: Re: Programing PHP & MySQL
From: patarok-ga on 12 Jul 2003 15:48 PDT
 
Thank you and please hold on untill tomorrow so I can try out some new
things and I may have a question for you by then.

Thank you for helping me with the script and have a great day.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy