Hi,
I am trying to update a MySQL database using a PHP script embeded in a WML
page. Here is my code:
The following is register2.php:
<wml>
> <template>
> <do type='prev' label='Back'>
> <prev/>
> </do>
> <do type='accept' label='Accept'>
> <go href="#card2"/>
> </do>
> </template>
>
> <card id="register2" title="Register2">
> <p>
> First Name: <input name="first" size="15"/><br/>
> Last Name: <input name="last" size="15"/><br/>
> Address: <input name="address" size="15"/><br/>
> Position: <input name="position" size="15"/><br/>
> </p>
> </card>
>
> <card id="card2" title="Registered">
> <p>
> <?php
>
> $db = mysql_connect("localhost", "root");
>
> mysql_select_db("mydb",$db);
>
> $sql = "INSERT INTO employees (first,last,address,position)
> VALUES ('$(first)','$(last)','$(address)','$(position)')";
>
> $result = mysql_db_query ("mydb", $sql);
>
> echo "$sql";
> ?>
> </p>
> </card>
> </wml>
>
Then I run register (to see if the database has been updated)!
> The following is register.php:
>
> </wml>
>
> <?php
> // send wml headers
> header("Content-type: text/vnd.wap.wml");
> echo "<?xml version=\"1.0\"?>";
> echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\""
> . " \"http://www.wapforum.org/DTD/wml_1.1.xml\">";
> ?>
> <wml>
> <template>
> <do type='prev' label='Back'>
> <prev/>
> </do>
> </template>
> <card id="register" title="Register">
> <p>
> <?php
> $db = mysql_connect("localhost", "root");
> mysql_select_db("mydb",$db);
> $result = mysql_query("SELECT * FROM employees",$db);
> printf("First Name: %s\n<br/>", mysql_result($result,0,"first"));
> printf("Last Name: %s\n<br/>", mysql_result($result,0,"last"));
> printf("Address: %s\n<br/>", mysql_result($result,0,"address"));
> printf("Position: %s\n<br/>", mysql_result($result,0,"position"));
>
> </p>
> </card>
> </wml>
In the the following line:
printf("First Name: %s\n<br/>", mysql_result($result,0,"first"));
the 0 is the row we want to view. Since I created an empty database this value
is initially 0. If i run register2.php a second time I have to increment this
0 to 1 before running register.php and so on.
You will see in register2.php that i have echied out $sql and it has the
correct value for exammple:
INSERT INTO employees (first,last,address,position) VALUES
('Kevin','Connolly','Somewhere','Manager')
but when I look at the database it has:
First Name:
Last Name:
Address:
Position:
instead of
First Name: Kevin
Last Name: Connolly
Address: Somewhere
Position: Manager
The reason I have
INSERT INTO employees (first,last,address,position) VALUES
('$(first)','$(last)','$(address)','$(position)')
is because in WML variables are stored as $(first) and not just $first like in
HTHML.
Somewhere between
$sql = "INSERT INTO employees (first,last,address,position)
> VALUES ('$(first)','$(last)','$(address)','$(position)')";
AND
> $result = mysql_db_query ("mydb", $sql);
it seemes to loose the values of all my variables!!
I would appreciate any help anyone can be since I have been working in this
for 2 days solid now and haven't managed to fix it (though i have managed to
recreate it in many different ways!!)
Thank you,
Kevin.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]