finney2005 Posted August 28, 2014 Share Posted August 28, 2014 (edited) // database connection strings. change these to your DB and Table names. $dbName = "a6474605_order"; $tableName = "godfathersorder"; // connect to the table mysql_select_db(a6474605_order)or die("cannot select DB"); if (!$link) { exit('Error: Could not connect to MySQL server!'); } // lets prepare some files to capture what is going on. $incomingJson = 'json.txt'; //$fullArray = 'fullArray.txt'; // needed if you enable the debugging secton below $sqlErrorLog = "sqlErrors.txt"; // initialize the string with a blank value $string = ""; // start SEND data if ($_SERVER['REQUEST_METHOD'] === 'POST') { //capture incoming data error_reporting(1); $sig = $_POST["sig"]; $jsondata = $_POST["params"]; // this line captures the sent data so you can figure out what you need to send back. file_put_contents($incomingJson,$jsondata); // this line tells the application that the data send was successful. echo '{"Status":"Success"}'; // convert JSON to an array $array = json_decode($jsondata, TRUE); /* // formats the array to view it easier $results = print_r($array,true); file_put_contents($fullArray,$results); */ //get the total number of objects in the array $arrlength = count($array['Children']['1']['Properties']); // set while loop index $i = 0; //loop through array node and get row values while ($i < $arrlength ) { // get row value $value = $array['Children']['1']['Properties'][$i]['Value']."\n"; // convert delimited string to an array $arrayPieces = explode("|", $value); // get array values. This section would have to be modified to capture each value you are interested in. $rowName = $arrayPieces(0); // this variable will be blank if you don't name your rows. $Pizza = $arrayPieces(1); $STUFEDCRUST = $arrayPieces(2); $MOREINFO = $arrayPieces(3); $coldel = $arrayPieces(4); $price = $arrayPieces(5); $NAME = $arrayPieces(6); $ADDRESS1 = $arrayPieces(7); $ADDRESS2 = $arrayPieces( ; $ADDRESS3 = $arrayPieces(9); $POSTCODE1 = $arrayPieces(10); $POSTCODE2 = $arrayPieces(11); $PHONE = $arrayPieces(12); mysqli_select_db("godfathersorder", $link) // construct SQL statement $sql="INSERT INTO godfathersorder(Pizza, STUFEDCRUST, MOREINFO, coldel, price, NAME, ADDRESS1, ADDRESS2, ADDRESSS3, POSTCODE1, POSTCODE2,PHONE)VALUES('$Pizza', '$STUFEDCRUST', '$MOREINFO', '$coldel', '$price', '$NAME', '$ADDRESS1', '$ADDRESS2', '$ADDRESS3', '$POSTCODE1', '$POSTCODE2', '$PHONE')"; // insert SQL statement $result=mysql_query($sql); // catch any errors if($result){ // if successful do nothing for now. } else { // if failure, write to custom log $sqlError = "Error writing to database\n"; file_put_contents($sqlErrorLog, $sqlError, FILE_APPEND); } $i++; } } // end of POST ?> please help the insert into table does not seem to work as there is nothing going into mysql tabe the code leaves a json.text file to show the first part working but does not seem to put the contents into my table. please please help godfathersSERVER.php Edited August 28, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/290701-php-help-please/ Share on other sites More sharing options...
CroNiX Posted August 28, 2014 Share Posted August 28, 2014 It's not really any use trying to update this as it's already deprecated code! mysql extension will not be available in a future version of php, so even if you get this code working it won't work for very long into the future unless you never plan on upgrading PHP. Use mysqli or PDO db driver. Quote Link to comment https://forums.phpfreaks.com/topic/290701-php-help-please/#findComment-1489161 Share on other sites More sharing options...
finney2005 Posted August 28, 2014 Author Share Posted August 28, 2014 sorry i have just started learning maybe am learning outdated code i would realy like to get this working having spent so much time onit before i look at updating it thanks for you advice Quote Link to comment https://forums.phpfreaks.com/topic/290701-php-help-please/#findComment-1489162 Share on other sites More sharing options...
finney2005 Posted August 28, 2014 Author Share Posted August 28, 2014 can anyone please helpme understand why its not wrighting to the table? thanks agen Quote Link to comment https://forums.phpfreaks.com/topic/290701-php-help-please/#findComment-1489163 Share on other sites More sharing options...
ginerjm Posted August 28, 2014 Share Posted August 28, 2014 (edited) First - you REALLY should listen to what others have said. The extension you are using for db access is soon going to disappear - then where will you feeble knowledge of MySQL_* be? Second - you turn on error reporting in the middle of the code. Turn it on at the beginning and turn it on correctly. error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); so that you can SEE the errors. Third - is the db name you are using a defined Constant? If not your error is right there in your select. Hopefully turning on error checking will pick that up as well as any other errors you have. Fourth - Please don't use subjects for your posts such as the one you just used. Think about ir - Everybody here needs help. How does your un-impressive subject get the attention your problem requires? Edited August 28, 2014 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/290701-php-help-please/#findComment-1489165 Share on other sites More sharing options...
finney2005 Posted August 28, 2014 Author Share Posted August 28, 2014 sorry like i said i realy new to all this and am trying to teach myself along the way and realy appreciate all the help and advice i get. i have put the error reporting ant the top of my php and will do form now on. the errors reporting did point out my mistake about the db name. it does not report any other mistakes once changed and is still not wrighting to the table. i have changed: // construct SQL statement $sql="INSERT INTO godfathersorder(Pizza, STUFEDCRUST, MOREINFO, coldel, price, NAME, ADDRESS1, ADDRESS2, ADDRESSS3, POSTCODE1, POSTCODE2,PHONE)VALUES('$Pizza', '$STUFEDCRUST', '$MOREINFO', '$coldel', '$price', '$NAME', '$ADDRESS1', '$ADDRESS2', '$ADDRESS3', '$POSTCODE1', '$POSTCODE2', '$PHONE')"; to mysqli_query($link,"INSERT INTO $tableName(Pizza, STUFEDCRUST, MOREINFO, coldel, price, NAME, ADDRESS1, ADDRESS2, ADDRESSS3, POSTCODE1, POSTCODE2,PHONE)VALUES('$Pizza', '$STUFEDCRUST', '$MOREINFO', '$coldel', '$price', '$NAME', '$ADDRESS1', '$ADDRESS2', '$ADDRESS3', '$POSTCODE1', '$POSTCODE2', '$PHONE'"); its still not wrighting into the table but the code seems to run fine. thanks agen for you help Quote Link to comment https://forums.phpfreaks.com/topic/290701-php-help-please/#findComment-1489175 Share on other sites More sharing options...
CroNiX Posted August 28, 2014 Share Posted August 28, 2014 Instead of: $sqlError = "Error writing to database\n"; Which tells you nothing useful, grab the actual error from mysqli $sqlError = mysqli->error; Quote Link to comment https://forums.phpfreaks.com/topic/290701-php-help-please/#findComment-1489176 Share on other sites More sharing options...
finney2005 Posted August 28, 2014 Author Share Posted August 28, 2014 thank you that seems to be i lot more usefull then what i had but still no error. the php recives the .json file which i can see on the sever but does not seem to convert it and put it in the table but does not show any errors. could this be aproblem on the webhost side as am using phpmyadmin.thanks agen Quote Link to comment https://forums.phpfreaks.com/topic/290701-php-help-please/#findComment-1489179 Share on other sites More sharing options...
mikosiko Posted August 28, 2014 Share Posted August 28, 2014 .... its still not wrighting into the table but the code seems to run fine. ... Really?... the posted code has several mistakes, which probably means that it was posted incomplete... where are you connecting to the database?... Do you know that you CANNOT mix mysql and mysqli sentences?.. you must pick one or another (you already were told that mysql is deprecated and you should not use it)... last but not least... something is missing here ,"......PHONE)VALUES('$Pizza', .... you have a load of work to do... best choice... learn and re write your code using PDO now (or mysqli even when it is a little more cumbersome than PDO) Quote Link to comment https://forums.phpfreaks.com/topic/290701-php-help-please/#findComment-1489180 Share on other sites More sharing options...
ginerjm Posted August 28, 2014 Share Posted August 28, 2014 Besides learning php you could really use some help with writing English. Phpadmin has nothing at all to do with json or php. Why do you mention it here? Quote Link to comment https://forums.phpfreaks.com/topic/290701-php-help-please/#findComment-1489181 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.