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




Calling A Function If A Query Is Not Successfull


I am using MySQL-Max (the transactional version of MySQL) in an application I'm working on. We've created a class that handles all the database access stuff, to make it easier to update the information for different users using the same app but on different databases.

The class itself does not issue the begin; and commit; statements to commit the queries between begin and commit to the database, as a transaction can have up to 50 inserts.
So to write stuff to the db we would use something like: Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Function/Global Var To Return Name Of Calling Function?
I'm sure I saw this somewhere but can't remember where and can't find it now...

Is there a PHP function or global variable that will return name of the calling function? I want to do this for error reporting purposes without
having to hardcode the function name into my scripts.

Say the function is named getFunctionName(). I want to do something like...

function foo() {

Delete Successfull Uploads If Not All Upload
This is the same file that i had issues with before. With help from this site i fixed the undefined varible. Now i have the problem that if not all files upload successfully the record is not inserted and i have files in my images folder that cant be overwritten(at least when i get my file exists code implemented) which makes it impossible for my client to upload the news and use these images.

Can i implement a code that deletes (unlinks) the successfull uploaded images if one or two fail. That way my client can try again. Or is there a better way to get around this?

Calling TCL Function From PHP 4.3
I'm just picking up PHP, and am really appreciating the transition, however,
I'm running into somewhat of a loggerhead. I'm trying to find a way to
utilize our existing code infrastructure (primarily written in TCL), while
providing an outlet for new technology (aka PHP). It seems that Tcl isn't
really well suited for integration with HTML pages (Rivet is fine, but not
as fleshed out as PHP seems to be). I was wondering if there is any
mechanism in which I can make embedded calls from PHP to TCL libraries? My
first priority would be for these processes to be somewhat embedded (ie:
avoid using a cgi-approach to invoke a new instance of Tcl each time the
particular page is requested via Apache).

Calling A Function From A Url?
I've got a function which echos the html for a page. the function is written asfunction sampleview($category,$imagepth){so it takes the two variables when called. This function is in a file called functions.php which is included on all of my pages. On one page I'm using Javascript to open up a new window which contains the same html as the php function.. I'm trying to transfer it all to php.

The problem I've got is, I'm not sure how to use php to create a link that will open a new window at a preset size.. I can easily do echo "<a href="mypage.php" target="_blank">click here</a>but that will just open a new window. I need to specify the height and width of the window..

I also need the link to somehow call the function, instead of loading a page like; <a href="sampleview(mycategory,myimage)">click here</a>Is this possible?

Calling A Static Function.
I have to call a bunch of static functions where class names are
stored in a array.
So I have:
$my_array = array("class_1", "class_2", ... and so on...)
So I tried this piece of code to call static functions attached to
each classes like that:
foreach($my_array as $classname)
$classname::MyStaticFunc(...);...

Calling A Thumbnail Function.
I found this function that converts images to thumbnails on PHP.net (http://www.php.net/manual/en/functi...copyresized.php). I am talking about last function on that page dated 21-Apr-2002 03:12. My question is: Do I have to compile it in GD library (like they suggest) or I can call this function from within PHP page? If yes how can I call it and what should I use for the parameters? Example of how to call this function would be very helpful.

Calling Function By Variable....
I have a function that pulls last 10 records from the database and formats it appropriatly then I need to assign that output into a variable named $content. That variable is used by other scripts when reffered to. Now my question....can I assign function call to the variable name...like that?? $content = any_function_name();

If so, how can I make sure that the function is not called right at the load of the page, but only upon the echo of the variable.

Db Connect And Calling A Function
I have database connect script at the beginning of my PHP page which sets the dbconnection. when I run a query in the script it works fine I have decided that rather than use the default error catch like this:

$result=mysql_query($query,$db_connect) or die("There has been an error adding the appointment to the database.".mysql_error());which works fine I would call a function to handle the errors - particularly in the case of a duplication Code:

Error Calling A Defined Function
I was trying to use the mail class from 'PHP 4 Professional Programming from Wrox' but I get the error:

Fatal error: Call to undefined function: send() in /home/www/mysite/my_mail_class_test.php on line 17

The problem is that the send() function IS defined as you may see in the scripts below:

Calling Function From Inside The Class
How I can call the outside function from inside the class without making any object of that class? The situation is shown below

Calling Variable In Onchange Function
I am using a javafunction (onclick in select) in which i am calling a
function in php (thats why i send this to both php and javascript
newsgroups).

in the onclick i call the function "Place_Selected" with the value from the
select (naam_keuze.value)

in the function the value becomes the $zoek_id and searches in the database
for the record with the id of $zoek_id

the naam_keuze.value does not give the value to $zoek_id

When i replace naam_keuze.value for a number (15) i works great.

WHAT AM I DOING WRONG?

This is my code

Function Place_Selected($zoek_id)
{
include("data.php");
$link=mysql_connect($db_host, $username, $password) or die("Database
error!");
mysql_select_db($database , $link)or die("Couldn't open $db:
".mysql_error());
$sql=mysql_query("SELECT * FROM specialismen WHERE id='$zoek_id'");

if ($sql)
{
while($blah2 = mysql_fetch_array($sql))
{
$newsid = $blah2['id'];
$sticky = $blah2['naam'];
}
}
return("document.form.achternaam.value='$sticky'");
}

<select id=naam_keuze size=1 name=keuze style=visibility:hidden
onchange=".Place_Selected('naam_keuze.value').";document.form.voornaam.value
=naam_keuze.value;>
<option value=0>Kies
$options
</select>


Calling A Function Through User Input.
So heres yet another question to a problem where I would have no idea
where to look for the answer for so I turn to you :)

Say my sites administrator wants to write a news update or blog or
whatever. Something like this

"Added a new gallery from my trip to Phuket, enjoy:
[GID=24]
If you liked it tell me."

I want the [GID=24] to get replaced by my galery loading function
(very nifty and handy) so it would turn into something like this

echo "Added a new gallery from my trip to Phuket, enjoy:
".galery($GID)."
If you liked it tell me.";

I chose this [GID=24] because it is similar to burning board code. I
would also like to include a command like [PID=45] witch would run my
picture function.

Calling Function From A Required File
I have a function like this is a php file: foo.php PHP Code:

Calling Php Function On Click Of A Hyperlink
How to call a php function on click of a hyperlink?

Calling A Function Inside The SendMail
I have a function to send an email to a client after they have successfully submitted a form on my site. I have a 2nd function that prints their input to the browser as a confirmation.

I'd like to be able to include that print function inside my mail
message like this :

function sendToClient($email) {
$subject = 'Confirmation'
-----> $message = printConfirm($lang); <----
$headers = 'MIME-Version: 1.0' . "";
<snip>, etc
mail($to, $subject, $message, $headers);
}

This way I don't have to duplicate the output. The confirmation will
get printed to the browser AND the exact same content will be emailed.

Calling A PHP Function From The Submit Button
I have designed a form that gathers information about the user and when the SUBMIT button is pressed I would like to execute a PHP function in the same .PHP document.

How can I call a PHP function within the same document when the submit button is pressed?

Returning Variables To A Calling Function
I have a system wherein different scores can be entered by month. The details for the selected month are displayed, and with a calendar box or by left and right arrows the user can move the form to different months.

I've done this via resubmitting on-clicks that load $_POST with the desired month and year.

When details are entered and the 'Save' button is pressed, javascript changes the form action to another PHP function and then submits the page. Code:

Passing By Reference Better Than Returning A Value When Calling A Function?
When I need a function to generate a string, I have two methods:
1. pass by reference: mystring = ""; myfunction( mystring ); // prototype of myfunction( &anystring );

OR

2. mystring = myfunction(); //which return a string. According to experience of C/C++, the former one is better as of the...

Calling A Function Inside An Array Element Txt Str
Long story short – I don’t have access to a DB, so I’ve done what I think is the next best thing; I’ve defined my Web-link addresses in an external file (global variables) and I include the HREFlist in all PHP docs. Next, and the part that causes question, I made a (really spiffy) function that writes out the <a href…> part.

I have an array of quotes from people who are saying things and I’d like to hyperlink keywords in their quotes. Ideally, this would mean several calls to the linkWriter() function. My initial attempts culminated with me finally throwing in the towel and I just hard-coded the HTML tags, although I was able to interject the global variables into the array variables so I didn’t have to hard-code the URLs....

Calling Session Variable Inside A Function
Related to my previous question on searching through an array, I
discovered the issue. I have a session variable ($username) which I
can not call inside my functions. I can call it just fine outside the
function. Suggestions?

Also, is it an issue because my array returns a column with the same
name?

****************************

function respond_check($qid)
{
include "db.inc.php";
$postchk2 = mysql_query("SELECT username FROM `answers` , `users`
WHERE `qid` = $qid AND `a_uid` = `userid` LIMIT 0,

30",$db);

while ($userx=mysql_fetch_array($postchk2))
{

if (in_array("$username",$userx)) {
echo "Got I finally Got ITT!!!!";
}

}

}
echo "$username is cool"; // This works here but not within the
function

****************************

Calling A Function After Sending Header Information
On my site, users can only download the same file once a month. I use direct link masking so that the user cant see the actual direct link of the file. When the user clicks on the download link next to the file, i run the following: Code:

Calling A Php Function From A Form Selection List
I have a function that will read records from the database and populate an area of my webpage based on a value selected from a list box. 

I have got it to work fine if the user hits a submit button but I was wondering if it possible to perform the function dynamically each time the user changes the value in the list box.

Getting The Function Name Of The Calling Function How?
I guess the Subject is a little ambiguos. I want to get the function
name which calls the target function.
Like
function xxx()
{
....
....
yyy(2,3);
function zzz()
{
....
yyy(5,6);
.....
function yyy($a,$ab)
{
...
...
echo "yyy() has been called by the function - ".$functionname;
Now how can I get the name of the function tat calls yyy()....

How To Use My Md5 Function In A Query?
The little problem I have is its not returning the password only the hash form of it. Can someone show me where to insert the md5 function. I tried everywhere I can think of.. Code:

Query: Mail() Function
I'm having some trouble trying to send mail out when I retrieve the emails from a DB. I really don't know whats going on, but I have tested this on 'normal' email and this works fine but when it comes to a email from a DB it doesn't work. PHP Code:

Trying To Perform Query With Function
I'm trying to create a piece of code that gets rows from a database, formats them as "|1|2|3|4|..", and then inserts them into the database. Here's my code:

Turning A Query Into A Function?
I'm having is trying to integrate it with an existing php script. It looks like the only real way to insert it is as a function, other methods create various syntax errors or the query doesn't produce any results. However the code by itself works fine. So I figured if I turn it into a function place that function in the php file, then call upon it then it would probably work properly. Code:

Query Result Navigator Function
I've just updated this, and I thought I'd also say that not only can this provide a page navigation for MySQL or other database results, but can be used to navigate other lists.. such as a file list. PHP Code:

Database Query From Within A Class Function
My application is object orientated and each object requires a cooresponding "PageID" in the tables "Page" and "PageContent" as well as a few other necessary elements to display properly as a web page.

Some page elements are contained in their own tables, but are associated with the"Page" and "PageContent" tables by the "PageID" that cooresponds to the page the element should be displayed on.

I have written a script that allows me to create a new page by inserting data into fields on the "Page" and "PageContent" tables, but it only works as long as the "PageID" in each table is auto_incrementing in sinc.

I wanted include a method for members to sign-up for the site and I fould a script named "Authlib v1.94" that seems to work pretty well on its own. However, I hacked the code to redirect the data to an existing member table and cut out some of the validation. My intital tests on the hack have been satisfactory.

If any of you are familiar with the "Authlib v1.94" code you may be aware there's a file named backend.php included in the script. It is a class file that includes some pretty nice validation functions for dealing with registering new members, logins, etc.

The register function of the authlib class validates user input from the regestration form. If all the checks pass, it goes on to create a new entry in the "Member" table. (Keep in mind that I redirected the data to this table and hacked the code a bit.) The code looks something like this: PHP Code:

Call To Undefined Function: Query()
Im getting insane by solving a problem ....

I try to define a function which uses a code-snippet from another file.
My base are the codes from the great book "WebDataBase-Book by H.
Williams & D. Lane".

So I try to use

$result = $connection->query("LOCK TABLES visitkarte WRITE");
if(DB::isError($result))
trigger_error($result->getMessage(), E_USER_ERROR);

which works in another .inc very fine.

Look at my .inc for the function VKDataInDB

<?php
require_once "db.inc";
require_once "DB.php";
require_once "authenticate.inc";
require_once "visitsontheweb.inc";

// Dieser Errorhandler ist extrem gefährlich da er das root-passwort
der DB ausgibt!
//set_error_handler("customHandler");

function VKDataInDB(&$connection)
{
//Book Page 641

$connection=DB::connect($dsn, true);
$cust_id=getCust_id($_SESSION["loginUsername"]);

// Lock Table -- 636
$result = $connection->query("LOCK TABLES visitkarte WRITE");
if(DB::isError($result))
trigger_error($result->getMessage(), E_USER_ERROR);

//Query for the highest ID
$result = $connection->query("SELECT max(vk_id) FROM visitkarte");
if (DB::isError($result))
trigger_error($result->getMessage(), E_USER_ERROR);
$row = $result->fetchRow(DB_FETCHMODE_ASSOC);

// Die nächste verfügbare vk_id errechnen
$vk_id = $row["max(vk_id)"] + 1;

//selbst erstellt
$sql = "INSERT INTO visitkarte cust_id = '{$cust_id}',
vk_id = '{$vk_id}',
erstelldatum = NOW(),
sessionid = '{SID}',
vorname = '{$_SESSION['vorname']}',
nachname = '{$_SESSION['nachname']}',
titel = (),
plz ='{$_SESSION['plz']}',
ort ='{$_SESSION['ort']}',
tel1 ={$_SESSION['telefonnummer']},
mobil=(),
strasse={$_SESSION['strasse']},
homepage=(),
email={$_SESSION['email']},
kategorie={$_SESSION['kategorie']},
hintergrund=(1),
";

//Write data
mysql_query ($sql) or mysql_error();

// Unlock tables
$result=$connection->query("UNLOCK TABLES");
if(DB::isError($result))
trigger_error($result->getMessage(), E_USER_ERROR);....

To Use Insert Query In A Javascript Function?
Am doing a page in which the data's to be updated on every click.. After updation the control should back on the actionpage with updation, i have some values in the javascript function(these are the datas upadting in the database..) I tried with ajax, but the control is getting lost after the first updation(first click)

Calling A Function Or Page To Another Page
I have two pages that are part of a user registration script. For simplicity's sake I will call one registration.php and the other validate.php What I basically would like to do is instead of going from registration.php to validate.php, I would like to call the script from validate.php and use it without leaving registration.php

The following code is a portion of the validate.php code. Here are my questions regarding this page. 1). If I want to call it or include it in registration.php should I make it a function? If so, how would I do that. 2) Can I call the validate page or function through an a href statement? (see registration.php code) PHP Code:

Is It Possible To Use Php User Function In A Single Global SQL Query?
This string does not work in php:

$sql="UPDATE mytable SET myfield=myuserfunction(myfield)"

What I want is my function to evaluate each field and put the new
value in the field.

For example, this works:
$sql= "UPDATE mytable SET myfield=myfield+3";

Stores myfield+3 in each myfield, but with a function it does not
work.

Function Names Stored In Db; Called Based On Query
I'm wondering whether something like this is possible:

1. I want to store an id# / function-name pair in a database - e.g. 0001 / functionA(), 0002 / functionB(), 0003 / functionC(), etc.

2. Based on some query, some number of these id / function name pairs are returned.

3. The returned function names are called in a script.

More background on my question:

I'm building an intranet for my company. There are various departments within my company, each of whom will have their own section of the intranet. I've built various online tools that may be of use to some number of these departments. I want the departments to be able to decide which tools they want to appear on their "home page" within the intranet. In my imagination, each time I create a new tool, I register it in a db table.

Each department uses an online form to flag the tools they want to appear on their page. The form they edit updates a db table, linking their department with the id number of the requested tool. The script that creates their home page queries the table, determines the tools they've asked to view on their home page, and calls the appropriate functions that will display these tools.

REGEX: Can't Seem To Replace LIMIT Clause In Query Using Preg_replace ($pattern, $replacement, $query)
Want to replace the limit clause in a query, but can't get it right.
What's wrong with this:

$pattern = "(.*)limit (.*)";
$replacement = '$1'
$replacement .= "LIMIT $limit";
$replacement .= '$2'
$query = preg_replace ($pattern, $replacement, $query);

PHP Update Query Mysql: Query Succussful?
I can't seem to successfully test an update query. Below is a piece of code that updates a statistics table. If row today doesn;t exist, a new day must be created. But this doesn't work...

thank you for your reply.

$today= date("Y-m-d");

$qq="update totals_r set hits_r=(hits_r+1), lang_$lang=(lang_$lang+1), cat_$cat=(cat_$cat+1), rating_$rating=(rating_$rating+1), bussite_$bussite=(bussite_$bussite+1) where date='$today'";

$result_6 = mysql_query ("$qq");

if (!$result_6){ /// IF !ROW_TODAY ==> CREATE NEW DAY

$qq_2="insert into totals_r (hits_r, lang_$lang, cat_$cat, rating_$rating, bussite_$bussite, date) values(&#391;',&#391;',&#391;',&#391;',&#391;','$today')";

$result_6_2 = mysql_query ("$qq_2");

if (!$result_6_2){
$err_msg_sql_6= mysql_error();
$err_loc_6="$PHP_SELF"." // Query6: update totals_r";
}
}

Speeding Up Query/code (query Within Result Set)
I'm looking for ideas on how to speed up this script. Basically it finds all the zip codes in a zipcode table, then looks for all the records in another table with those zip codes.

Right now it finds all the zips then within that WHILE, it looks for a record in another table with that zip: PHP Code:

Calling Url.
Is it possible, with php, to figure out what the "calling url" is ?

Let's say I have a track.html (with some php code) and if someone
clicks on a link to track.html I want to see the url where that visitor
came from.

Calling CVS In PHP
Howdy does have any PHP fuctions that allow me to run CVS?
Here's what I've tried so far:

<?php
system('cvs
-d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/izicontents login;
cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/izicontents
co -P iziContents1 .');

Calling PHP Within PHP
I have a script that is on serveral sites. It changes constantly, so updating 10 sites is a hassle. What I wanted to know if there is a way to call PHP within PHP, using php itself, or javascript, etc. Simply because I'll place the file that is going to be called on a seperate location where all sites can call from it.

Can it be called in a .js file? Using <?php at start ?> at end? or is there a easier way?

Calling Perl From Php?
I have a site all in PHP, for login, auth, session management, etc. I have to interface it with a banks perl scripts to do credit card transactions. Their wrapper perl script expects a few arguments, including a hash with all the data.

What would be easiest way to get the data entered into my adduser.php form to the perl script?

Calling Cgi As SSI Inside PHP??
Hello, i wanted to know if it is possible to execute perl scripts from inside PHP-scripted pages...

i have tried adding php to the SSI section of my apache server config file... SSI will work fine once i do that... however that will prevent any of the PHP from functioning inside the page.

Is there any way i can go about having both execute, and work in the same file?

Currently the page has around 2 small PHP scripts, and a cgi poll with the SSI inserted in it. I have tried changing to a PHP include, but that only works for PHP produced files... can i include a cgi file from PHP in a different format, and have it execute?

Calling Functions
Could someone out there give me information on how to call a function from a click event? Is it possible to do in PHP or do I need to write it in javaScript? What I would like to do is click the next record button and have all of the fields in my form change to hold the data of the next record in the table.

Name Of The Calling Method
I'd like to get the name of the calling method. I can't find the solution.
For example :

function MyFct()
{
return TheOtherFct();
}

function TheOtherFct()
{
echo "Hi, the calling method is ...";
return true ;
}

MyFct();

How To Calling Php Script From <img Src=>
I want to call a php scrip from <img Html tag. As the script should have to output any picture , But i don;t want to out put any picture. so how to out put a balnk picture so that the tag will work properly. Please give me a complete code.

Calling Functions
Can I call function like they are called in JavaScript, in events like Onclick and so on.
for examle like this: <input type='submit' value='remove' onclick='remove($current)'>

Get The Url Of The Calling Page?
Is there a function similar to php_self that gives me the actual page that will give me the url of the calling page?

Calling Application (.exe) From PHP On XP
I am trying to call an application from php. I have tried exec() and
system() and even popen() all to no avail.

Can an application be called if it brings up a window? The app I am
calling has a command line interface, but it insists on bringing up
it's standard window also.

At the moment the .exe file displays in Windows Task Manager in the
Processes tab.

The PHP script hangs (until timeout) and the .exe doesn't do the job it
should.

I am probably being daft :o)

PHP Calling Programs On AS/400
I have a website (running on a linux machine) that currently makes use
of JSP to access data on an AS/400.

I've found information telling me that after setting up ODBC drivers on
the linux server I'll be able to access the databases on the AS/400
however I've not found any information about executing programs on the
AS/400.

I've looked at the docs for exec, passthru, etc. and it appears those
will only work on the local operating system.

Is it possible for a PHP page to execute a program on a remote machine?

If so, how does PHP handle the ASCII <--> EBCDIC conversion for
parameters passed and returned?


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