I'm using Alban Xhaferllari AJAX multiple uploader and I have an issue with inserting data to my database. Here is the link to the upload.php. here is my code that it doesn't work.
function success($file_path)
{
$conn = new mysqli("localhost", "xxxxx", "xxxxxxxx");
$conn->set_charset("utf8");
$conn->select_db("xxxxxxx");
$id = $conn->query("INSERT INTO Galerie (Poza) VALUES($file_path) ");
}
This is the code from their website dunno what's wrong cause I dont get any error but still it doesn't insert.
Please correct following it works for me
$id = $conn->query("INSERT INTO Galerie (Poza) VALUES('$file_path') ");
Related
I am trying to make a simple form that takes some feedback from the user and adds it to a MySQL database.
The code is as follows -
<?php
$store_id = '4';
$feedbackcontent = 'test';
$rating = '2';
if($feedbackcontent=='' || $rating=='') {
echo 'Feedback and a rating are required';
}
else {
$s1 = new MySqlTable();
$sql = 'INSERT INTO reviews (store_id, FeedbackContent, Rating)
VALUES ("'.$s1->escape($store_id).'", "'.$s1->escape($feedbackcontent).'", "'.$s1->escape($rating).'")';
$s1->executeQuery($sql);
}
?>
But, when I run it in Chrome, I get the following error in the debug console.
500 (Internal Server Error)
Screenshot of the 500 internal server error
Its worth mentioning If I remove the below lines of code and put a simple echo or something, it works OK.
$s1 = new MySqlTable();
$sql = 'INSERT INTO reviews (store_id, FeedbackContent, Rating)
VALUES ("'.$s1->escape($store_id).'", "'.$s1->escape($feedbackcontent).'", "'.$s1->escape($rating).'")';
$s1->executeQuery($sql);
Is there anything obviously wrong with the code or a better way to debug this type of error? Im quite new to PHP, but as far as I can tell this code should work.
I think you miss to set connection with database mysql.
$mysqli = new mysqli("host", "user", "password", "dbname");
I've updated my project to it's almost final form and made a small change. The suggestion of #Raghbendra Nayak worked before the change and now, I'm trying to incorporate it to my new form. After 'submit' it pushes the item to the folder still and the link to the DB, however the link is on a separate row and not on the same row where the data name-description written is found.
Update: Got it working guys. Thanks!
You can simply follow the below code to insert data in database why you are using mysqli_connect to run the insert query.
Updated:
Change your if condition:
if(move_uploaded_file($file['tmp_name'],$upload_directory.$path)){
mysqli_connect("localhost", "root", "", "order") or die ("Connecting to DB failed");
mysqli_connect("INSERT INTO item VALUES ('', '$path')");
}
To
if(move_uploaded_file($_FILES['filename']['tmp_name'],$upload_directory.$path)){
$conn = mysqli_connect("localhost", "root", "", "order") or die ("Connecting to DB failed");
// If you want to save image name you can get like below:
$filename = $_FILES["filename"]["name"];
$path = $path."/".$filename;
$sql = "INSERT INTO item (path) VALUES ('$path')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
You have to add your image name also. Hope it will work for you, let me know it anything required.
I'm working on a symfony2 project. when i insert data with french accents like (é), it is inserted as shown in this image:
when i try to retrieve this data using a php file to use it in android app, i use this code:
<?php
define('HOST','localhost');
define('USER','root');
define('PASS','');
define('DB','adproject');
$con = mysqli_connect(HOST,USER,PASS,DB) or die('unable to connect to db');
$sql = "select * from actualite";
$result = array();
$res = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($res)){
array_push($result,
array('id'=>$row[0],
'login'=>$row[1],
'password'=>$row[2]
));
}
echo json_encode($result);
mysqli_close($con);
?>
I get nothing because of the accents in the database. Any suggestion?
I suspect you'll need to go through this Configuring the Database section and setting up for UTF8:
http://symfony.com/doc/current/doctrine.html#configuring-the-database
Let us know if you've already done that.
Decided to move to procedural style coding. I've tried the below code and receive no errors or returned data. What am I doing wrong? Blanked out the mysqli_connect parameters because I am using a shared server - assume the parameters are correct. Thanks in advance.
function login(){
$connect = mysqli_connect("**********", "******", "****", "*****");
$result = mysqli_query($connect, "SELECT * FROM `new_base`");
$bang = mysqli_fetch_all($result);
echo $bang; }
NOTE: The call to the function does work echoing a string does get returned to the page.
I wonder whether someone can help me please.
I'm trying to put together a PHP script that takes data from an xml file and places the data in a mySQL data. I've been working on this for a few days and I'm still can't seem to get this right.
This is the code that I've managed to put together:
<?
$objDOM = new DOMDocument();
$objDOM->load("xmlfile.xml");
$Details = $objDOM->getElementsByTagName("Details");
foreach( $Details as $value )
{
$listentry = $value->getElementsByTagName("listentry");
$listentrys = $listentry->item(0)->nodeValue;
$sitetype = $value->getElementsByTagName("sitetype");
$sitetypes = $sitetype->item(0)->nodeValue;
$sitedescription = $value->getElementsByTagName("sitedescription");
$sitedescriptions = $sitedescription->item(0)->nodeValue;
$siteosgb36lat = $value->getElementsByTagName("siteosgb36lat");
$siteosgb36lats = $siteosgb36lat->item(0)->nodeValue;
$siteosgb36lon = $value->getElementsByTagName("siteosgb36lon");
$siteosgb36lons = $siteosgb36lon->item(0)->nodeValue;
//echo "$listentrys :: $sitetypes :: $sitedescriptions :: $siteosgb36lats :: $siteosgb36lons <br>";
}
require("phpfile.php");
//Opens a connection to a MySQL server
$connection = mysql_connect ("hostname", $username, $password);
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
mysql_query("INSERT IGNORE INTO scheduledsites (listentry, sitetype, sitedescription, siteosgb36lat, siteosgb36lon) VALUES('$listentrys','$sitetypes','$sitedescriptions','$siteosgb36lats','$siteosgb36lons') ")
or die(mysql_error());
echo "Data Inserted!";
?>
I can pull the data from the xml file, but it's the part of the script that sends the data to my database table that I'm having trouble with.
The script runs but only the last record is saved to the database.
I can parse the fields from the xml file without any problems and the check I'm trying to put in place is, if there is a 'listentry' number in the new data that is matched to one already in the table then I don't want that record to be added to the table, i.e. ignore it.
I just wondered whether someone could perhaps take a look at this please and let me know where I'm going wrong.
Many thanks
You are only calling mysql_query once. So it will only insert one row.
The sql needs to be inside the loop.