oriental_express Posted December 19, 2007 Share Posted December 19, 2007 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 Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 try $result = mysql_query($query, $connection) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
oriental_express Posted December 19, 2007 Author Share Posted December 19, 2007 try $result = mysql_query($query, $connection) or die(mysql_error()); it nows says cannot make connection Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 Check your connection information to the database/ Quote Link to comment Share on other sites More sharing options...
oriental_express Posted December 19, 2007 Author Share Posted December 19, 2007 no luck cause it now says could not add data to the table Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 no luck cause it now says could not add data to the table whats the actual error message? post it. Quote Link to comment Share on other sites More sharing options...
oriental_express Posted December 19, 2007 Author Share Posted December 19, 2007 //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. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 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"; Quote Link to comment Share on other sites More sharing options...
oriental_express Posted December 19, 2007 Author Share Posted December 19, 2007 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 ? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 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(); } } ?> Quote Link to comment Share on other sites More sharing options...
oriental_express Posted December 19, 2007 Author Share Posted December 19, 2007 Thank you so much ! phpsensei im ever so greatful ! Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 Thank you so much ! phpsensei im ever so greatful ! , mark the topic solved if you will sir. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.