JD.CoolPenguin's Profile
Reputation: 0
Apprentice
- Group:
- Members
- Active Posts:
- 27 (0.07 per day)
- Joined:
- 05-May 12
- Profile Views:
- 364
- Last Active:
Apr 24 2013 10:45 AM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: PHP to insert or update mySQL database if row already exists
Posted 24 Apr 2013
Thank you very much Andrewsw!!
This:
<html> <body> <p>You are testing, testing, testing.</p> <?php ini_set('display_errors',1); error_reporting(E_ALL); $mysqli = new mysqli("localhost", "username", "password", "database"); if ($mysqli->connect_errno) { printf("Connection failed: %s\n", $mysqli->connect_error); exit(); } $url = $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; echo $url; $mysqli->query("INSERT INTO `download_log`(`url`, `downloads`) VALUES ('".$url."', '1') ON DUPLICATE KEY UPDATE downloads = downloads + 1"); ?> </body> </html>
Works!
/>
Of course, I'm now going to go and try and get it to work in a wordpress install, and I'm sure there is something extra I'm going to have to do to connect to the database.
Thanks a million.
JD -
In Topic: PHP to insert or update mySQL database if row already exists
Posted 24 Apr 2013
andrewsw, on 24 April 2013 - 10:14 AM, said:Add this to the top of your script so you can see all errors:
ini_set('display_errors',1); error_reporting(E_ALL);
WHERE $url won't work on its own.
$existchk = $mysqli->query("SELECT `url` FROM `download_log` WHERE `url` = '$url'");
(placing apostrophes around the string $url.)
BTW The back-ticks aren't necessary, unless the field or table-names contain reserved words or non alphanumeric characters.
I suggest that you investigate INSERT.. ON DUPLICATE KEY UPDATE as well (here). If you make the url field a unique index or primary key then this statement will either inesrt a new row, or update an existing row.
Hello Andrewsw, I will do that and let you know what it comes back as shortly (just popped out).
I saw that about the ON DUPLICATE KEY, but couldn't find any information about using it with mySQLi, I wasn't sure if it would work or not.
So, I'll try using that instead when I get back.
Thanks for the advice.
JD. -
In Topic: Help understanding/calculating bandwidth (I'm streaming video).
Posted 24 Feb 2013
Damn, just missed the edit deadline.
As I currently understand it I'd need do something like this to calculate it:
[Number of people watching the videos per month] x [Total size of all videos] = Total data transferred by people watching the videos per month.
For example.
5000 people
100MB (2 videos)
5000 x 100 = 500,000MB (something short of 500GB).
Thanks,
Josh -
In Topic: glob() not returning anything
Posted 31 Jan 2013
Thank Cbeppe, I can't actually check this as 1&1's cpanel is down at the moment for maintenance so the only access I have is via FTP, but when it's back up, I'll check.
In the meantime, is it possible that it's a setting in the php.ini file? or the .htaccess file? or some setting that only 1&1 can change?
Thanks,
JD. -
In Topic: glob() not returning anything
Posted 30 Jan 2013
Its not the PHP version, it's on 5.4, I already checked that.
And wouldn't I only need to use chmod if the folder didn't already have read permissions?
Thanks,
JD.
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Private
Friends
JD.CoolPenguin hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
JD.CoolPenguin has no profile comments yet. Why not say hello?