Results 1 to 5 of 5
-
9th Apr 2011, 06:11 AM #1OPMemberWebsite's:
megahotfiles.comwhy wont this work?
hey guys, trying to make a function anyway why wont this insert data into the table
Code:$Connection = mysql_open(); $likes= array(); foreach($likes as $like) { $insert3 = "insert into ProfileInterests " . "values ('$id', $like, null)"; $result3 = @ mysql_query ($insert3, $connection) or showerror(); mysql_close($connection) or showerror(); }
pisoj1 Reviewed by pisoj1 on . why wont this work? hey guys, trying to make a function anyway why wont this insert data into the table $Connection = mysql_open(); $likes= array(); foreach($likes as $like) { $insert3 = "insert into ProfileInterests " . "values ('$id', $like, null)"; $result3 = @ mysql_query ($insert3, $connection) or showerror(); Rating: 5
-
9th Apr 2011, 06:27 PM #2MemberWebsite's:
EastsideHosting.com MediaONAIR.com ImgWiz.com cPadmin.net EastsidePCWorks.com HostedTalk.comWell, after looking at your code (looks different) to what I normally use;
Could try this;
Find:
PHP Code:$Connection = mysql_open();
PHP Code:$connection = mysql_open();
EastsideHosting - (Web Hosting, Proxy Hosting, Reseller Program)
MediaONAIR - (SHOUTcast Servers, ICEcast Servers, Reseller Program)
Server Administrator - (Dedicated Servers, VPS Management, One Time Services)
ImgWiz - (Free Image Hosting)
-
19th Apr 2011, 05:20 PM #3Member
If that's the entire code you're using, the array you're using is null; in your insert statement, you're missing the column name declarations before the values list; you're placing the mysql_close() function within your foreach() loop so after the first run, it would close your SQL connection. Also I'm not sure if mysql_open() is even a function, mysql_close() is however.
Here is how you would connect to your database. Replace the info with your own:
PHP Code:<?php
$dbserver = 'yourserver';
$dbuser = 'username';
$dbname = 'database';
$dbpass = 'password';
$connect = mysql_connect($dbserver, $dbuser, $dbpass) or die(mysql_error());
$database = mysql_select_db($dbname) or die("Cannot select DB");
?>
PHP Code:<?php
include_once 'connect.php';
$likes = array("key1" => "value1", "key2" => "value2");
foreach($likes as $key) {
mysql_query( "INSERT INTO ProfileInterests (id, like, null) VALUES ('$id', '$key', null)" ) or die(mysql_error());
}
mysql_close(); //You don't have to use this unless you have persistent connects
?>
-
19th Apr 2011, 11:18 PM #4Member
You could be awesome, AdM.as and do it in one query (MySQL only I guess):
PHP Code:$likes = array("key1" => "value1", "key2" => "value2");
$jmz = array();
foreach($likes as $li => $ke) $jmz[] = "('" . $li . "', '" . $ke . "', null)";
mysql_query("INSERT INTO ProfileInterests VALUES " . implode(",", $jmz));
Pseudoephedrine ftw..
Go buy some Actifed/Sudafed Decongestant, take 3+ and you'll see what i mean ;)
-
19th Apr 2011, 11:45 PM #5MemberWebsite's:
Tastro.org HDTVXviDLOL.com EpisodeSeasons.com FileBorg.org W-47.comyep, your array is empty:
$likes= array();LE with your pr2 site? <a href="http://tastro.org/">Tastro.org</a> or link exchance with our category page: <a href="http://tastro.org/i/hdtv">HDTV</a> | <a href="http://tastro.org/i/dvdrip">DVDRip</a> | <a href="http://tastro.org/i/r5">R5</a> | <a href="http://tastro.org/i/bdrip">BDRip</a> | <a href="http://tastro.org/i/brrip">BRRip</a>
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
[WCDDL] Rating mod wont work :s
By Laz0r in forum Web Application/Script SupportReplies: 2Last Post: 15th Aug 2011, 07:12 PM -
Changed Forum Directory and Admin Panel wont work!
By .HelFi0 in forum vBulletinReplies: 1Last Post: 6th Jul 2011, 03:10 AM -
C..P.A.L.E.A.D don't wont to pay
By fole13 in forum Webmaster DiscussionReplies: 4Last Post: 1st Jul 2011, 08:50 PM -
kloxo lightpd wont work
By accyuklad in forum Server ManagementReplies: 3Last Post: 17th May 2011, 02:12 PM -
Site wont work right in Safari
By AnIMaL in forum Technical Help Desk SupportReplies: 2Last Post: 27th Mar 2008, 01:00 PM
themaCreator - create posts from...
Version 3.21 released. Open older version (or...