WAP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreWAP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old June 11th, 2006, 08:05 AM
noxhanti noxhanti is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 23 noxhanti User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 19 m 48 sec
Reputation Power: 0
Insert into mysql table

I don't know much php or wml. I need to be able to insert values into a mysql table and have tried various adaptations of code found in various forums. The ones below are the only ones that have been recognised by my browser (WinWap Smartphone) as wml content. I now get the error message : syntax error 17 :Unexpected end of the wml source. can anyone see where I am going wrong. I have tried combinations of saving them as wml or php files, using POST instead of GET and have run them through php and wml code validator utilities which suggest that the code should be OK.

repdetails.wml

Code:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd">

<wml>
  <card id="card2" title="userdetails">
    
    <p>
      User Details:<br/>
      
      Enter User ID<br/>
      <input name="repid"/><br/>
      Enter Name<br/>
      <input name="name"/><br/>
      Enter address<br/>
      <input name="address"/><br/>
    
       Enter Telephone Number<br/>
      <input name="tel"/><br/>
       

      <anchor>
        <go method="get" href="insert.php">
         <postfield name="customer_id" value="$(repid)"/>
          <postfield name="name" value="$(name)"/>
          <postfield name="address" value="$(address)"/>          
          <postfield name="tel" value="$(tel)"/>          
        </go>
        Submit Data
      </anchor>
    </p>
  </card>
</wml>

insert.php

Code:
<?php
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>
<card id="card2" title="add">
<p>

<?php

//connect to database server
$connection = mysql_connect("localhost", "root", "password")
or die ("connection failed");

//Select the database
$db = mysql_select_db("db_wap", $connection)
or die ("failed to select database <br />\n");

//execute a query
$sql = mysql_query("INSERT INTO 'tbl_User' ('repid', 'name', 'address', 'tel') Values ('$_GET[repid]', '$_GET[name]', '$_GET[address]', '$_GET[tel]')") or die("Input failed");

if (!$sql) {
echo "Error cannot Insert record.!!!<BR>"; mysql_error;exit;
}else {
echo "record inserted";
}

//insert OK inform user
	
print "<b>Customer Database:</b> <br/>";

?>
</p>
</card>
</wml>

Reply With Quote
  #2  
Old June 11th, 2006, 09:04 AM
jabba_29's Avatar
jabba_29 jabba_29 is offline
Back in HEL
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Feb 2002
Location: Finland
Posts: 8,613 jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)  Folding Points: 57777 Folding Title: Beginner FolderFolding Points: 57777 Folding Title: Beginner FolderFolding Points: 57777 Folding Title: Beginner Folder
Time spent in forums: 3 Months 3 Weeks 3 Days 5 h 32 m 57 sec
Reputation Power: 1550
Send a message via ICQ to jabba_29 Send a message via AIM to jabba_29 Send a message via MSN to jabba_29 Send a message via Yahoo to jabba_29 Send a message via Google Talk to jabba_29 Send a message via Skype to jabba_29
Facebook
You are using die and exit functions, this means that the script will stop if it fails,
so you cards will not be fully written out - thus the error message.

You are using postfield with get, this is fine,
but you also need to validate your entry, a user could easily do something nasty if you are not careful.

In your insert.php file, you could do something like.
PHP Code:
<?php
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>
<card id="card2" title="add">
<p>
<?php
$connection 
mysql_connect("localhost""root""password");
if (!
$connection):
echo 
'cannot connect';
else:
// continue, we can connect
$db mysql_select_db("db_wap"$connection);
if (!
$db):
echo 
'cannot select db';
else:
// do your stuff
endif;
// end first conditional
endif;
?>
</p>
</card>
</wml>
Also, <BR> should be <br/> or <br /> in wml.
HTH.

Also note that if error reporting is switched on this may kill yoru WML as it spits out the errors usually before the page, and you have a coulple of undefined variables
__________________
Cheers,

Jamie


# skiFFie | Home of the 'accessibility module' for Drupal
# Jamie Burns [me] Accessibility Module [drupal]
# guidelines | search | wap resources | not getting help | fold to cure

# Any form of employment is strictly prohibited ......


__________________

Let the might of your compassion arise to bring a quick end
to the flowing stream of the blood and tears .....
Please hear my anguished words of truth.

__________________

Reply With Quote
  #3  
Old June 11th, 2006, 10:21 AM
noxhanti noxhanti is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 23 noxhanti User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 19 m 48 sec
Reputation Power: 0
insert into mysql table

I logged in not expecting a reply so soon. I added the if statements at first with : and them with brackets as below but I get not wml content. Where and how would I define the variables and do I have to.I don't know where I am going wrong
Code:
<?php
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>
<card id="card2" title="add">
<p>

<?php

//connect to database server
$connection = mysql_connect("localhost", "root", "password");
if (!$connection){
echo 'cannot connect';
}
else{


//Select the database
$db = mysql_select_db("db_wap", $connection);
}
if (!$db){
echo 'cannot select db';
}
endif;
}
//execute a query
$sql = mysql_query("INSERT INTO 'tbl_User' ('repid', 'name', 'address', 'tel') Values ('$_GET[repid]', '$_GET[name]', '$_GET[address]', '$_GET[tel]')") or die("Input failed");

if (!$sql) {
echo "Error cannot Insert record.!!!<br />"; mysql_error;exit;
}else {
echo "record inserted";
}endif;

//insert OK inform user
	
print "<b>Customer Database:</b> <br/>";

?>
</p>
</card>
</wml>

Reply With Quote
  #4  
Old June 11th, 2006, 10:41 AM
jabba_29's Avatar
jabba_29 jabba_29 is offline
Back in HEL
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Feb 2002
Location: Finland
Posts: 8,613 jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 9th Grade (Above 100000 Reputation Level)  Folding Points: 57777 Folding Title: Beginner FolderFolding Points: 57777 Folding Title: Beginner FolderFolding Points: 57777 Folding Title: Beginner Folder
Time spent in forums: 3 Months 3 Weeks 3 Days 5 h 32 m 57 sec
Reputation Power: 1550
Send a message via ICQ to jabba_29 Send a message via AIM to jabba_29 Send a message via MSN to jabba_29 Send a message via Yahoo to jabba_29 Send a message via Google Talk to jabba_29 Send a message via Skype to jabba_29
Facebook
You are probably getting parse error - you have endif; that should't be there.
Sorry about potential confusion - that's just the way I code.
This should be closer, but I don't usually write this way, so there may well be errors.
PHP Code:
<?php
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>
<card id="card2" title="add">
<p>

<?php

//connect to database server
$connection mysql_connect("localhost""root""password");
if (!
$connection){
    echo 
'cannot connect';
} else {

    
//Select the database
    
$db mysql_select_db("db_wap"$connection);

    if (!
$db){
    echo 
'cannot select db';
    } else {

        
//execute a query
        // SANITIZE YOUR DATA !!
        
$sql mysql_query("
            INSERT INTO 'tbl_User' ('repid', 'name', 'address', 'tel') 
            VALUES ('"
$_GET['repid'] ."', '"$_GET['name'] ."', 
                '"
$_GET['address'] ."', '"$_GET[tel] ."')");

        if (!
$sql) {
        echo 
"Error cannot Insert record.!!!<br />"mysql_error;exit;
        } else {
            
            echo 
"record inserted";
        }

    }

}
    
print 
"<b>Customer Database:</b> <br/>";

?>
</p>
</card>
</wml>


Can you test the output in Firefox or Opera browsers, then you will be able to see the exact errors in the source code?

Reply With Quote
  #5  
Old June 11th, 2006, 12:16 PM
noxhanti noxhanti is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 23 noxhanti User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 19 m 48 sec
Reputation Power: 0
Thanks for your help and time.I tried the changes and this time I get Syntax error 1 (202) The WML source is wrong. I have run it through the php syntax checker from http://www.meandeviation.com/ and the wml validator at http://validator.w3.org/ (had to alter the headers) and everything seemed fine. I thought maybe I hadn't set up my Apache httpd.conf file properly (see below) or Winwap may have specific requirements.
#####################################
#phpconfiguration
LoadModule php4_module c:/php/php4apache2.dll
AddType application/x-httpd-php .php

#this is the php config section
ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php/php.exe"

##########

#Wap configuration
# For WML scripted languages

AddType application/vnd.wap.wmlc .wmlc
AddType text/vnd.wap.vmlscript .wmls
AddType application/vnd.wap.wmlscriptc .wmlsc
AddType text/vnd.wap.wml .wml
AddType image/vnd.wap.wbmp .wbmp

# For PHP 4.x, use this:

AddType application/x-httpd-php .wml

Code:
<?php
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>
<card id="card2" title="add">
<p>

<?php

//connect to database server
$connection = mysql_connect("localhost", "root", "password");
if (!$connection){
echo 'connection failed';
} else {

//Select the database
$db = mysql_select_db("db_wap", $connection)
;
}
if (!$db){
echo "cannot select db";
}else {
//execute a query
$sql = mysql_query("INSERT INTO 'tbl_User' ('repid', 'name', 'address', 'tel')
 Values ('". $_GET['repid'] ."', '". $_GET['name'] ."', '". $_GET['address'] ."', '". $_GET[tel] ."')"); 
}
if (!$sql) {
echo "Error cannot Insert record.!!!<br />"; mysql_error;exit;
}else {
echo "record inserted";
//insert OK inform user
}
?>
</p>
</card>
</wml>

Reply With Quote
  #6  
Old June 13th, 2006, 04:33 PM
noxhanti noxhanti is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 23 noxhanti User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 19 m 48 sec
Reputation Power: 0
tested my php script on IE and it stops at "input failed". Can anyone see anything wrong with my query or could it be that my values are not being passed from the form.

Reply With Quote
  #7  
Old June 13th, 2006, 07:55 PM
vrspectre's Avatar
vrspectre vrspectre is offline
I see semi-colons
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: Portland, OR
Posts: 297 vrspectre User rank is Sergeant (500 - 2000 Reputation Level)vrspectre User rank is Sergeant (500 - 2000 Reputation Level)vrspectre User rank is Sergeant (500 - 2000 Reputation Level)vrspectre User rank is Sergeant (500 - 2000 Reputation Level)vrspectre User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 10 h 38 m 59 sec
Reputation Power: 16
Send a message via AIM to vrspectre Send a message via Yahoo to vrspectre
Quote:
Originally Posted by noxhanti
tested my php script on IE and it stops at "input failed". Can anyone see anything wrong with my query or could it be that my values are not being passed from the form.


I don't see anything wrong w/ your query, have you tried echoing the values before you run the insert to see if they hold data? If they were empty you wouldn't get an error, it just wouldn't put anything in the DB field.

Also, what do you mean be "input failed" is that the entire error message in IE?

I don't know of a plugin for IE that will allow you to view wml files. That might be the problem. What happens when you use a phone capable of WML or the firefox WML plugin ?
__________________


Reply With Quote
  #8  
Old June 15th, 2006, 01:24 PM
noxhanti noxhanti is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 23 noxhanti User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 19 m 48 sec
Reputation Power: 0
I echoed the values and they did come up. i don't know what went wrong. The IE thing was explained to me by s.o..When I call the insert.php file in IE it produces a download file which shows me where the error occurs. "Input failed" comes just after the insert query i.e. if it doesn't work. anyway i have cheated and used WinMySQL Pro from http://www.winmysql.com/page4.html. it has a form and query generator and I was able to create something that worked in 10mins rather than agonising over it. by looking at the code I might be able to work out where I went wrong. I have produced the generated code below:

repdetails.wml

Code:
<?xml version="1.0"?>
<!-- generated by WinMySQL Professional 1.0 (http://www.winmysql.com/) - Unregistered copy -->
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>
<card id="HomeCard" ontimer="#MainCard" title="Our wap service">
<timer value="250"/>
<do type="accept" label="Main menu">
<go href="#MainCard"/>
</do> 
<p align="center"><b>WinMySQL WAP</b><br/><br/>
<img src="logo.wbmp" alt="WinMySQL Pro logo "/>
<br/><br/>"Options" to go
</p>
</card>
<card id="MainCard" title="Main Menu">
<do type="prev" label="Back"><prev/></do>
<p align="center">
<a href="#repid">Enter repid</a><br/>
<a href="#name">Enter name</a><br/>
<a href="#address">Enter address</a><br/>
<a href="#tel">Enter tel</a><br/>
<a href="#SubmitCard">Submit values</a>
</p>
</card>
<card id="repid" title="repid">
<do type="prev" label="Back"><prev/></do>
<p align="left">
Please, enter a value for repid : <br/>
<input type="text" name="repid"/>
</p>
</card>
<card id="name" title="name">
<do type="prev" label="Back"><prev/></do>
<p align="left">
Please, enter a value for name : <br/>
<input type="text" name="name"/>
</p>
</card>
<card id="address" title="address">
<do type="prev" label="Back"><prev/></do>
<p align="left">
Please, enter a value for address : <br/>
<input type="text" name="address"/>
</p>
</card>
<card id="tel" title="tel">
<do type="prev" label="Back"><prev/></do>
<p align="left">
Please, enter a value for tel : <br/>
<input type="text" name="tel"/>
</p>
</card>
<card id="SubmitCard" title="Submit values">
<do type="prev" label="Back"><prev/></do>
<do type="accept" label="Submit values">
<go method="post" href="mysql.php">
<postfield name="repid" value="$(repid)"/>
<postfield name="name" value="$(name)"/>
<postfield name="address" value="$(address)"/>
<postfield name="tel" value="$(tel)"/>
</go>
</do>
<p align="left">
You are about to submit the following values :<br/>
<b>repid : </b>$(repid)<br/>
<b>name : </b>$(name)<br/>
<b>address : </b>$(address)<br/>
<b>tel : </b>$(tel)<br/>
Use "options" to submit the current values or "back" to modify.
</p>
</card>
</wml>


mysql.php

Code:
<SCRIPT LANGUAGE="PHP">
header("Content-type: text/vnd.wap.wml");
$REMOTE_ADDR=$_SERVER["REMOTE_ADDR"];
$login=$_REQUEST["login"];
$password=$_REQUEST["password"];

 echo "<?xml version=".chr(34)."1.0".chr(34)."?>\n";
 echo "<!-- generated by WinMySQL Professional 1.0 (http://www.winmysql.com/) - Unregistered copy -->\n";
 echo "<!DOCTYPE wml PUBLIC ".chr(34)."-//WAPFORUM//DTD WML 1.1//EN".chr(34)." ".chr(34)."http://www.wapforum.org/DTD/wml_1.1.xml".chr(34).">\n\n";
 echo "<wml>\n";
echo "<card id=".chr(34)."MainAnswer".chr(34)." title=".chr(34)."Query result".chr(34).">\n";
  echo "<do type=".chr(34)."prev".chr(34)." label=".chr(34)."Back".chr(34)."><prev/></do>\n";
 echo "<p align=".chr(34)."center".chr(34).">\n";

 if (isset($login))
 $_CntResult=@mysql_connect("localhost",$login,$password);
 else
  $_CntResult=@mysql_connect("localhost","wapuser","wappass");

 if ($_CntResult<1)
  echo "connection to database refused -   MySQL unavailable or access denied !\n";
  else
  { $_WebQuery="insert into tbl_user (";

     if (isset($_REQUEST["repid"]))
      { $repid=$_REQUEST["repid"]; }
    if (isset($repid))
      $_WebQuery=$_WebQuery."repid".", ";

     if (isset($_REQUEST["name"]))
      { $name=$_REQUEST["name"]; }
    if (isset($name))
      $_WebQuery=$_WebQuery."name".", ";

     if (isset($_REQUEST["address"]))
      { $address=$_REQUEST["address"]; }
    if (isset($address))
      $_WebQuery=$_WebQuery."address".", ";

     if (isset($_REQUEST["tel"]))
      { $tel=$_REQUEST["tel"]; }
    if (isset($tel))
      $_WebQuery=$_WebQuery."tel";

    if  (substr($_WebQuery,strlen($_WebQuery)-2,2)==", ")
      $_WebQuery=substr($_WebQuery,0,strlen($_WebQuery)-2);

    $_WebQuery=$_WebQuery.") values(";

    if (isset($repid))
      $_WebQuery=$_WebQuery.$repid.", ";

    if (isset($name))
      $_WebQuery=$_WebQuery.chr(34).$name.chr(34).", ";

    if (isset($address))
      $_WebQuery=$_WebQuery.chr(34).$address.chr(34).", ";

    if (isset($tel))
      $_WebQuery=$_WebQuery.chr(34).$tel.chr(34);

    if  (substr($_WebQuery,strlen($_WebQuery)-2,2)==", ")
      $_WebQuery=substr($_WebQuery,0,strlen($_WebQuery)-2);

    $_WebQuery=$_WebQuery.")";

    $_QryResult=mysql_db_query("db_wap",$_WebQuery,$_CntResult);

    if (mysql_errno()==0)
      echo "<b>Record successfully inserted !</b>\n";
     else
       echo "<b>Record not inserted, reason given by server :<br/>\n<br/>\n".mysql_error()."</b>\n";  

    echo "</p>\n";
    echo "</card>\n";
    echo "</wml>\n";
   }

</SCRIPT>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreWAP Programming > Insert into mysql table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |