hi im trying to insert a url and its content into 2 table but i will use an id from a table and insert this id in multiple entries in the second table i hope i succeed to clarify my issue here the probleme that i can view data but i cant insert data in mysql using pdo all i got in mysql is NULL values is my code for more clarification
first my class file is like that Links.php
/** * Sets the object's properties using the values in the supplied array * * @param assoc The property values */ public function __construct1( $data=array() ) { if ( isset( $data['listURL'] ) ) $this->listURL = $data['listURL']; if ( isset( $data['hostname'] ) ) $this->hstname = $data['hostname']; } /** * Sets the object's properties using the values in the supplied array * * @param assoc The property values */ public function __construct2( $data=array() ) { if ( isset( $data['stringName'] ) ) $this->stringName = $data['stringName']; if ( isset( $data['stringUrl'] ) ) $this->stringUrl = $stringUrl = $data['stringUrl']; } /** * Sets the object's properties using the edit form post values in the supplied array * * @param assoc The form post values */ public function storeFormValues1 ( $params ) { // Store all the parameters $this->__construct1( $params ); } /** * Sets the object's properties using the edit form post values in the supplied array * * @param assoc The form post values */ public function storeFormValues2 ( $params ) { // Store all the parameters $this->__construct2( $params ); } public function insertlistFuncClass() { $conn = new PDO(DB_NDS, DB_USERNAME, DB_PASSWORD); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE); $sql = "INSERT INTO lists ( listURL, hostname ) VALUES (:listURL, :hostname)"; $st = $conn->prepare($sql); $st->bindValue( ":listurl", $this->url, PDO::PARAM_STR ); $st->bindValue( ":hostname", $this->hstname, PDO::PARAM_STR ); $st->execute(); $listId = $conn->lastInsertId(); $conn = null; } public function insertStringsFuncClass() { $listId = $this->listId; $conn = new PDO(DB_NDS, DB_USERNAME, DB_PASSWORD); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE); $sql = "INSERT INTO Strngs ( stringName, stringUrl, listId ) VALUES (:stringName, :stringUrl, :listId)"; $st = $conn->prepare($sql); $st->bindValue( ":stringName", $this->channelName, PDO::PARAM_STR ); $st->bindValue( ":stringUrl", $this->streamUrl, PDO::PARAM_STR ); $st->bindValue( ":listId", $listId, PDO::PARAM_STR ); $st->execute(); $conn = null; }
for file.php it is like that:
require("config.php"); session_start(); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); function insertlists() { header('Content-Type: application/json'); header('Access-Control-Allow-Origin: *'); header('allow-origin: *'); header("Access-Control-Allow-Headers: ACCEPT, CONTENT-TYPE, X-CSRF-TOKEN"); header("Access-Control-Allow-Methods: GET, POST, OPTIONS, DELETE"); $url = $_POST['url']; print $url . " was successfully submitted "; $createdate = date('Y/m/d H:i:s'); $hstname = parse_url($url, PHP_URL_HOST); $listsInfo = array(); $listArr = array( 'listURL' => $url, 'hostname' => $hstname ); $listInfo[] = $playlistArr; print_r($playlistArr); $mylink = new Lists; $mylink->storeFormValues1($_POST); $mylink->insertPlaylistFuncClass(); } function insertStrings() { insertlists(); header('Content-Type: application/json'); header('Access-Control-Allow-Origin: *'); header('allow-origin: *'); header("Access-Control-Allow-Headers: ACCEPT, CONTENT-TYPE, X-CSRF-TOKEN"); header("Access-Control-Allow-Methods: GET, POST, OPTIONS, DELETE"); $m3ufile = file_get_contents($url); $find = ['/((?:https?|rtmp)://(?:S*?.S*?)(?:[s)[]{};"'<]?(.mp4)|.s|$))/', '/((?:https?|rtmp)://(?:S*?.S*?)(?:[s)[]{};"'<]?(.avi)|.s|$))/', '/((?:https?|rtmp)://(?:S*?.S*?)(?:[s)[]{};"'<]?(.mkv)|.s|$))/']; $replace = ['', '', '']; $result = preg_replace($find, $replace, $m3ufile); $re = '/((?:https?|rtmp)://(?:S*?.S*?)(?:[s)[]{};"'<]|.s|$))/'; $attributes = '/([a-zA-Z0-9-_]+?)="([^"]*)"/'; preg_match_all($re, $result, $matches); $items = array(); foreach ($matches[0] as $list) { preg_match($re, $list, $matchList); $mediaURL = preg_replace("/[nr]/", "", $matchList[3]); $mediaURL = preg_replace('/s+/', '', $mediaURL); $channelName = $matchList[2]; $stringUrl = $mediaURL; $newdata = array( 'stringName' => $matchList[2], 'listURL' => $url, 'stringUrl' => $mediaURL, 'listId' => ':listId' ); preg_match_all($attributes, $list, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $newdata[$match[1]] = $match[2]; } $items[] = $newdata; echo 'Insert: (' . $matchList[2] . ' - ' . $mediaURL . ' - ' . $url . ')' . "rn"; $mylink = new Article; $mylink->storeFormValues2($_POST); $mylink->insertstringsFuncClass(); } } insertStrings();
all i got for inserted values is null
Advertisement
Answer
i found a solution i just work with global
i put it in file.php in the two function and tadaaa it worked
global $listId;
but i had to insert from this file not from the class .