PHP, MySQL and WML!

From: Date: Thu, 25 Jan 2001 09:02:18 +0000
Subject: PHP, MySQL and WML!
Groups: php.db 
Request: Send a blank email to php-db+get-6156@lists.php.net to get a copy of this message
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.

« previous php.db (#6156) next »