Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Check If Variable Is Multiple Of TWO


Is there another fast way (withOUT to call a PHP function), to do this? It is to know if a variable (into a loop) is a multiple of two. PHP Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Check For Multiple @'s
We are trying to prevent spammers from mass mailing their list while
using our contact us script. We have a few security measures in place
but would also like to add a "check for more than 1 @'s in the to:, cc:
and bcc: fields. Can anyone point us to some code or turotials for
doing this?

How To Check If Multiple Of 2?
I am creating a tournament script and need to have total matches as a multiple of 2 (2, 4, 8, 16, 32... ). How can i check the number to see if it's ok.

example
$matchesNum = 38;//obviously this is not a multiple

How would I check that number to make sure it was 32 or 64...

Passing Multiple Variable Errors...last Variable Vanishes.
I have been trying to figure this one out for a few days now and it is starting to drive me mad.  I'm sure this is something simple that I have done wrong but I can't for the life of me figure out what is wrong here. Some background.

I decided I needed to learn PHP, I really enjoy it but keep getting stuck on things like this due to my lack of knowledge.  So I set myself a challenge to write a PHP CMS system using PHP, mySQL, XHTML and CSS.  All was going fine (all be it rather slowly) until I tried to write the page to edit articles in the CMS.

I have the 'ID', 'title', 'venue' and 'article' stored in the database fine.  I can pull entries out and display them fine.  I now want to edit them using a browser.  So I thought I would use the same form I used to add mySQL entries and change ti so that it loads in the article into the form fields depending on the id.  (This is chosen through a link saying 'edit). Code:

Check For Multiple Occurances In An Array.
I am checking an array for existence of a value, but I want to see how many times it exists in the array.

Is there a quick function to do this or must I use a loop and step through? I looked through the manual and did not see any array functions that would do this, but I may have misunderstood one of them. Which has happened before.

I was using this before I realized I had multiple occurences in the array. PHP Code:

Handling Multiple Check Boxes
I have a PHP generated page which displays X many records. Each record has
a checkbox preceding it. The user checks several checkboxes, and hits a
delete button. All the corresponding records will be deleted.

But I'm running into difficulty...

Right now the NAME property of each check box is the primary key of the
corresponding record. Hence if I know which checkboxes are checked, I
simply use DELETE using the NAME value.

Generally speaking, how do I get the server side to see which check boxes
were checked?

The check box names may not be sequential, if any records have been deleted
previously, and the first check box might be a number greater than 0.

Is there an easy mechanism to do this? Some kind of built in cnotrol array
allowing me to loop over every check box that was on the form submitted?

I could store the last and first checkbox number in a hidden input, then
loop starting/ending at those values, but that may loop over a lot of
controls that do not exist.

Multiple Variables Eregi Check.....
This is an easy one I think but I just can't do it for some reson - I want to check more than one variable on the same line, not just address, but can't work out the syntax to do this...

ie. So this code........

$crack=eregi("(to:)|(from:)|(cc:)|(bcc:)",$address);

does this........

$crack=eregi("(to:)|(from:)|(cc:)|(bcc:)",$address and another variable);

I want it so that if any of the variables meet the criteria set in the eregi function then $crack will be true (or 1).

How To Check Value Of Variable??
I have this input box that is optional called "Reason" If a user submits this form with data in the "Reason" form then I want to take those contents and add to them, ie:

if (isset($reason)) {
$reason_message = "Reason for rejection: $reason";}
else {
$reason_message = "";}


Then I have $reason_message sent alow with other stuff in an email. The problem is that if a user leaves "Reason" empty, when they get their email, this string called "Reason for rejection:" is sent. Bottom line: is there a way for me to tell that "Reason" has no value and there for not send "Reason for rejection:"

Function To Check For Multiple Instances Of A String In An Array?
I need to check if there are more than one of the same string in an array. Does anyone know of a function?

How To Check If Variable Is An Array?
I'm using php 4.4.4. How do i check if a given variable is an array
or simply a scalar?

Check Variable Value In Array
I'm wandering if there's a function in php which lets you check for a variable value in a preset array, and how you could check this (TRUE / FALSE) For example:

$variable = a;
$array = array("a","b","c");

Check If A Variable Has Contents In It
I am making a user login system, on the main login page it first gets the contents of a "logged-in" session cookie then sets it to a variable. How can i make something that will check if the variable is empty or not? 

Check To See If A Variable Exists In An SQL Database
I am working on a project.  I want to safegaurd against a user entering a number into the database multiple times.  So what i want to do is run a query and check the users entry against the database, and then return an error if it exists.  Here is how i thought it would work

The script would take the Text Field posted and asign it a variable

$var = $POST_['textfld'];
Then i thought it might work if i were to say

$var2 = mysql_query("SELECT item FROM table WHERE var = '$var'");

Then i could have a statement similar to

if { $var = $var2
      echo "Number already entered into Database";
}
else echo "Thank You";

I thought that would be a good way to make it work, but its not working so far, any suggestions?

How To Check Weather A Variable Contains Serialized Data Or Not
Is there a way to check weather a variable contains serialized
data or not, as we hve some functions like
( is_ double,is_ float) to check the integer and float value.


How To Check If A Character Appears In A Form Variable?
Can anyone tell me how you can perform validation on a string variable
in PHP so that you can check if a specific character is contained
within the string. The reason for this is i am trying to create a form
for a site i am making and i want to validate the user's input for the
email address field, by ensuring it contains the '@' character.

How To Check Weather A Variable Contains Serialized Data Or Not
Is there a way to check weather a variable contains serialized
data or not, as we hve some functions like
( is_ double,is_ float) to check the integer and float value.

Php Variable Post Whois_class To Check Domain Availibility
I am trying to use whois_class to check domain availibility in my domain registration website.I need to pass the available domain to a new page in my site so that it can then be emailed to me.But...Please help me how to extract the domain name that user has choosen to register.

The script is like this , i need the choosen domain name be available globally in all subsequent pages.Thanx a lot in advance

<?php
include($_SERVER['DOCUMENT_ROOT']."/domain/server_list.php");
include($_SERVER['DOCUMENT_ROOT']."/domain/whois_class.php");
// error_reporting(E_ALL);
$my_whois = new Whois_domain;
$my_whois->possible_tlds = array_keys($servers); // this is the array from the included server list

if (isset($_POST['submit'])) {
$my_whois->tld = $_POST['tld'];
$my_whois->domain = $_POST['domain'];
$my_whois->free_string = $servers[$_POST['tld']]['free'];
$my_whois->whois_server = $servers[$_POST['tld']]['address'];
$my_whois->whois_param = $servers[$_POST['tld']]['param'];
if ($my_whois->process()) {
$test=$this->msg;
header("Location:http://localhost/domain/get.php");
// $url = "http://localhost/domain/get.php?".explode("&",$HTTP_POST_VARS);
//header("Location: $url");

}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Whois class example with redirect</title>
</head>

<body>
<h2>Whois domain name check with redirect </h2>
<p>Check here only the domain name availability, <br>
if the domain name is free you will be redirected to a external page.<br>
</p>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" name="form">
<input type="text" name="domain" size="14" maxlength="63" value="<?php echo (isset($domain))? $domain : "";?>">
<?php echo $my_whois->create_tld_select(); // this method generates the select menu woth all tld's?>
<input type=hidden name=reg value=domain>
<input name="submit" type="submit" value="Check">
</form>
<p><?php echo ($my_whois->msg!= "")? $my_whois->msg : "";?></p>

</body>
</html>

OnUnload (check If Variable Is Set) Events To Detect Browser
I'm building a website using PHP/JavaScript/HTML. I am using sessions. I need to find out how to do two tasks.

1. Log the time when the user is done using the website. I am using the onLoad (set a variable) and onUnload (check if variable is set) events to detect browser close. But this doesnt let the page to be refreshed or the 'Back' button to be used. (I am ensuring that the time is not logged when the user clicks a hyperlink by resetting the variable.) Is there a way to let the user use the back button and refresh without logging him out?

2. I need to make sure that only one user logs into the site using a username. What is the best way to do this? I have the usernames stored in a database. DO I set and reset a flag when a user logs in or out?

Multiple Variable In URL ...
I have read some topics regarding url with multiple variables (index.php?........).

From what I have read, there are two important points that I should not ignore :

1/ Not to have a variable called $id
2/ Stick to 2 or 3 variables max

My website is a databank of pictures and user can see pic in thumbnail formats. Because they have the possibility to set a number of results, to order them differently, type search keywords, etc... my url can have upto 8 variables. Though, I have done a small php script to remove the var from the URL when the variable is NULL, I am not satisfied and am afraid that my HEAVY databased website will not be fully indexed.

I am aware of the mod_rewrite in Apache, but I'd like to know if there are other alternatives. Is placing variable (such as $order, $qty) in session is a good procedure or should I just eliminate these features in order to reduce my URL?

Multiple Selections Of The Same Variable
<input type="checkbox" value="apples" name="fruit_ARRAY[]"> apples
<input type="checkbox" value="oranges" name="fruit_ARRAY[]"> oranges
<input type="checkbox" value="bananas" name="fruit_ARRAY[]"> bananas

...when checked and submitted...

$fruit = implode($fruit_ARRAY, ",");
print"$fruit";

...this gives me the result... apples,oranges,bananas

I want to query the table for the fruits that match the selected fruits. example:

$result = mysql_query("SELECT * FROM $userstable where $fruits = 'apples' and $fruits = 'oranges' and $fruits = 'bananas");

It needs to find the record for each fruit until there are no more left in the array. I haven't worked with arrays before...and I'm not sure how to query with multiple selections of the same variable.

Multiple Variable Forms
I am trying to create a form that will autofill variables into the buy it now button. Example

Page 1:

Choose your game
o Silkroad - SRO
o Heroes Online - HO
o Knights Online - KO

Choose Amount
o 10 mil - $7.00
o 20 mil - $13.00
o 30 mil - $18.00

these will have a values like Game name is G1 value is SRO or HO or KO.
Amount name is A1 with a value of 7.00 or 13.00 or 18.00. they will click submit, I would like it to automatically fill in the values on a payment system like with moneybookers payment: Code:

Checking Multiple Conditions For One Variable
What I need to do is a comparison to see if a variable equals none of
the 48 contiguous United States, but as efficiently as possible.

The best way I can come up with the the textbook method of :

if (($state != "AR") && ($state != "AK") && ($state != "AL") &&
($state != "CO") ...etc ) {

Is there some way to shorten that a bit to do:

if ($state != "AR" && "AK" && "AL" && ...etc ) {

I looked at php.net for logical operators but couldn't find anything
that seemed to apply.

If someone can just tell me the keyword to look up in php.net I'd
appreciate it. Like "search 'foobar', newbie" would be fine.

Update Multiple Rows With Variable IDs
I'm trying to update multiple rows on my database using one form. The problem is that the number of rows on the form is variable, and the ID for each row is also variable...

   $Team = $_GET['Team'];
   $Game = $_GET['Game'];
   $result = mysql_query("SELECT * FROM data WHERE Team='$Team'",$db);
   while($myrow = mysql_fetch_array($result)) {

echo '<input type="hidden" name="PlayerID" Value="', $myrow["PlayerID"], '">', '<input type="hidden" name="Game" Value="', $Game, '">', $myrow["Team"], ' - ', $myrow["PlayerName"], ' - ', $myrow["Owner"], ' - Points:<input type="Text" size="5" name="Points" value="', $myrow["$Game"], '"><br>';
}
?>

That is my form. When I POST the data I only get the data from the last row that is echoed. I assume that the problem is that the names of my inputs are static and will be overwritten each line, but if I change them to a variable, how can I tell my form to know what they are on the other side? From my limited knowledge it looks like I want to pass an array through POST, just don't know how to do that!

Multiple Str_replaces On A Variable, In One Command?
I have this:

<?php
$article_raw=$_POST['article'];

$article = str_replace ( chr(10), "<BR>", $article_raw );
?>

Which takes my textarea's text and makes the carriage-returns into <BR>'s. Works perfectly BUT--I'd like to be able to add pictures quickly by typing something like

[img:jvfb112507]
...and have it automatically replace that [img:jvfb112507] with something like

<div id="inline_photo"><img src="./images/articles/jvfb112507.jpg"></div>

I just have no idea how to do it.

Selecting Multiple Arrays And Putting Them Into One Variable
Is there a way of assigning lets say $argv[3] through to $argv[10] to one variable??
Also is it possible to assign all of an array after a certain number to a variable??
The reason i wish to do this: I am using a forwarder pointing to a php script.

This script uses exim variables to then send on the email to another couple of addresses.
When a user puts a " in the message body it splits the body into multiple arrays instead of just the one.

Passing Multiple Selections In A List To A Variable
I have a form with a Select box as follows: <SELECT NAME=msgtype SIZE=6 multiple> and in that are 6 options. If I pick one, it is passed to a query reading something like: SELECT * FROM mytable WHERE msgtype LIKE '$msgtype'

This doesn't work if they chose two or more of the items in my SELECT box. How can I make it work if they do? I already have a "All of the above" that passes the value "%%" to the query to search in all of the six options, but want users to be able to search 2-5 of the options at once as well.

[Speed] Multiple Scans Through Variable For Search/replace
At the moment I am developing a app that uses templates.
In the templates I have placeholders like this:

Dear ***FIRSTNAME***<br>
You have subscribed to ***LISTSUBSRIBE***.
etc

The ***XXXX*** must be replaced with values created in my script.

I am a bit worried about the speed and wonder which approach will be
fastest. A straightforward solution would be to run a str_replace($arrSearch,$arrReplace), where $arrSearch contains the strings to be
replaced by the corresponding values in $arrReplace.

Is this a fast solution?
Will a regexpression approach be faster?

Does anybody have experience with this or advise?
Or should I just try a few and benchmark it?

Variable Scoping - Issues With Global And Multiple Includes
I have my main index.php file,
which looks so: <?php include "includes/header.php"; #defines a global
variable called $lang include "includes/functions.php"; # some required
functions safe_include "main_page.html"; # user-defined function that
tries to # include main_page.html.$lang
or gives a warning message echo "Language available to index.php at
line XYZ is -$lang-"; #-- to check empty value include
"includes/footer.php"; #page footer ?> and header.php looks so: <?php
global $lang; $lang = "en"; ?> footer.php looks like so: <?php echo
"Language is set to -$lang-"; # should print out current language in
use ?> Now the problem is, the $lang variable is available to all
statements in between, upto and including the safe_include statement.
Unfortunately, footer.php refuses to see the variable. What can be
the problem?

Retrieve Data From Table With Multiple Returned Variable
I am trying to set up a function to recalculate prices for my products - (per product that is) The problem I am having is that I have a table that stores the prices for each client type (so one product can have multiple prices) so I need to be able to recalculate the price for each client. Code:

Check Variable Against A List (cf. Mysql "in")
Is there a PHP way to see if a variable is a member of a list? E.g. I want to know if $a is in the following list: "apple", "orange", lemon". I know I could loop through an array of values, or I could do a series of "or"s in an IF statement, but I'm looking for something easier and more elegant.

I know in mysql, I could do a query like 'select * from table where id in ("value1", "value2", "value3")'..

Check If Session & Session Variable Exist
I'm setting up a basic "shopping cart" using a multi-dimensional array stored in a session. I want to check if the session exists & if the cart has anything in it to determine whether or not to display "view cart" or "nothing in cart" - easy enough to do. BUT, I don't want to just session_start and then check if my variable is registered - or count() the variable (I'm thinking - why start a session if there is no need to at that stage?).

Seeing as you can't session_start(); before sending headers to the browser, I thought I could run this function at the very top of every page that needs to know if the cart has items in it, while trying not to start a session if one DOESN'T exist: PHP Code:

Selecting Multiple Values From Multiple Tables Using Checkboxes
I've been struggling with this for a bit but cannot seem to find a simpler, cleaner way of doing this.

a. I have a Table A - Customers , Table B - Contacts .
b. I have a form where a user types the first few alphabets of a customer name and then gets a list of contacts, cities.
c. The user is supposed to select multiple options from this list and then send that data to another form for processing.

I'm able to only pass data from Table A, not from B . Could someone please have a look at the 2 snippets of code and advise? And is there a way both these php scripts could be combined in a single one ? Code:

Grabbing Data From Multiple Tables For Multiple Requests
Here's what I'm trying to get at.

A table that displays all the Process Server's name, the number of summons's he has out within 7 days, 7-14 days and 15+ days...pretty simple, it's just a report so management can stay on top of how many papers are out.

I've got the server_information table with the server name and ID. and a case_information table with the serverID.

I've got a while loop that displays all the server's name, the problem is when I try to get the # of cases....here's what i've got so far. Code:

Multiple-combo - Multiple Mail Recipients
I am new to scripting but trying to create a page that lets users create an e-mail (mailto after having chosen from two drop-down menus (arrays).

I have managed to do so in HTML by using a Java script borrowed from Randall Wald (http://www.rwald.com).

However, I don't want the e-mail addresses to appear in the page to avoid spam. Is there a way to do so by using PHP?

P.S.: The first array contains (University A, University B) and the second array (Faculty, Staff, Students), i.e. 6 different e-mail addresses

To Search Multiple Words In Multiple Fields
I have a $phrase made of some words.Every query has a number variable of words. I would sort of my_table all records that have at least 1 word of the $phrase into field_a AND/OR field_b of my_table.

Multiple Users, Multiple Tables, One Form
I have a small group of users that will submit their 'goals' via one form (placed in a postnuke block). I have created one table (mysql) for each user to collect collect their goals. I need some direction in writing the php that will submit the form data to the correct table based upon the users Postnuke login.

Multiple Multiple Select Boxes
I'm looking to have multiple multiple-select-boxes on a page. But I
can only get the contents from the last selected value within a box,
via PHP. I've tried numerous methods. What am I doing wrong?

You can see ALL the values present in the url:
http://myserver/test.php?notify_use..._updcats=Update
e.g.......

Loop Through Array And Create Variable Session Variable Names
As part of my user authentication class I've written a method that sets session variables. I pass an array to the function by reference which contains elements populated with information from the users table in the DB (name, street, country etc)

At the moment the function looks like this:

/* Set the session variables for easy access to user data */
function _setSessionData(&$userData) {
$_SESSION['loggedOn'] = true; // Logged on

$_SESSION['userID'] = $userData['UserID'];
$_SESSION['username'] = $userData['UserName'];
$_SESSION['password'] = $userData['Password'];
$_SESSION['firstName'] = $userData['FirstName'];
$_SESSION['surname'] = $userData['Surname'];
$_SESSION['email'] = $userData['Email'];
$_SESSION['street'] = $userData['Street'];
$_SESSION['city'] = $userData['City'];

return true;
}

What I'm wondering is if it is possible to loop through the $userData array, and dynamically name and populate the session variables rather than listing them all and assigning like I have?

What? Assigning A Session Variable Also Assigns The Local Variable?
Alright,
In the following code, I expect the printed result to be:
DEBUG: frank's last name is burns.

Instead, what I get is:
DEBUG: frank's last name is burns.

Here is the code:
$frank = "burns";
$_SESSION['frank'] = "black";
echo "DEBUG: frank's last name is is $frank";

What is coming into play here? I thought of register_globals but I
thought that only dealt with GET, POST, REQUEST, etc.

Problem With Session Variable And Passing Variable On Insert
I am trying to set a session variable along with my insert statement but on the next page when I do my query I get no results even though I know there are. Code:

Extract Variable From Database, Then Output That Variable.
I have this strange problem (and probably also a strange question).

Let's say you set a variable $blah. The variable has 'test' as content. When I write the variable ($blah) to a database (and not the content of the variable 'test') and I want to output the variable again, I get $blah as output. And not 'test'. PHP Code:

Changing Variable Folder Names To Php Variable
Let me just show you quickly what I mean:

The site url:

http://www.nothing.com/vr/

will then redirect to

http://www.nothing.com/index.php?sec=vr

I'm just wondering if this is possible. The folder after the domain isn't an actual folder, but rather a pseudo one, which is then used in a varible. Another example:

http://www.nothing.com/test/
->
http://www.nothing.com/index.php?sec=45&desc=test

The "folder" has to be variable and so cannot be an actual folder.

Session Variable Becoming Linked To Post Variable
Basically i have a user id stored in session variable eg user_id =1. I have a simple forum that i created myself that inserts this session variable into the db with the persons entry. eg insert into forum value (session[user_id],'$_post['content']);

This is all working fine until i go to edit this post from say the moderator account. I set the user_id for the "replace into db" initially to my session value unless i have selected to edit someone elses post, then i set it to the value submited back from the <form action=self>

i get as far as selecting the contents from db only for the session variable holding my id to change to the value of the user_id selected from the db. Code:

How Can I Refer From One Variable To Hidden Variable?
I have started my php source code shown below

---------------------------------------------------------
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1"))
{....

How To Refer From One Variable To Hidden Variable?
I have started with my php source code shown below, and how can I
refer from one var to hidden var?

----------------------------------------------------------------------------
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1"))
{
$insertSQL = sprintf("INSERT INTO users (UserID, UserName, Password)
VALUES (%s, %s, %s)",
GetSQLValueString($_POST['UserID'], "int"),
GetSQLValueString($_POST['UserName'], "text"),
GetSQLValueString($_POST['Password'], "text"));

mysql_select_db($database_SHHConnection, $SHHConnection);
$Result1 = mysql_query($insertSQL, $SHHConnection) or
die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1"))
{
$insertSQL = sprintf("INSERT INTO holidaymaker (HMID, Name, Status)
VALUES (%s, %s, %s)",

GetSQLValueString($_POST['HMID'], "int"),
GetSQLValueString($_POST['Name'], "text"),
GetSQLValueString($_POST['Status'], "text"));

mysql_select_db($database_SHHConnection, $SHHConnection);
$Result1 = mysql_query($insertSQL, $SHHConnection) or
die(mysql_error());
}

<input type="hidden" name="UserID" value="">
<input type="hidden" name="HMID" value= "">

----------------------------------------------------------------------------

The "UserID" is generated by MySql with auto_increment.[color=blue]
>UserID int(4) auto_increment primary key,[/color]

Assume that I want to add new user and the value for UserID is 5
(after auto increment). Then, I want HMID refer to UserID, the value
of HMID is also 5,
thats mean HMID = UserID, how can I do that? What is the command?

How To Print A Variable That Consists Of A Variable?
how can i print an variable whose name is a variable? look at this pseudo code: PHP Code:

Variable Variable Array Indexes
I am converting my script to run with globals off, this is for image uploads before I used to store the data in a variable variable ${"image".$i} with $i coming from a for loop. How do I convert this to work with $_REQUEST

${"_REQUEST['image".$i."']"} this doesn't want to know and as I see it that is the logical conversion, I have searched the forums but haven't come up with this yet.

SQL SELECT Using Variable Unless Variable Is Empty
Iv got a form where users input details that are then used as search criteria and it all works fine as long as all the details are enterd. But if a variable is empty then this blank space is used as search criteria with doesnt match any records and thus creates no results. Code:

Assign Javascript Variable To PHP Variable
i have select option on my website.When i choose select option  the value of selecet option which i get in the javascript want to assign to PHP variable .So that i can use that in the query.


Copyright © 2005-08 www.BigResource.com, All rights reserved