i'm working on a project where there is posts .. which you can comment to. the comments are in an iframe which is embeded to the post. the iframe has the comment form and the queries to get and insert comments. my problem is that i want to refresh the iframe page whenever the comments table changes. for example i have a conversation with another user trought the comments i don't need to refresh the page to see new comments .. but rather the new comments show up in my comments section. any suggestion or bit of code will be good. thanks.
objectivec
mercredi 1 juillet 2015
How to insert multiple rows and files into mysql using php array?
How to insert multiple rows and upload files into mysql database using php array?
I want to add a 'Add More' Option in this form by which the same fields got duplicates down to it, and can easily insert multiple rows as well as file uploads to mysql database.
Here is the code :
<?php
// @author - Chetanaya Aggarwal
?>
<?php include('header_dashboard.php'); ?>
<?php include('session.php'); ?>
<?php $get_id = $_GET['id']; ?>
<body id="home">
<?php include('navbar_client.php'); ?>
<div class="container-fluid">
<div class="row-fluid">
<?php include('Device_sidebar.php'); ?>
<div class="span9" id="content">
<div class="row-fluid">
<!-- block -->
<div class="block">
<div class="navbar navbar-inner block-header">
<div class="muted pull-left">Upload Documents</div>
<div class="muted pull-right"><a id="return" data-placement="left" title="Click to Return" href="clients_list.php"><i class="icon-arrow-left icon-large"></i> Back</a></div>
<script type="text/javascript">
$(document).ready(function(){
$('#return').tooltip('show');
$('#return').tooltip('hide');
});
</script>
</div>
<div class="block-content collapse in">
<div class="alert alert-success"><i class="icon-info-sign"></i> Please Fill in required details</div>
<form class="form-horizontal" method="post" enctype="multipart/form-data">
<table style width="100%">
<tr>
<tr>
<td>
<div class="control-group">
<label class="control-label" style="font-size: 16px;" for="inputPassword"><b>Document Type</b></label>
<div class="controls">
<select name="docstype_id" class="chzn-select" required/>
<option></option>
<?php $docs_type=mysql_query("select * from docs_type")or die(mysql_error());
while ($row=mysql_fetch_array($docs_type)){
?>
<option value="<?php echo $row['docstype_id']; ?> Name <?php echo $row['docsname']; ?>"><?php echo $row['docsname']; ?></option>
<?php } ?>
</select>
</div>
</div>
</td>
<td>
<div class="control-group">
<label class="control-label" style="font-size: 16px;" for="inputPassword"><b>Document Copy</b></label>
<div class="controls">
<input name="Photo" class="input-file uniform_on" id="fileInput" type="file" required>
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="control-group">
<label class="control-label" style="font-size: 16px;" id="la-add-mob" for="inputPassword"><b>Document No.</b></label>
<div class="controls">
<input type="text" class="span8" name="file_no" id="file_no" placeholder="Document No.">
</div>
</div>
</td>
<td>
</td>
</tr>
<tr>
<td>
<div class="control-group">
<div class="controls">
<button name="save" id="save" data-placement="right" title="Click here to Save your new data." class="btn btn-primary"><i class="icon-save"></i> Save</button>
</div>
</div>
</td>
</tr>
<script type="text/javascript">
$(document).ready(function(){
$('#save').tooltip('show');
$('#save').tooltip('hide');
});
</script>
</tr>
</table>
</form>
</div>
</div>
<?php
$uploadDir1 = 'uploads/'; //Image Upload Folder
if (isset($_POST['save'])){
$docstype_id = $_POST['docstype_id'];
$fileno = $_POST['file_no'];
function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; }
$fileName1 = $_FILES['Photo']['name'];
$extension = getExtension($fileName1);
$extension = strtolower($extension);
$tmpName1 = $_FILES['Photo']['tmp_name'];
$fileSize1 = $_FILES['Photo']['size'];
$fileType1 = $_FILES['Photo']['type'];
$image_name= $fileno.'.'.$extension;
$filePath1 = $uploadDir1 . $image_name;
$result1 = move_uploaded_file($tmpName1, $filePath1);
if (!$result1) {
echo "Error uploading file";
exit;
}
if(!get_magic_quotes_gpc())
{
$fileName1 = addslashes($fileName1);
$filePath1 = addslashes($filePath1);
}
mysql_query("insert into upload (clients_id,docstype_id,file_no,file_path) values('$get_id','$docstype_id','$fileno','$filePath1')")or die(mysql_error());
?>
<script>
window.location = "clients_list.php";
$.jGrowl("Documents Uploaded Successfully added", { header: 'Device add' });
</script>
<?php
}
?>
</div>
</div>
<!-- /block -->
</div>
</div>
</div>
<?php include('footer.php'); ?>
</div>
<?php include('script.php'); ?>
</body>
unABLE TO INSERT FORM DATA INTO DATABASE TABLE
Please i have been trying to insert form data into my database with this code
$servername = "localhost";
$user = "Ahmed";
$password = "hammed";
$dbname = "registration";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $user, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// check user_error
$checkuserstmt = $conn->prepare("SELECT * FROM user_registration WHERE username= ? && email= ?");
$checkuserstmt->bindParam(1, $username);
$checkuserstmt->bindParam(2, $email);
$checkuserstmt->execute();
if($checkuserstmt->rowcount()==0){
$stmt = $conn->prepare("INSERT INTO user_registration(fname, lname, username, email, pass, gender)
VALUE (?, ?, ?, ?, ?, ?)");
//bind parameter
$stmt->bindparam(1, $fname);
$stmt->bindparam(2, $lname);
$stmt->bindparam(3, $username);
$stmt->bindparam(4, $email);
$stmt->bindparam(5, $pass);
$stmt->bindparam(6, $gender);
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$username = $_POST['username'];
$email = $_POST['email'];
$pass = $_POST['pass'];
$gender =$_POST['gender'];
// use exec() because no results are returned
$stmt->execute();
if($stmt==false){
echo "<p>There is already a user with that name: </p>";
}
else{
echo "New record created successfully. Last inserted ID is: " ;
$users = $conn->query("SELECT * FROM user_registration");
$row = $users->fetch();
echo $row["username"] . " -- " . $row["email"] . "<br />";
}
}
}
catch(PDOException $e)
{
echo "Unable to create your account: " . $e->getMessage();
}
$conn = null;
// but instead i get error message first type will be undefined index and the exception error is SQLSTATE[23000]: Integrity constraint violation: 1048 Le champ 'fname' ne peut �tre vide (null)
How to get a portion of a string with a regular expression
I have this situation where I can have strings like this:
"Project\\V1\\Rest\\Car\\Controller"
"Project\\V1\\Rest\\Boat\\Controller"
"Project\\Action\\Truck"
"Project\\V1\\Rest\\Helicopter\\Controller"
"Parental\\Boat\\Action"
Just in case the string follow the pattern:
"Project\\V1\\Rest\\THE_DESIRED_WORD\\Controller"
I want to get THE_DESIRED_WORD.
That's why I'm thinking in a regular expression.
Included File Gets Me Undefined Variables
Couldnt find an answer that solves my codes issue.
file.php:
if(isset($_GET['season1'])) {
$season1 = $_GET['season1'];
$url = 'http://ift.tt/ywvpFl'.$season1.'/episodes?season=1';
$imdb_content = file_get_contents($url);
$html = str_get_html($imdb_content);
//Grabbed Content
$resultarray = array();
foreach($html->find('strong a[itemprop="name"]') as $results) {
$resultarray[] = $results;
}
echo $resultarray[0];
echo $resultarray[1];
} else {
header("Location: ../");
}
index.php:
include("http://ift.tt/1IPwyQs".urlencode($imdbid));
(...)
<div class="row">
<div class="tech-spec-element col-xs-20 col-sm-10 col-md-5"> <span title="Episode 1"></span>1 - <?= $resultarray[0]; ?>
<div></div>
</div>
<div class="tech-spec-element col-xs-20 col-sm-10 col-md-5"> <span title="Episode 2"></span>2 - <?= $resultarray[1]; ?>
<div></div>
</div>
<div class="tech-spec-element col-xs-20 col-sm-10 col-md-5"> <span title="Episode 3"></span>3 - <?= $resultarray[2]; ?>
<div></div>
</div>
<div class="tech-spec-element col-xs-20 col-sm-10 col-md-5"> <span title="Episode 4"></span>4 - <?= $resultarray[3]; ?>
<div></div>
</div>
</div>
I know the file.php is being loaded fine as it gives me its output but when I try and use $resultarray[0]; it just doesnt work and say its undefined.
Any ideas on how I would resolve this pleasE?
Downgrade class php 5.6 to 5.5
I founded a class to stack object layers and closures but my server isnt running on php 5.6 yet. And i was wondering how can i convert the ...$parameters because i cant fix it by replacing everything with call_user_func_array() then the buildCoreClosure() method will throw errors for example because a closure isnt an array...
class Stack
{
/**
* Method to call on the decoracted class.
*
* @var string
*/
protected $method;
/**
* Container.
*/
protected $container;
/**
* Middleware layers.
*
* @var array
*/
protected $layers = [];
public function __construct(Container $container = null, $method = null)
{
$this->container = $container ?: new Container;
$this->method = $method ?: 'handle';
}
public function addLayer($class, $inner = true)
{
return $inner ? array_unshift($this->layers, $class) : array_push($this->layers, $class);
}
public function addInnerLayer($class)
{
return $this->addLayer($class);
}
public function addOuterLayer($class)
{
return $this->addLayer($class, false);
}
protected function buildCoreClosure($object)
{
return function(...$arguments) use ($object)
{
$callable = $object instanceof Closure ? $object : [$object, $this->method];
return $callable(...$arguments);
};
}
protected function buildLayerClosure($layer, Closure $next)
{
return function(...$arguments) use ($layer, $next)
{
return $layer->execute(...array_merge($arguments, [$next]));
};
}
public function peel($object, array $parameters = [])
{
$next = $this->buildCoreClosure($object);
foreach($this->layers as $layer)
{
$layer = $this->container->get($layer);
$next = $this->buildLayerClosure($layer, $next);
}
return $next(...$parameters);
}
}
JQuery UI Sortable: Save keys with sort order
I am using this code to save my JQuery UI sort order:
$(function() {
$('#sortable').sortable({
update: function (event, ui) {
var data = $(this).sortable('serialize');
$.ajax({
data: data,
type: 'POST',
url: '/sort.php'
});
}
});
$( "#sortable" ).disableSelection();
});
This produces an array of numbers. Let's say I also want to save keys with the numbers, based on tags in my list items.
So for example a sorted list such as:
<ul id='sortable'>
<li id='item-3' name='special'><image src='special.jpg'></li>
<li id='item-1' name='normal'><image src='normal.jpg'></li>
<li id='item-2' name='extraordinary'><image src='extraordinary.jpg'></li>
</ul>
Would produce this array in PHP:
$item['special'] = 3;
$item['normal'] = 1;
$item['extraordinary'] = 2;
I know how to access the tags with JQuery but not how to serialize these into an array to pass to my PHP script along with the sorted numbers. Help!