Activity Stream
48,167 MEMBERS
61000 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 5 of 5
  1.     
    #1
    Member
    Website's:
    megahotfiles.com

    Default why 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();
      }
    Without the loop it would add 1 line of the array...but not all of them...any idea what to do?
    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

  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    EastsideHosting.com MediaONAIR.com ImgWiz.com cPadmin.net EastsidePCWorks.com HostedTalk.com
    Well, after looking at your code (looks different) to what I normally use;

    Could try this;

    Find:
    PHP Code: 
    $Connection mysql_open(); 
    Replace:
    PHP Code: 
    $connection mysql_open(); 
    Rest is lowercase.
    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)

  4.     
    #3
    Member
    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");

    ?>
    You can put that into a file on your server called connect.php for instance. Now in all of your other pages, you can simply include this file and you'll be connected and ready to go. Here is your code posted above with just a test array with random info and the connect.php file included:

    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

    ?>

  5.     
    #4
    Member
    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 ;)

  6.     
    #5
    Member
    Website's:
    Tastro.org HDTVXviDLOL.com EpisodeSeasons.com FileBorg.org W-47.com
    yep, 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>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [WCDDL] Rating mod wont work :s
    By Laz0r in forum Web Application/Script Support
    Replies: 2
    Last Post: 15th Aug 2011, 07:12 PM
  2. Replies: 1
    Last Post: 6th Jul 2011, 03:10 AM
  3. C..P.A.L.E.A.D don't wont to pay
    By fole13 in forum Webmaster Discussion
    Replies: 4
    Last Post: 1st Jul 2011, 08:50 PM
  4. kloxo lightpd wont work
    By accyuklad in forum Server Management
    Replies: 3
    Last Post: 17th May 2011, 02:12 PM
  5. Site wont work right in Safari
    By AnIMaL in forum Technical Help Desk Support
    Replies: 2
    Last Post: 27th Mar 2008, 01:00 PM

Tags for this Thread

BE SOCIAL