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:


<?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\
" .
	"
	$email\
" .
	"
	$phone\
" .
	"
	$subject\
" .
	"
	$opsys\
" .
	"
	$description" . "
	$mailing\
";

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!! :slight_smile:

~ Lauren :confused:

You appear to be mixing mysql_ functions and mysqli_ functions. You should be using one or the other in your page.

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!!

i changed them all to mysqli but am still getting error

What PHP/MySQL versions does your server run as mysqli only works with PHP 5 (99% sure) and MySQL 4.1.3 and greater

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

Could you please post the line your trying to use

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);

}

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;

$con=mysql_connect('localhost','username','password');
$sql="select * from tablenme";
mysql_query($sql,$con);

:slight_smile:

This is the line with the error.

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

change this code

$result = mysql_query ($dbc, $query)

to

$result = mysql_query ($query,$dbc)

Ok, I switched the $dbc and the $query and the warning is gone, but it is still not going all the way :frowning:

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 :slight_smile:

Try echoing $query then running it direct in phpmyadmin, if it doesn’t work, what error has been reported?

I’m not sure how to do that. Sorry. Do I open phpmyadmin, and go to SQL and type it in there?

One more mistake is here…
Change this

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

To

$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…

IT WORKS!!! Thank you sooo much!!! I really appreciate it!!! Have a great night everyone! Now I can finally get some sleep lol :slight_smile: