Jump to content

[SOLVED] Help with php regular expressions


simbarashe

Recommended Posts

Hie

 

Could someone please help me with my regular expresssions because my script is behaving in a rather wierd way when I implement the regular expressions. I am checking names and addresses before I insert them into my database but the regular expression function is not working when the MYSQL INSERT QUERIES are running. Below is my script and I'm just going to briefly explain it. The isWord($value,$pageURL) funtion is in a file called dbFunction.php and its as follows:

 

function isWord($value,$pageURL){

$value2 = trim(stripslashes($value));

f((strlen($value2) == 0) or (!ereg("^[[:alpha:]'-]{1,100}$",$value2))){

$uri = "//" . $_SERVER["SERVER_NAME"]. rtrim(dirname($_SERVER['PHP_SELF']), '/\\');

header("Location: http:".$uri.$pageURL."&err=1");

}else{

return $value2;

}

}

 

I then called it in dbJobsheet as follows:

 

$firstName = isWord($_POST['firstName'],$errorPageURL);

 

this works perfectly because if I put in invalid characters I get redirected to the error page. However when I put in the script to insert the data into the database the above isWord($value,$pageURL) doesnt work.

 

the script that stops all this from working is as follows:

 

<?

$timeQuery = mysql_query("SELECT date_assinged,time_assigned,assStaffID

 

FROM FOLLOW_UP WHERE

time_assigned ='$newTime' AND

date_assinged = '$newAssignedDate'

AND assStaffID = '$assStaffID' ")

or die(mysql_error());

 

$results = mysql_fetch_array($timeQuery);

//checks if there is a time clash and redirects user to the page to re-enter the information.

if ((count($results)-1)>0){

header('Location: index.php?

page=redirectOldClientsJobSheet.php&err=6'); }

 

//checks is the contact exists

elseif(mysql_num_rows(mysql_query("SELECT contactID FROM

CONTACTS WHERE first_name = '$firstName'

AND last_name = '$lastName' AND

email_address = '$email_address' "))){

 

mysql_query("INSERT INTO STATUS VALUES(

NULL,'$status','$description') ")

or die (mysql_error());

 

$statusID = mysql_query("SELECT statusID FROM STATUS WHERE

statusID = 'LAST_INSERT_ID()' ") or die (mysql_error());

 

mysql_query("INSERT INTO JOBSHEET VALUES(

NULL,'$clientID',LAST_INSERT_ID(),'$staffID','$COD','$billed',

CURRENT_DATE(),'$warranty','$jobID','$contactID','$title',

'$complete','$log')") or die (mysql_error());

 

header('Location: index.php?page=oldClientsEnteredInfoDisplay.php');

}

else{

header('Location: index.php?page=redirectOldClientsJobSheet.php&err=7');

}

}

?>

 

Could someone please tell me where I am getting it wrong.

 

Tahnk you

Link to comment
Share on other sites

First off, use [ code ] tags when posting code and also use <?php so that the code will be format for easy reading.

 

I don't see any corelation between your regex function and the code above. Where are you calling isWord() in your script? Did you try echoing the value of $firstName before and after calling the isWord function?

 

Also, your isWord function is taking a second parameter, but I don't see it used in the function.

Link to comment
Share on other sites

sorry about the messy code, I'm not so sure how to use the quote but I'll give it a shot

 

I am using the isWord() function to verify fi the variable given is a word and the call:

<?php
$firstName = isWord($_POST['firstName'],$errorPageURL);
?>

 

is supposed to check if $firstname has the same pattern as the regex I made. If not, I get refered to an error page. The second parameter is the URL of the page that has called the function and I use it to refer the user back to that page if he\she has made a mistake. This all works fine before I put in the following code:

 

<?php

$timeQuery = mysql_query("SELECT date_assinged,time_assigned,assStaffID 
FROM FOLLOW_UP WHERE
time_assigned ='$newTime' AND 
date_assinged = '$newAssignedDate' 
AND assStaffID = '$assStaffID' ")
or die(mysql_error());

$results = mysql_fetch_array($timeQuery);
//checks if there is a time clash and redirects user to the page to re-enter the information. 
if ((count($results)-1)>0){ 
header('Location: index.php? 
page=redirectOldClientsJobSheet.php&err=6'); } 

//checks if the contact exists
[b]elseif(mysql_num_rows(mysql_query("SELECT contactID FROM 
CONTACTS WHERE first_name = '$firstName' 
AND last_name = '$lastName' AND 
email_address = '$email_address' "))){[/b]

mysql_query("INSERT INTO STATUS VALUES(
NULL,'$status','$description') ") 
or die (mysql_error());

$statusID = mysql_query("SELECT statusID FROM STATUS WHERE
statusID = 'LAST_INSERT_ID()' ") or die (mysql_error());

mysql_query("INSERT INTO JOBSHEET VALUES(
NULL,'$clientID',LAST_INSERT_ID(),'$staffID','$COD','$billed',
CURRENT_DATE(),'$warranty','$jobID','$contactID','$title',
'$complete','$log')") or die (mysql_error()); 

header('Location: index.php?page=oldClientsEnteredInfoDisplay.php'); 
}
else{ 
[b]header('Location: index.php?page=redirectOldClientsJobSheet.php&err=7');[/b]
} 
}
?>

 

I started having problem with the script when I put in the code that checks if the contact exists,just after the second comment. Hope this helps clarify my question. May be i need to stop my script from running as soon as it detects an error.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.