SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Enthusiast BrooklynSpice's Avatar
    Join Date
    Jan 2009
    Location
    Brooklyn, NY
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Call to undefined function mysqli_query()

    Hi All,

    I am just learning PHP and I have run into a little snag. I have my database all set up with the table that I need, but when I try to run it, i get the following error.

    Fatal error: Call to undefined function mysqli_query() in /home/heights/public_html/test.php on line 108

    This is my code:
    Code PHP:
    <?php
     
     
     
    $first_name = $_POST['firstname'];
     
     
    $last_name = $_POST['lastname'];
     
     
    $name = $_POST['firstname'] . ' ' . $_POST['lastname'];
     
     
    $email = $_POST['email'];
     
     
    $phone = $_POST['phone'];
     
     
    $subject = $_POST['subject'];
     
     
    $opsys = $_POST['opsys'];
     
     
    $description = $_POST['description'];
     
     
     
    $mailing = $_POST['mailing'];
     
     
    $to= 'heightsdigital@gmail.com';
     
    $msg = "$name\n" .
    	"
    	$email\n" .
    	"
    	$phone\n" .
    	"
    	$subject\n" .
    	"
    	$opsys\n" .
    	"
    	$description" . "
    	$mailing\n";
     
    mail($to, $subject, $msg, 'From:' . $email);
     
     
     
     
    if ($mailing == yes) {
    	$dbc = mysql_connect('localhost', 'heights', 'horizon9M','heights_digital')
    	   or die ('Error connecting to MySQL Server!');
     
    	$query = "INSERT INTO mailing_list (first_name, last_name, email) " .
    	   "VALUES ('$firstname','$lastname','$email')";
     
    	mysqli_query ($dbc, $query)
    	   or die ('Error querying the database.');
     
    	mysql_close ($dbc);
     
    }	
     
    echo 'Hello, ' . $first_name . '<br/>';
     
     
    echo 'Thank you for contacting Heights Digital Services.<br />';
     
     
    echo 'You can count on a reply to you within one business day!<br/>';
     
    echo 'Click here to return to <a href="index.html">heightsdigital.com</a><br />';
     
    ?>


    Any help would be awesome! Thanks!!

    ~ Lauren
    You know I love it when you talk techie to me!

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,597
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    You appear to be mixing mysql_ functions and mysqli_ functions. You should be using one or the other in your page.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Enthusiast BrooklynSpice's Avatar
    Join Date
    Jan 2009
    Location
    Brooklyn, NY
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    at first it was all mysqli but when i got the errors i started playing around with it.which is better? is this something i can fix or do i need contact the server admin?

    thanks!!
    You know I love it when you talk techie to me!

  4. #4
    SitePoint Enthusiast BrooklynSpice's Avatar
    Join Date
    Jan 2009
    Location
    Brooklyn, NY
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i changed them all to mysqli but am still getting error
    You know I love it when you talk techie to me!

  5. #5
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    What PHP/MySQL versions does your server run as mysqli only works with PHP 5 (99&#37; sure) and MySQL 4.1.3 and greater
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle

  6. #6
    SitePoint Enthusiast BrooklynSpice's Avatar
    Join Date
    Jan 2009
    Location
    Brooklyn, NY
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    MySQL client version: 4.1.22
    PHPMyAdmin Version: 3.2.4

    So, I switched it to all mysql_ instead of mysqli_

    now I am getting this warning

    mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/heights/public_html/test.php on line 101
    You know I love it when you talk techie to me!

  7. #7
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Could you please post the line your trying to use
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle

  8. #8
    SitePoint Enthusiast BrooklynSpice's Avatar
    Join Date
    Jan 2009
    Location
    Brooklyn, NY
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if ($mailing == 'yes') {

    $dbloc = 'localhost';
    $user = 'heights';
    $pass = 'password';
    $dbname = 'heights_digital';

    $dbc = mysql_connect($dbloc, $user, $pass, $dbname)
    or die ('Error connecting to MySQL Server!');

    $query = "INSERT INTO mailing_list (first_name, last_name, email) " .
    "VALUES ('$firstname','$lastname','$email')";

    $result = mysql_query ($dbc, $query)
    or die ('Error querying the database.');

    mysql_close ($dbc);

    }
    You know I love it when you talk techie to me!

  9. #9
    SitePoint Zealot RishikeshJha's Avatar
    Join Date
    Mar 2009
    Location
    INDIA
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    The first parameter of mysql_query() would be the sql statement and second parameter would be the link identifier.

    The link identifier is the connection variable

    For example;
    Code PHP:
    $con=mysql_connect('localhost','username','password');
    $sql="select * from tablenme";
    mysql_query($sql,$con);

  10. #10
    SitePoint Enthusiast BrooklynSpice's Avatar
    Join Date
    Jan 2009
    Location
    Brooklyn, NY
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the line with the error.

    $result = mysql_query ($dbc, $query)
    or die ('Error querying the database.');
    You know I love it when you talk techie to me!

  11. #11
    SitePoint Zealot RishikeshJha's Avatar
    Join Date
    Mar 2009
    Location
    INDIA
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BrooklynSpice View Post
    if ($mailing == 'yes') {

    $dbloc = 'localhost';
    $user = 'heights';
    $pass = 'password';
    $dbname = 'heights_digital';

    $dbc = mysql_connect($dbloc, $user, $pass, $dbname)
    or die ('Error connecting to MySQL Server!');

    $query = "INSERT INTO mailing_list (first_name, last_name, email) " .
    "VALUES ('$firstname','$lastname','$email')";

    $result = mysql_query ($dbc, $query)
    or die ('Error querying the database.');

    mysql_close ($dbc);

    }
    change this code
    Code PHP:
    $result = mysql_query ($dbc, $query)

    to
    Code PHP:
    $result = mysql_query ($query,$dbc)

  12. #12
    SitePoint Enthusiast BrooklynSpice's Avatar
    Join Date
    Jan 2009
    Location
    Brooklyn, NY
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I switched the $dbc and the $query and the warning is gone, but it is still not going all the way

    i am now getting the die error (Error querying the database.)

    Sorry for all the trouble, I am really new at this, and it shows
    You know I love it when you talk techie to me!

  13. #13
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,904
    Mentioned
    93 Post(s)
    Tagged
    0 Thread(s)
    Try echoing $query then running it direct in phpmyadmin, if it doesn't work, what error has been reported?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  14. #14
    SitePoint Enthusiast BrooklynSpice's Avatar
    Join Date
    Jan 2009
    Location
    Brooklyn, NY
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure how to do that. Sorry. Do I open phpmyadmin, and go to SQL and type it in there?
    You know I love it when you talk techie to me!

  15. #15
    SitePoint Zealot RishikeshJha's Avatar
    Join Date
    Mar 2009
    Location
    INDIA
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BrooklynSpice View Post
    if ($mailing == 'yes') {

    $dbloc = 'localhost';
    $user = 'heights';
    $pass = 'password';
    $dbname = 'heights_digital';

    $dbc = mysql_connect($dbloc, $user, $pass, $dbname)
    or die ('Error connecting to MySQL Server!');

    $query = "INSERT INTO mailing_list (first_name, last_name, email) " .
    "VALUES ('$firstname','$lastname','$email')";

    $result = mysql_query ($dbc, $query)
    or die ('Error querying the database.');

    mysql_close ($dbc);

    }
    One more mistake is here..
    Change this
    Code PHP:
    $dbc = mysql_connect($dbloc, $user, $pass, $dbname)
    	   or die ('Error connecting to MySQL Server!');

    To
    Code PHP:
    $dbc = mysql_connect($dbloc, $user, $pass)
    	   or die ('Error connecting to MySQL Server!');
    mysql_select_db($dbname) or die("Database not found");

    Hope this will work...

  16. #16
    SitePoint Enthusiast BrooklynSpice's Avatar
    Join Date
    Jan 2009
    Location
    Brooklyn, NY
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IT WORKS!!!! Thank you sooo much!!! I really appreciate it!!! Have a great night everyone! Now I can finally get some sleep lol
    You know I love it when you talk techie to me!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •