Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using w32api function calls from php in an html page

Status
Not open for further replies.

SDowd

Programmer
Nov 11, 2005
91
US
hey everyone,
im trying to place message boxes in my php script in order to make sure my data is useful as i make my way through the page. i tried using the dl() function to register the w32api, then register the function, to then later call it. does anyone know if i am doing anything wrong. or if there is an extra step or two that i am missing. all i have been able to figure out what to do is what i have stated. if someone could point me in the right direction i would appreciate it.

Code:
dl("php_w32api.dll");
		w32api_register_function("User32.dll",
                         "MessageBoxA",
                         "long"); 

		//run the query... enter info into database
		$query = "INSERT INTO test (user_name, password, first_name, phone, email)
					VALUES ('$username', '$password', '$name', 5555555555, '$email', NOW())";
		
		$result = @mysql_query($query);
		
		w32api_invoke_function("MessageBoxA", NULL, $query, "test", MB_OK);
		MessageBoxA(NULL, $query, "test", MB_OK);
		
		if($result)
		{
			echo "connection to the database was made and you were entered";
		}		
		else
		{
			echo "something didnt work";
		}
 
im running it through an html web site
 
Then whatever it is you are trying to do won't work.

The Win32 API calls work on the machine on which the script is running. In the case of a PHP web application, this is the web server, not the client. If you want to open dialog boxes on the browser, use JavaScript.

Also, it looks like you're trying to write console code here, but you're running under HTTP. The single most important thing a console app programmer can learn is that web applications are discontinuous:[ol][li]A script runs or an HTML file is fetched. The connection between the browser and the server closes[/li][li]The user interacts with the form, filling in data, then submits[/li][li]The browser sends data to a script, which processes it and produces output. The connection between the browser and server closes.[/li][/ol]

The script code you've posted looks, in contrast, like it's supposed to wait for user input, then continue. This only works for software running on the console.



Want the best answers? Ask the best questions! TANSTAAFL!
 
well what i was trying to accomplish was on a submit button from the form. the snippet provided is contained within a routine run on the submit button. no console app. at least to my knowledge. but if trying to use win32 message boxes will not work, how can i get immediate info about the data aside from sending it to a new page? i only ask these questions because the SQL statements do not seem to be accessing my database. so to make sure my query is populated correctly i was trying to display its value.
 
the snippet provided is contained within a routine run on the submit button.
No, it's not. PHP runs on the server, not the client. You do not have access to PHP functions from the browser.

how can i get immediate info about the data aside from sending it to a new page?
As I said before, you don't. Even with advanced techniques like AJAX, data must be submitted from the browser to the server before server-side script code, such as PHP, can get to the data.



Want the best answers? Ask the best questions! TANSTAAFL!
 
so is that to say all of this validating isnt going to run?

Code:
<body>
<?php

if(isset($_POST['submit']))
{
	//handle the form
	
	$message = NULL; //create and empty new variable
	
	//check for a name
	if(strlen($_POST['name'] ) >0)
	{
		$name = TRUE;
	}
	else
	{
		$name = FALSE;
		$message .= '<p>You forgot to enter your name!</p>';
	}
	
	//check for an email
	if(strlen($_POST['email']) > 0)
	{
		$email = TRUE;
	}
	else
	{
		$email = FALSE;
		$message .= '<p>You forgot to enter your email</p>';
	}
	
	//check for user name
	if(strlen($_POST['username']) >0)
	{
		$username = TRUE;
	}
	else
	{
		$username = FALSE;
		$message .= '<p>You forgot to enter your user name</p>';
	}
	
	//check password against confirmed password
	if(strlen($_POST['password1']) > 0)
	{
		if($_POST['password1'] == $_POST['password2'])
		{
			$password = TRUE;
		}
		else
		{
			$password = FALSE;
			$message .= '<p>Your password did not match</p>';
		}
	}
	else
	{
		$password = FALSE;
		$message .= '<p>You forgot to enter your password</p>';
	}
	if($name && $email && $username && $password)
	{
		//if all the info is true then register them
		
		//send an email
		$body = "Thank you for registering with our site!\nYour username is '{$_POST['username']}'
					and your password is '{$_POST['password1']}'.\n\nSincerely,\nUs";
		mail($_POST['email'], 'Thank you for registering!', $body, 'From: admin@site.con');
		//header('Location: Thankyou.php');
		exit();
	}
	else
	{
		$message .= '<p>Please Try Again</p>';
	}
}

//set the page title and include the HTML header.
$pageTitle = 'Register!';
include('./header.inc');

//print error message if there is one
if(isset($message))
{
	echo '<font color ="red">', $message, '</font>';
}

?>

<form action = "thankyou.php" method = "post">
<fieldset>
	<legend>Enter your information in the form below:</legend>

	<p><b>Name:<br></b><input type = "text" name = "name" size = "20" maxlength = "50"></p>
	<p><b>Email Address:<br></b><input type = "text" name = "email" size = "20" maxlength = "50"></p>
	<p><b>User Name:<br></b><input type = "text"  name = "username" size = "20" maxlength = "50"></p>
	<p><b>Password:<br></b><input type = "password" name = "password1" size = "20" maxlength = "50"></p>
	<p><b>Confirm Password:<br></b><input type = "password" name = "password2" size = "20" maxlength = "50"></p>

</fieldset>

<div align = "center"><input type = "submit" name = "submit" value = "Submit"></div>


</form><!-- form -->

im new to php so im still grasping the concepts of it.
 
im sorry that last post didnt include the SQL stuff:

Code:
<body>
<?php

///////////////////////////////////////////////////////////////
//	currently no header or footer exists so errors will show when they are trying to be included
///////////////////////////////////////////////////////////////


if(isset($_POST['submit']))
{
	//handle the form
	
	$message = NULL; //create and empty new variable
	
	//check for a name
	if(strlen($_POST['name'] ) >0)
	{
		$name = TRUE;
	}
	else
	{
		$name = FALSE;
		$message .= '<p>You forgot to enter your name!</p>';
	}
	
	//check for an email
	if(strlen($_POST['email']) > 0)
	{
		$email = TRUE;
	}
	else
	{
		$email = FALSE;
		$message .= '<p>You forgot to enter your email</p>';
	}
	
	//check for user name
	if(strlen($_POST['username']) >0)
	{
		$username = TRUE;
	}
	else
	{
		$username = FALSE;
		$message .= '<p>You forgot to enter your user name</p>';
	}
	
	//check password against confirmed password
	if(strlen($_POST['password1']) > 0)
	{
		if($_POST['password1'] == $_POST['password2'])
		{
			$password = TRUE;
		}
		else
		{
			$password = FALSE;
			$message .= '<p>Your password did not match</p>';
		}
	}
	else
	{
		$password = FALSE;
		$message .= '<p>You forgot to enter your password</p>';
	}
	if($name && $email && $username && $password)
	{
		//if all the info is true then register them
		
		//send an email
		$body = "Thank you for registering with our site!\nYour username is '{$_POST['username']}'
					and your password is '{$_POST['password1']}'.\n\nSincerely,\nUs";
		mail($_POST['email'], 'Thank you for registering!', $body, 'From: admin@site.con');
		//header('Location: Thankyou.php');
		
dl("php_w32api.dll");
        w32api_register_function("User32.dll",
                         "MessageBoxA",
                         "long"); 

        //run the query... enter info into database
        $query = "INSERT INTO test (user_name, password, first_name, phone, email)
                    VALUES ('$username', '$password', '$name', 5555555555, '$email', NOW())";
        
        $result = @mysql_query($query);
        
        w32api_invoke_function("MessageBoxA", NULL, $query, "test", MB_OK);
        MessageBoxA(NULL, $query, "test", MB_OK);
        
        if($result)
        {
            echo "connection to the database was made and you were entered";
        }        
        else
        {
            echo "something didnt work";
        }


        exit();
	}
	else
	{
		$message .= '<p>Please Try Again</p>';
	}
}

//set the page title and include the HTML header.
$pageTitle = 'Register!';
include('./header.inc');

//print error message if there is one
if(isset($message))
{
	echo '<font color ="red">', $message, '</font>';
}

?>

<form action = "thankyou.php" method = "post">
<fieldset>
	<legend>Enter your information in the form below:</legend>

	<p><b>Name:<br></b><input type = "text" name = "name" size = "20" maxlength = "50"></p>
	<p><b>Email Address:<br></b><input type = "text" name = "email" size = "20" maxlength = "50"></p>
	<p><b>User Name:<br></b><input type = "text"  name = "username" size = "20" maxlength = "50"></p>
	<p><b>Password:<br></b><input type = "password" name = "password1" size = "20" maxlength = "50"></p>
	<p><b>Confirm Password:<br></b><input type = "password" name = "password2" size = "20" maxlength = "50"></p>

</fieldset>

<div align = "center"><input type = "submit" name = "submit" value = "Submit"></div>


</form><!-- form -->
 
I'm confused. What does this have to do with the subject of the thread, "using w32api function calls from php in an html page"? I don't see any w32api calls in that code.

I have no idea if any validating is taking place. Is data being submitted to this script?



Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top