Jump to content

php help please


finney2005

Recommended Posts

// 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 by Ch0cu3r
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by ginerjm
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

....

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)

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.