Advertisement
DArcher

post.php source

Feb 10th, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.74 KB | None | 0 0
  1. <?php
  2. //Change this is this are broken and you can't see why
  3.     error_reporting(0);
  4.     define('DB_NAME', 'aramisbl_help');
  5.     define('DB_USER', 'aramisbl_help');
  6.     define('DB_PASSWORD', 'kittens123');
  7.     define('DB_HOST', 'localhost');
  8.  
  9.     //MySQL_* function are depricated and will eventually be removed, it's best to go ahead and get into the habit of using mysqli
  10.     //$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  11.     $link = new mysqli(DB_HOST, DB_USER, DB_PASSWORD,DB_NAME);
  12.  
  13.     if($con->connect_errno){
  14.         die("SQL Failure to connect: {$con->connect_error}");
  15.     }
  16.  
  17.     //With MySQLi you can select the DB
  18.     //$db_selected = mysql_select_db(DB_NAME, $link);
  19.  
  20.     //The above error catcher will also handle DB issues
  21.     //if (!$db_selected) {
  22.     //    die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
  23.     //}
  24.  
  25.     //This is the WRONG way to get these
  26.     //$lista = $_POST['listItem[]']; #THIS IS LINE 20
  27.     //$listb = $_POST['listPrice[]']; #THIS IS LINE 21
  28.  
  29.     //This is one right way
  30.     $lista = serialize($_POST['listItem']);
  31.     $listb = serialize($_POST['listPrice']);
  32.  
  33.     $list_name = $_POST['listname'];
  34.     $user_name = $_POST['username'];
  35.     $password = $_POST['password'];
  36.  
  37.    //I wrap my variables in curly brackets because to me, it's easier to read
  38.     $add_listname = "INSERT INTO mylist_add (lista, listb, listname, `user`, password) VALUES ('{$lista}', '{$listb}', '{$list_name}', '{$user_name}', '{$password}')";
  39.  
  40.     //MySQLi does things differently
  41.     //if (!mysql_query($add_listname)) {
  42.     //    die('ERROR: ' . mysql_error());
  43.     //}
  44.  
  45. $exeAdd = $link->query($add_listname);
  46.     if (!empty($link->error)) {
  47.         die('ERROR: ' . $link->error);
  48.     }
  49.  
  50. //Slight change
  51. //mysql_close();
  52.  
  53. /*
  54.  * The following is just to get all saved data
  55.  */
  56. $getRawData = "SELECT * FROM mylist_add";
  57.  
  58. $exeGetList = $link->query($getRawData);
  59. $thSet = false;
  60. $th = "";
  61.  
  62. echo "View this pages source here: <a href='http://pastebin.com/hqaDFufy'>http://pastebin.com/hqaDFufy</a><br><br>";
  63.  
  64. echo "Raw Data:<br>";
  65. $rawData = "";
  66. while($r = $exeGetList->fetch_array(MYSQLI_ASSOC)){
  67.     if(!$thSet){
  68.         $th .= "<thead><tr>";
  69.     }
  70.     $rawData .= "<tr>";
  71.     foreach($r  AS $col => $val){
  72.         if(!$thSet){
  73.             $th .= "<th style='border:1px solid #000; padding:3px;'>{$col}</th>";
  74.         }
  75.         $rawData .= "<td style='border:1px solid #000; padding:3px;'>{$val}</td>";
  76.     }
  77.     if(!$thSet){
  78.         $th .= "</tr></thead>";
  79.     }
  80.     $rawData .= "</tr>";
  81.     $thSet = true;
  82. }
  83.  
  84. echo "<table style='border:1px solid #000'>{$th}<tbody>{$rawData}</tbody></table><br><br>";
  85.  
  86. $link->close();
  87.  
  88. echo $add_listname;
  89.  
  90. echo "<pre>";
  91. var_dump($_POST);
  92. echo "</pre>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement