Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - stlewis

Pages: [1] 2
1
Beginners - Learning PHP / Re: Validate Function Not working
« on: February 20, 2012, 01:34:40 PM »
A couple of things...I'm not going to preach on this too much, but to be honest it's a really bad practice to rely entirely upon Javascript to handle form validation.  All a user needs to do then to get around your validation scheme is turn off Javascript in their browser.  So...add some validation on the server side in addition to what you've got going on in the JS.

As to your JS...I might be missing something critical here, but I think your problem lies in the fact that you're returning out of your validate_form function as soon as you check the first field.  You only call validate_form the one time, (on form submit), and once you return out of a function, that function is done...it won't keep going.  So, what's happening is your first field is validating, and none of the other fields are being checked assuming that one is good.  You can confirm my theory by putting an invalid value in the Name field and seeing if it gives you your error.

Assuming I'm correct, the solution is to get rid of all those returns and return just one time after all the fields have been checked.  You can do that by setting up a variable that stores the state of the form depending upon whether or not all the fields are valid:

Code: [Select]
  <script>
    function validate_form(){
     var form_dirty = false

    if(firstName == "" || firstName == null){
      form_dirty = true;
    }

   if(lastName == "" || lastName == null){
      form_dirty = true;
   }
   if(form_dirty){
     alert("There are problems with your form submission");
     return false;
   }
   return true:
  }
  </script>

Sorry about the crap indentation, but you get the idea...

Hope this helps!!

2
Beginners - Learning PHP / Re: Creating forms in php
« on: February 17, 2012, 08:18:55 PM »
First of all, let me recommend a quick clean up for your function code, that might make it a little easier to see what's going on with your code:

PHP Code: [Select]

function drawForm($value$pwd$files){
  
$form = <<<DOC
    <form action='page2.php' method='get'>
      Username: <input type='text' name='username' value='
$value' /><br />
      Password: <input type='text' name='password' value='
$pwd' /><br />
      <select name='course'>
DOC;
  
$fileNames scandir("courses");
  foreach(
$fileNames as $fileName){
    if(
$fileName != "index.txt" && $fileName != '.' $fileName != '..'){
      
$form .= "<option value='$fileName'>$fileName</option>";
    }
    
$form .= "<input type='submit' /><br /></form>";
  }

  echo 
$form;
}


None of the above actually addresses your question except to say that this is a little cleaner than having a million echo statements in a function body, but that's really beside the point.  Your specific issue is likely related either to your page2.php file not being in the same directory as the php file that contains your form, (because the action attribute wants the location of the file, not just it's name...if page2.php is in a different directory, you need to give it the appropriate path), or potentially to the permissions on page2.php not being set correctly.  Make sure that your script is at least world-readable, which it honestly should be by default.

3
Beginners - Learning PHP / Re: Email doesn't send name in body
« on: October 28, 2011, 05:58:48 PM »
You're not really showing us enough code here...your snippet doesn't indicate whether or not you've even defined the $name or $cat variables, for instance.

4
Beginners - Learning PHP / Re: Select within Select ? If that makes sence
« on: October 25, 2011, 09:34:13 PM »
What you're likely looking for is an inner join of some sort:

Code: [Select]
SELECT t1.first_name, t1.last_name, t1.aged, t2.pbs, t2.medals FROM t1, t2 WHERE t1.swim_id = t2.swim_id;

5
Beginners - Learning PHP / Re: Send fax instead of email
« on: October 25, 2011, 09:28:06 PM »
There isn't any 'standard' PHP way to send a fax.  Your best bet would be to look in to fax by email services that are out there and then just write your code to send emails to whatever address you're given by that fax by email service.

6
Beginners - Learning PHP / Re: Input Value Default
« on: October 24, 2011, 07:23:33 PM »
Honestly, I can't be sure exactly how to fix the problem without being pretty familiar with your server set up.  How are you actually going about editing the page?  It seems like for whatever reason, PHP code is being stripped out of the final version of the page, so it might actually be an intentional configuration thing too.  Your best bet at this point will be to show what you've done to the server admin.  There's nothing wrong with your code, so they'll need to help you make sure things are configured properly.

7
Beginners - Learning PHP / Re: Input Value Default
« on: October 24, 2011, 07:09:42 PM »
Hmm...interesting.  When I go to your page, it's not just not working.  What's happening is that the PHP code is being written in to the text box 'raw', that is, it's not being interpreted.  I copy and pasted your code in to my local server and tried it, and everything works properly though.

That makes me wonder if PHP is enabled on the page correctly.  Are there other examples of PHP code on the page that are working?  If not, try something experimental...where you currently have the "Important Info" h3 tag, replace it with this:

PHP Code: [Select]
<?= "<h3>Important Info</h3>" ?>

Just to see what happens.  If you see that code rendered raw instead of your heading just like you had before, then there's something wrong with your PHP configuration.

8
Beginners - Learning PHP / Re: fread() is not a valid stream resource
« on: October 24, 2011, 06:59:50 PM »
From the sound of the error, it seems that the URL you're passing to fread isn't valid for whatever reason.  Just to debug it, echo out your concatenated $url variable to see what it looks like, and confirm that it's valid.

If that checks out, keep in mind that on some server set ups, the allow_url_fopen PHP ini directive is set to false, which means that you can't pass URL's to file reading functions such as fread().  If you have control over your own ini settings make sure allow_url_fopen is set to true...if you don't have that control and can't confirm that it's enabled, you may be SOL.

9
To verify that a user is logged in to your site:

Verifying a user is currently logged in to your site:

Typically this is done by setting a session variable after the user logs in.  If you set the variable value to say, the user's ID in the database, it helps with your second step:

Retrieving/Displaying User Information:

If the session variable containing a user id is set, you can use that ID to perform a SQL lookup and get back your user data. There are a number of ways/formats to pull data from a database using PHP, you'll need to read up on them.  Once you have your result set, you can just echo the results straight in to your HTML.

As to rendering the page as a PDF, there are all kinds of PHP libraries that offer that functionality, again, it's just a matter of picking one that works for you.

10
Beginners - Learning PHP / Re: Newbie- Wallpaper Site Project
« on: October 24, 2011, 06:45:26 PM »
I'm afraid I'm having a little bit of difficulty understanding what you're trying to achieve. If you want all of the thumbnail images to automatically display on the same page when you click the corresponding gallery link, you're probably needing to look at Javascript, as that's the more appropriate tool. No need for a server side language for something like that.

11
Beginners - Learning PHP / Re: generic registration
« on: October 24, 2011, 06:41:53 PM »
Yup, just a small logic error.  Your function is named registration(), but in the code, you're calling registerUser().  Just have to resolve that confusion and you're all set.

12
Beginners - Learning PHP / Re: Input Value Default
« on: October 24, 2011, 06:39:44 PM »
Could I get you to post:

1. The exact URL you're using to get to the page with the form on it.
2. The complete code for the form.

I double checked my code example, and it's working for me in a basic case.

13
Beginners - Learning PHP / Re: Input Value Default
« on: October 24, 2011, 05:43:39 PM »
Hmm...I can't see why it wouldn't work.  Let me explain what's going on.

Let's say you have an URL like this:  http://www.example.com/?foo=bar&baz=bot

Notice everything after the question mark?  Those are GET variables, and they are referenced in PHP code by accessing the $_GET superglobal array.  So for instance, if we want to get the value of the 'foo' GET variable, we get to it like this:

PHP Code: [Select]

echo $_GET['foo'// bar


The only reason I can think that my example wouldn't work, you might not have PHP short tags enabled on your server, (which would be a bit weird, but on that chance, try this:

PHP Code: [Select]

<div class="rbox">
<
label><input type="text" name="req_found" class value="<?php echo $_GET['ref'] ?>" /></label>
</
div>





14
Beginners - Learning PHP / Re: Input Value Default
« on: October 24, 2011, 01:43:26 PM »
PHP Code: [Select]

<div class="rbox">
<
label><input type="text" name="req_found" class value="<?= $_GET['ref'] ?>" /></label>
</
div>


Pretty self-explanatory, I hope?

15
Beginners - Learning PHP / Re: Problems with where clause
« on: October 21, 2011, 01:23:55 PM »
Your query should probably read something like this:

PHP Code: [Select]

$infosql 
"SELECT * FROM premiersounds_users WHERE username = '$username'";

Pages: [1] 2