Forum Moderators: coopster & phranque

Message Too Old, No Replies

Function with submit button

In PHP

         

circuitjump

6:12 pm on Oct 30, 2001 (gmt 0)

10+ Year Member



Hi all,
I'm trying to get this function to work with a submit button.

Here it is

<?php
// Function time
function submit($cur) {
// SQL Command
$cur = odbc_exec( $cnx, "update prospects set FirstName = $FirstName, LastName = $LastName, Company = $Company, ".
"BusinessPhone = $BusinessPhone, BusinessFax = $BusinessFax, BusinessCell = $BusinessCell,".
"EmailAddress = $EmailAddress, BusinessStreet = $BusinessStreet, BusinessCity = $BusinessCity".
"BusinessState = $BusinessState, BusinessPostalCode = $BusinessPostalCode where ID = $ID" );
}
?>

The submit button is

<input type="Submit" value="submit" onClick="<? submit() ?>">

Thanks

David

7:10 pm on Oct 30, 2001 (gmt 0)

10+ Year Member



I didn't know you could do that, If you can I am not sure how.
Do you send it back to the server with the action of the form ?

If so I would test for the value of submit, call the function.

Maybe I am not understanding This...

ggrot

7:31 pm on Oct 30, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmm, when your php page hits the line:
<input type="Submit" value="submit" onClick="<? submit() ?>">
It will execute the submit function and then print:
<input type="Submit" value="submit" onClick="">
to the html of the page. There is no way to trigger a spefic function in php based upon an html event. You can do something similar w/ javascript, but the browser does not interpret php - it never even sees the function in your onClick parameter.

circuitjump

7:52 pm on Oct 30, 2001 (gmt 0)

10+ Year Member



Correct :)

I got it working like this,

I put did the form like so

<form action="<?= $PHP_SELF ?>" method="POST">
<input type="submit" name="submit" value="submit this">
</form>

with extra input fields :)

Then at the top of my page I did this


<?php
// SQL Command
$cur = "UPDATE prospects SET FirstName = '".$FirstName."', LastName = '".$LastName."', Company = '".$Company."',".
"BusinessPhone = '".$BusinessPhone."', BusinessFax = '".$BusinessFax."', BusinessCell = '".$BusinessCell."',".
"EmailAddress = '".$EmailAddress."', BusinessStreet = '".$BusinessStreet."', BusinessCity = '".$BusinessCity."', ".
"BusinessState = '".$BusinessState."', BusinessPostalCode = '".$BusinessPostalCode."' WHERE ID = '".$ID."'" ;
// Function time
function submit($cnx,$cur) {
odbc_do($cnx,$cur);
}
if(isset($submit))
submit($cnx,$cur);
?>

But now I'm getting a SQL-ODBC error and I don't know what the heck it means. Well, somewhat :)

Here is the error

Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression., SQL state 22005 in SQLExecDirect in c:\program files\apache group\apache\htdocs\edit.php on line 24

Thanks

David

9:09 pm on Oct 30, 2001 (gmt 0)

10+ Year Member



I havent seen that before, any chance you have the table set up as "state" and not "BusinessState".
Just a wild guess

circuitjump

9:37 pm on Oct 30, 2001 (gmt 0)

10+ Year Member



Got IT WORKING!!!!

You were right. It ended up being my mistake. In the Access DB I set the data type to "Number" so it would not take empty fields or letters. Thats where the error was coming from.

Thanks for the help