Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Change this is this are broken and you can't see why
- error_reporting(0);
- define('DB_NAME', 'aramisbl_help');
- define('DB_USER', 'aramisbl_help');
- define('DB_PASSWORD', 'kittens123');
- define('DB_HOST', 'localhost');
- //MySQL_* function are depricated and will eventually be removed, it's best to go ahead and get into the habit of using mysqli
- //$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
- $link = new mysqli(DB_HOST, DB_USER, DB_PASSWORD,DB_NAME);
- if($con->connect_errno){
- die("SQL Failure to connect: {$con->connect_error}");
- }
- //With MySQLi you can select the DB
- //$db_selected = mysql_select_db(DB_NAME, $link);
- //The above error catcher will also handle DB issues
- //if (!$db_selected) {
- // die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
- //}
- //This is the WRONG way to get these
- //$lista = $_POST['listItem[]']; #THIS IS LINE 20
- //$listb = $_POST['listPrice[]']; #THIS IS LINE 21
- //This is one right way
- $lista = serialize($_POST['listItem']);
- $listb = serialize($_POST['listPrice']);
- $list_name = $_POST['listname'];
- $user_name = $_POST['username'];
- $password = $_POST['password'];
- //I wrap my variables in curly brackets because to me, it's easier to read
- $add_listname = "INSERT INTO mylist_add (lista, listb, listname, `user`, password) VALUES ('{$lista}', '{$listb}', '{$list_name}', '{$user_name}', '{$password}')";
- //MySQLi does things differently
- //if (!mysql_query($add_listname)) {
- // die('ERROR: ' . mysql_error());
- //}
- $exeAdd = $link->query($add_listname);
- if (!empty($link->error)) {
- die('ERROR: ' . $link->error);
- }
- //Slight change
- //mysql_close();
- /*
- * The following is just to get all saved data
- */
- $getRawData = "SELECT * FROM mylist_add";
- $exeGetList = $link->query($getRawData);
- $thSet = false;
- $th = "";
- echo "View this pages source here: <a href='http://pastebin.com/hqaDFufy'>http://pastebin.com/hqaDFufy</a><br><br>";
- echo "Raw Data:<br>";
- $rawData = "";
- while($r = $exeGetList->fetch_array(MYSQLI_ASSOC)){
- if(!$thSet){
- $th .= "<thead><tr>";
- }
- $rawData .= "<tr>";
- foreach($r AS $col => $val){
- if(!$thSet){
- $th .= "<th style='border:1px solid #000; padding:3px;'>{$col}</th>";
- }
- $rawData .= "<td style='border:1px solid #000; padding:3px;'>{$val}</td>";
- }
- if(!$thSet){
- $th .= "</tr></thead>";
- }
- $rawData .= "</tr>";
- $thSet = true;
- }
- echo "<table style='border:1px solid #000'>{$th}<tbody>{$rawData}</tbody></table><br><br>";
- $link->close();
- echo $add_listname;
- echo "<pre>";
- var_dump($_POST);
- echo "</pre>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement