Jump to content

[SOLVED] WML form wont insert record into mysql via php.


oriental_express

Recommended Posts

Hi there everyone, im kinda having trouble getting my application to store data, my problem is that it seems to connect to mysql but then it says "  ("Could not add data to the table"); "

 

Im using this wml deck

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" 
   "http://www.wapforum.org/DTD/wml_1.1.xml"> 

<wml>

<card id="aged" title="Aged Charites">
<p align="center">Select charity to donate </p>

   <p>
     <select>
    	     <option title="Pilgrim Homes"         onpick="#pilgrimhomes">Pilgrim Homes</option>
     	     <option title="Guild Care"            onpick="#guildcare">Guild Care</option>
             <option title="Carers UK"             onpick="#carersuk">Carers UK</option>
             <br/><br/>
           </p>

              <p>
              <a href="menu.wml#main">Main menu</a>
              </p>

</card>


<card id="pilgrimhomes" title="Pilgrim Homes">
       <p>We have been looking after needy, elderly Christians since 1807.<br/></p>

             <p align="center"><b>Form<b/></p>

                  <p>
	   	Name:  <input name="name" size="15"/>
		Adddress:   <input name="address" size="15"/>
		Credit card no:  <input name="ccn" size="15"/>
		Expiry date mm/yy:  <input name="expirydate" size="15"/>
		Security code:  <input name="securitycode" size="15"/>
		Amount to donate:  <input name="amount" size="15"/>

		<anchor>
                          <go method="post" href="agedpillgrimhomes.php">
          			<postfield name="name" value="$(name)"/>
          			<postfield name="address" value="$(address)"/>
          			<postfield name="ccn" value="$(ccn)"/>
          			<postfield name="expirydate" value="$(expirydate)"/>
			<postfield name="securitycode" value="$(securitycode)"/>
			<postfield name="amount" value="$(amount)"/>
        		</go>
        			Submit
      			</anchor>

	  </p>

<p>
<a href="menu.wml#main">Main menu</a>
    
</p>

</wml>

 

 

and this is my php code to store the data but its not working

 

<?php header('Content-type: text/vnd.wap.wml'); ?>
<?php echo '<?xml version="1.0"?'.'>'; ?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd">

<?php
#this script stores form entry data as before but will validate for empty fields
# and check for a duplicate record of the book, in either case an error message
# will be displayed in the client

import_request_variables("P", "mypost_");

/* Get the posted book form's values from the request object*/

$name = $mypost_name;
$address = $mypost_address;
$ccn = $mypost_ccn;
$expirydate = $mypost_expirydate;
$securitycode = $mypost_securitycode;
$amount = $mypost_amount;

if (empty($name) || empty($address) || empty($ccn) || empty($expirydate) || empty($securitycode) || empty($amount)) 
{  
echo "Please go back and fill in all the fields"; 
}  
else 
{ 
//db connection - Note how the next few lines have moved away from the book data storage SQL

$connection = @mysql_pconnect("localhost", "admin", "admin") or die("cannot make connection");  
/* Set up database and table names */	
$db_name = "wml";  
$table_name = "agedpillgrimhomes"; 


//Open db connection
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());	

$query = "SELECT name FROM $table_name WHERE name ='$name'"; 
$result = mysql_query($query, $connection); 
$numrows = mysql_num_rows($result); 

if ($numrows == "0") 
{
	//No match - book is unique

	//Create SQL string
	$insert = "INSERT INTO $table_name (name,address,ccn,expirydate,securitycode,amount) VALUES      ('$name','$address','$ccn','$expirydate','$securitycode','$amount'"; 

       mysql_query($insert) or die ("Could not add data to the table");

	echo "Your donation has been successfully recieved";

} 
else 
{ 
	//The book has been entered on a previous occasion
	echo "Your donation was not accepted this time"; 
	exit();  
} 

}
?>

 

ive created a database via mysql but does not work cause the record wont insert. Ive made sure the phone simulator is in good order but still no luck. Can anyone help please :)

 

Thanks

Link to comment
Share on other sites

//Create SQL string

$insert = "INSERT INTO $table_name (name,address,ccn,expirydate,securitycode,amount) VALUES      ('$name','$address','$ccn','$expirydate','$securitycode','$amount'";

 

      mysql_query($insert) or die ("Could not add data to the table");

 

echo "Your donation has been successfully recieved";

 

 

that bit exactly.

Link to comment
Share on other sites

change it to

 

 

      $insert = "INSERT INTO $table_name (name,address,ccn,expirydate,securitycode,amount) VALUES      ('$name','$address','$ccn','$expirydate','$securitycode','$amount'";

     

      mysql_query($insert) or die (mysql_error());

     

      echo "Your donation has been successfully recieved";

 

Link to comment
Share on other sites

wierd problems

 

Now i have

 

" you have an erro in your sql syntax; check the manual that coressponds to the mysql server version for the right syntax to use near " at line 1

 

???

 

Thanks for your help by the way.

Any other ideas ?

 

lol, i used that method to find the problem with your query. Your missing a ")" on VALUES "("

this should work

 

<?php header('Content-type: text/vnd.wap.wml'); ?>
<?php echo '<?xml version="1.0"?'.'>'; ?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd">

<?php
#this script stores form entry data as before but will validate for empty fields
# and check for a duplicate record of the book, in either case an error message
# will be displayed in the client

import_request_variables("P", "mypost_");

/* Get the posted book form's values from the request object*/

$name = $mypost_name;
$address = $mypost_address;
$ccn = $mypost_ccn;
$expirydate = $mypost_expirydate;
$securitycode = $mypost_securitycode;
$amount = $mypost_amount;

if (empty($name) || empty($address) || empty($ccn) || empty($expirydate) || empty($securitycode) || empty($amount)) 
{  
echo "Please go back and fill in all the fields"; 
}  
else 
{ 
//db connection - Note how the next few lines have moved away from the book data storage SQL

$connection = @mysql_pconnect("localhost", "admin", "admin") or die("cannot make connection");  
/* Set up database and table names */	
$db_name = "wml";  
$table_name = "agedpillgrimhomes"; 


//Open db connection
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());	

$query = "SELECT name FROM $table_name WHERE name ='$name'"; 
$result = mysql_query($query, $connection); 
$numrows = mysql_num_rows($result); 

if ($numrows == "0") 
{
	//No match - book is unique

	//Create SQL string
	$insert = "INSERT INTO $table_name (name,address,ccn,expirydate,securitycode,amount) VALUES    ('$name','$address','$ccn','$expirydate','$securitycode','$amount')"; 

       mysql_query($insert) or die ("Could not add data to the table");

	echo "Your donation has been successfully recieved";

} 
else 
{ 
	//The book has been entered on a previous occasion
	echo "Your donation was not accepted this time"; 
	exit();  
} 

}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.