Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 09-12-2005, 11:30 PM
kjhkjh's Avatar
kjhkjh kjhkjh is offline
 
Join Date: Jul 2005
Posts: 77
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default My last question on PHP, promise :)

I really do appreciate the help that I get on this forum and know that I'm asking a lot. But I learn from all the advice. Thank you.

Here is my final question...

Summarizing what I want to do from the start:

1. I have a form with 4 fields. For example $mobile, $code, $message,
$tickbox

2. I need to confirm that there are no blank values and that the
tickbox is ticked.

3. I need to confirm that $mobile is a number (no other characters)

4. If there are blank values or $mobile contains a value other than a
number, I need error messages and the form to be presented back to them
with the error messages below.

5. Another tricky part is that I need $code to be checked, so that it
is matched to a code in mysql database. Otherwise the user gets
requested to re-enter the code (but hopefully the message and mobile
fields will still be populated from what the user originally put in
each of the fields. This will stop them getting annoyed that the
message they spent 10 mins writing has disappeared after the error.

6. If there are no blanks AND the code matches any code on mysql (I
have a table there with a single field which has 1000 codes) AND the
mobile value is all numbers, then and only then would I like myfile.php
to be actioned which involves sending an email (I have the email bit
all worked out in the myfile.php)

7. The final bit is that on submission If all the above is correct (no
blanks and code confirmed etc...) then I need the code to be deleted
from the mysql table.

I know that this is quite a bit of work but if anyone could help me
with anybit then I would appreciate it.

At the moment I might be doing it the wrong way but have this:

PHP Code:
<?php 

//substr just to have the php page accept a certain number of 
charactersnot all that important

$mobile substr($_REQUEST["mobile"], 015); 
$code substr($_REQUEST["code"], 08); 
$message substr($_REQUEST["message"], 0122); 
$tickbox $_REQUEST["tickbox"]; 

//will redirect to blanks.php page which is almost the same as the 
original form page
//but with the blanks error message 

if (empty(mobile) || empty($code) || empty($message) || 
empty(
$tickbox)) { 
        
header"Location: http://www.mysite.com/blanks.php" ); 

  } 

//will redirect to bad number page which is almost identical to the 
original form page 
//but with bad number comment 
if (!ereg("^[0-9]{1,}$",$mobile)) { 
        
header"Location: http://www.mysite.com/badnumber.php" ); 

  } 

//the bit that sends the email 
//this bit works and so i dont need help on the actual email send 
$my_email "xxx...@xxxxxx.com"

if (
$_SERVER['REQUEST_METHOD'] != "POST"){exit;} 

$message ""

while(list(
$key,$value) = 
each($_POST)){if(!(empty($value))){$set=1;}$message $message "$key
$value\n\n";} if($set!==1){header("location: 
$_SERVER[HTTP_REFERER]");exit;} 

$message "$code 
                      
$mobile 
                      
$message 
                      
$tickbox"

$subject "subject"
$headers "From: " $_POST['senderemail'] . "\n" "Return-Path: " 
$_POST['senderemail'] . "\n" "Reply-To: " $_POST['senderemail'] . 
"\n"

mail($my_email,$subject,$message,$headers); 

<
html
<
head
</
head
<
body

Actual final page that the user sees after successful form submission 
is here in the html


</
body
</
html

?>
So thats how far I've come with separate .php files for error messages.

But I do need to only have this form submit the email bit if there are
no blanks AND the $mobile only contains numbers AND the $code matches a
code in mysql table.

On submission I would need the used code to be deleted from the table
on mysql.

All help appreciated!
Reply With Quote
  #2  
Old 09-13-2005, 11:44 AM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

instead of
PHP Code:
ereg("^[0-9]{1,}$",$mobile
you can use the is_numeric function
Reply With Quote
  #3  
Old 09-13-2005, 12:12 PM
kjhkjh's Avatar
kjhkjh kjhkjh is offline
 
Join Date: Jul 2005
Posts: 77
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks,

Someone else told me that but I can't get it to work.

Do I just replace the lines:


PHP Code:
if (!ereg("^[0-9]{1,}$",$mobile)) {  
        
header"Location: http://www.mysite.com/badnumber.php" );  

  } 

With:

PHP Code:
if (is_numeric($mobile)) {  
        
header"Location: http://www.mysite.com/badnumber.php" );  

  } 

Because this is what I did and it doesn't work like ereg does?


This is as far as I have got with the form field validation bit too. If someone can help me finish this, it may be the quickest $30 paypal they've ever made!

So I add:

PHP Code:
$username="username"
$password="password"
$database="databasename"

mysql_connect('localhost',$username,$password); 
@
mysql_select_db($database) or die( "Unable to select database"); 

$sql "select count(*) items from tablename where code = '$code'"
//Run the query 
if (items == 0) { 
    
header"Location: http://www.mysite.com/badcode.php" ); 


With this I'm trying to validate that $code submitted in the form is in a table. If it is progress with the action (sending an email- noted in first post) PLUS then I would need to have this $code value deleted from the mysql database table.

If the value of $code isn't on the table then I have the redirect to http://www.mysite.com/badcode.php

PLEASE help if you can and I will paypal you $50 as soon as I have it working. I'm sure that this is easy for a lot of people.

Thanks.
Reply With Quote
  #4  
Old 09-13-2005, 12:32 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
if (!is_numeric($mobile)) 
You should be using ! (not).
Reply With Quote
  #5  
Old 09-17-2005, 09:51 AM
kjhkjh's Avatar
kjhkjh kjhkjh is offline
 
Join Date: Jul 2005
Posts: 77
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks marco

you've helped me a bunch of times and i really appreciate it.
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:14 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04086 seconds
  • Memory Usage 2,228KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete