Adding to Column in SQL issues (in photo-gallery website) - php

I'm building a photography website where I have one page that displays the pictures (bootstrapped and all) and then another page so I can upload new photos (consists of an html page with form and php that runs download code). In this php page I want to make an SQL addition to my column name in database photos. I want to add the file name into the SQL database name so I can later access it in my page displaying the photos and I can get the file name so I can for loop it there for all the pictures in the directory. The issue I'm having is adding the target file into the name and then getting it. Here's my code for adding the filename:
$link = mysql_connect('meadowebcom.ipagemysql.com', 'lphotos', 'gut2*EMI_12');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db(photos);
$sql = 'INSERT INTO `name` (`target_file`) VALUES ('.basename( $_FILES["fileToUpload"]["name"]).');';
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
I have it display that I am connected but can't add anything. I haven't even started on getting the file in the other file. I don't usually do PHP outside of contact and registration forms so any help or any points in the right direction would help.

Related

Blank Field in Mysql After Uploading Data

I was uploading data from my android application to a PHP file then inserting it to Mysql database, the problem i am having that i buy a new hosting plan and when i configured everything in the new hosting, i try to upload data from the application it shows only blank fields in the table, i am sure that there's no problem in the PHP or the android code, cause it was working fine and great with the old hosting.. i tried to change the encoding but same issue.
Here's the PHP file:
<?php
$con = mysql_connect("HOST","USER","PASS");
if (!$con)
{
die('Could not Connect:'. mysql_error());
}
mysql_select_db("TABLE",$con);
mysql_query ("INSERT INTO table (rep_desc,dateT) VALUES ('".$_REQUEST['report_Desc']."','".$_REQUEST['Date_Time']."')");
mysql_close($con);
?>
Thanks in advance
If there is any auto_increment column in table. Better check if its auto_increment flag not got uncheck.
Please also check length of database fields and data that you actually trying to insert.
Name of all request variables, columns, tables should be in proper case if it is a UNIX system.
get all the tables by something like this query ...
$sql = "SHOW TABLES FROM $dbname";
$result = mysql_query($sql);
if (!$result) {
echo "DB Error, could not list tables\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_row($result)) {
echo "Table: {$row[0]}\n";
}

phpgraph lib not showing any output

Im using phpgraph lib to create graphs on my linux server. I tried an example and it worked, but I had provided it with the data.
then I wanted to connect it to mysql database and plot a query, when I run it, nothing happens, I don't see any output on the page or any errors, I don't see any output on the page at all, even if I put wrong credentials to my database e.t.c any inputs?
I have executed the sql statement on sql server and it's working fine.
the version of php the server has is PHP 5.3.3
<?php
include('phpgraphlib.php');
$graph= new PHPGraphLib(550,350);
$link = mysql_connect('localhost', 'user', 'password')
or die('Could not connect: ' . mysql_error());
mysql_select_db('databasename' or die('Could not select database');
$dataArray=array();
//get data from database
$sql="my sql statement";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
if ($result) {
while ($row = mysql_fetch_assoc($result)) {
$salesgroup=$row["var1"];
$count=$row["count"];
//add to data areray
$dataArray[$salesgroup]=$count;
}
}
//configure graph
$graph->addData($dataArray);
$graph->setTitle("Sales by Group");
$graph->setGradient("lime", "green");
$graph->setBarOutlineColor("black");
$graph->createGraph();
?>
I fixed it, I was expecting to see errors on the webpage, but didn't see any on CHROME, I hen opened it in IE and saw error 500.
Troubleshooted through the log file.
Turned out the sql statement wasn't suppose to have double quotes e.g instead of
where name="john"
it's suppose to be
where name='john'

Displaying a single image on a seperate page from a group of images displayed from a database

I'm so sorry that that title probably makes no sense.
Basically whats going on is I have a page with images being displayed on it that were uploaded to a database from users. I want the user to be able to select one of those images which links them to another page that only displays the image they picked. Problem is that I cant get that selected image to display on the linked page.
Any idea whats going on?
// Database credentials
require("config.php");
// Connect to the database
$dbc = mysqli_connect ($db_host, $db_user, $db_password, $db_name) OR die ('Could not connect to MySQL: '. mysqli_connect_error());
// Get the image
$query = "SELECT
*
FROM
image
WHERE
image_id = '{$_GET['image']}' LIMIT 1";
$result = mysqli_query($dbc, $query) or die('Query failed: ' . mysqli_error($dbc));
$row = mysqli_fetch_assoc($result);
// Back to all images
echo "<p>Back to the gallery</p>";
// Display the chosen image image
echo "{$row['image']}";
I'm playing with something like this, but all its giving me it a broken url path icon.
echo '<img src="upload/'.$row["image"].'">';
You shd echo:
echo "<img src=".row['image']." />";

MySQL DB Column Not Updating after TinyMCE post INSERT

I've managed to implement a simple TinyMCE editor on my site and have it call using mySQL database. My problem Im having now is getting the DB to overwrite the contents already stored inside with what is being posted?
I simply want to overwrite the table contents (within the column) with what is being inserted.
Here is my code:
<!--- CONNECT TO THE DATABASE------>
<?php
$con = mysql_connect("localhost","root","jdkldk8%by");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("cms", $con);
$sql="INSERT INTO tinymce (contents, contact, slider, resources)
VALUES
('$_POST[contents]','$_POST[contact]','$_POST[slider]','$_POST[resources]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
<!--- END DATABASE SETTINGS ----->
[ View your changes here ]
///////////////////////////////////////////////////////////////////////////////////////
Well... i tried again but its still not posting all fields to the DB! only updating 1.
<!--- CONNECT TO THE DATABASE------>
<?php
require_once('db.php');
$contents=$_POST['contents'];
$contact=$_POST['contact'];
$slider=$_POST['slider'];
$resources=$_POST['resources'];
$id='1';
$sql="UPDATE tinymce SET `contents`='$contents', `contact`='$contact', `slider`='$slider', `resources`='$resources' WHERE id='$id'";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Saved!";
mysql_close($con);
?>
<!--- END DATABASE SETTINGS ----->
You want to use UPDATE, not INSERT, to update a previously created MySQL column.
Try editing a column using phpmyadmin and copying the resulting code from their MySQL code viewer.

INSERT IGNORE In mySQL

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.

Categories