Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Function which is not called
I need to put some HTML data into the PHP variable. Here is the code with
error:

----------------------------------------------------------------------------
-----------------
$MIDDLE="<form name=\"formSzukaj\" id=\"formSzukaj\"
ALIGN=\"CENTER\">MENU_L:  <input name=\"username\"
type=\"text\" id=\"username\" value=\"$MENU_L\"> <INPUT type=\"button\"
name=\"Submit\" value=\"Zmien\"
OnClick=\"funkcja_update(\"menu\",\"MENU_L\",\"krzeslo\")\"></form>";
----------------------------------------------------------------------------
-----------------
I have one edit field, whose value is put in the function - funkcja_update,
which update me data in SQL database

Function created in PHP shows:
----------------------------------------------------------------------------
-----------------
function funkcja_update($tabela,$pole,$opis)
{
$link_ = mysql_connect("localhost", "database", "password") or die ("Serwer
die");
mysql_select_db ("database") or die ("Baza die");
$query_ = "UPDATE ".$tabela." SET opis='".$opis."' WHERE
pole='".$pole."';";
$result_ = mysql_query ($query_);
}
----------------------------------------------------------------------------
-----------------

How to construct $MIDDLE variable to make it work properly, because now PHP
interpreter doesn`t show any error message,
but update SQL database function is not called???

Please, help me
Thank you in advance

Marcin













Report this thread to moderator Post Follow-up to this message
Old Post
Marcin Zmyslowski
03-27-04 04:13 AM


Re: Function which is not called
Marcin Zmyslowski wrote:

> I need to put some HTML data into the PHP variable. Here is the code with
> error:
>
>
----------------------------------------------------------------------------
> -----------------
>  $MIDDLE="<form name=\"formSzukaj\" id=\"formSzukaj\"
> ALIGN=\"CENTER\">MENU_L:  <input name=\"username\"
> type=\"text\" id=\"username\" value=\"$MENU_L\"> <INPUT type=\"button\"
> name=\"Submit\" value=\"Zmien\"
> OnClick=\"funkcja_update(\"menu\",\"MENU_L\",\"krzeslo\")\"></form>";
>
----------------------------------------------------------------------------
> -----------------
> I have one edit field, whose value is put in the function -
> funkcja_update, which update me data in SQL database
>
> Function created in PHP shows:
>
----------------------------------------------------------------------------
> -----------------
> function funkcja_update($tabela,$pole,$opis)
> {
>  $link_ = mysql_connect("localhost", "database", "password") or die
>  ("Serwer
> die");
>  mysql_select_db ("database") or die ("Baza die");
>  $query_ = "UPDATE ".$tabela." SET opis='".$opis."' WHERE
> pole='".$pole."';";
>  $result_ = mysql_query ($query_);
> }
>
----------------------------------------------------------------------------
> -----------------
>
> How to construct $MIDDLE variable to make it work properly, because now
> PHP interpreter doesn`t show any error message,
> but update SQL database function is not called???

To start off with, the HTML you're trying to put into the variable $MIDDLE
is quite unreadable. Secondly, variables are conventionally only written in
all caps when they refer to globals (and a few other things). So I suggest
using $middle in stead of $MIDDLE. Here's a cleaned up version of your
$middle statement:

$middle = "<form_name='formSzukaj'_id='formSzukaj'
ALIGN='CENTER'>MENU_L:__<input_name='username'
type='text' id='username' value='$MENU_L'> <INPUT type='button'
name='Submit' value='Zmien'
 OnClick='funkcja_update('menu','MENU_L',
'krzeslo')'></form>";

OK, now that looks a lot better. However, the execution of your program
suffers from a logistics error. OnClick is a client-side function, while
you're trying to do something server-side i.e. inserting data into a
database. What you need to do is point the form action to a script that
will do the server-side stuff for you. I like to do everything in the same
script, so here's what I think it could look like:

<?
/* I don't know what the variables $opis and $pole are, or where you get
their values from, but here goes... */

function funkcja_update($tabela,$pole,$opis) {
$link__=_mysql_connect("localhost",_"database",_"password")_or_die_("Server
die");
mysql_select_db_("database")_or_die_("Baza_die");
$query_=_"UPDATE_$tabela_SET_opis='$opis'_WHERE
pole='$pole'";
return $result_=_mysql_query_($query);
}

if ($_POST['Submit']) {
# User pressed submit button, update db
funkja_update("var1","var2","var3");
} else {
# We need to display the form
$middle = "<form_action='$_SERVER[PHP_SELF]'
name='formSzukaj'_id='formSzukaj'
ALIGN='CENTER'>MENU_L:__<input_name='username'
type='text' id='username' value='$MENU_L'> <INPUT type='button'
name='Submit' value='Zmien'></form>";
# The form is still not displayed, we need to
# print the value of $middle
print $middle;
}
?>

I have obviously not tested the above. If you still have problems, make sure
that the variable you collect from the form (username) is passed into the
function.

Albe

--
http://www.ninja.up.ac.za

Report this thread to moderator Post Follow-up to this message
Old Post
.:Ninja
03-27-04 04:13 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 03:29 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.