Jump to content

Fatal error: Call to undefined function: mysql_connect_errno()


icorange

Recommended Posts

Hi everyone ... thank you in advance for looking at this ...

 

I have a site ... uploading to GoDaddy hosting (MySQL version 5.0) ... I've tried so many things with my coding, changed it from mysqli to mysql ... and everything else, I'm a bit confused now ... when I upload all my files for a VERY simple subscription service, I keep getting this error:

 

Fatal error: Call to undefined function: mysql_connect_errno()

 

I have read a lot about this error - and have made so many changes, I think my coding is a bit scrambled now ... I would really appreciate the help!!! Thanks again ...

 

<?php 

function doDB() { 
global $mysql; 


$mysql = mysql_connect('hostsite', 'user', 'password', 'dbname'); 
if (mysql_connect_errno()) { 
printf("Connect failed: %s\n", mysql_connect_error()); 
exit(); 
} 
} 

function emailChecker($email) { 
global $mysql, $check_res; 

$check_sql = "SELECT id FROM SUBSCRIPTION WHERE email = '".$email."'"; 
$check_res = mysql_query($mysql, $check_sql) or die(mysql_error($mysql)); 
} 

if (!$_POST) { 

$display_block = " 
<form method=\"POST\" action=\"".$_SERVER["PHP_SELF"]."\"> 

<p><strong>Your E-Mail Address:</strong><br/> 
<input type=\"text\" name=\"email\" size=\"40\" maxlength=\"150\"> 

<p><strong>Action:</strong><br/> 
<input type=\"radio\" name=\"action\" value=\"sub\" checked> subscribe 
<input type=\"radio\" name=\"action\" value=\"unsub\"> unsubscribe 

<p><input type=\"submit\" name=\"submit\" value=\"Submit Form\"></p> 
</form>"; 

} else if (($_POST) && ($_POST["action"] == "sub")) { 


if ($_POST["email"] == "") { 
header("Location: form.php"); 
exit; 
} else { 

doDB(); 

emailChecker($_POST["email"]); 

if (mysql_num_rows($check_res) < 1) { 

mysql_free_result($check_res); 


$add_sql = "INSERT INTO subscription (email) VALUES('".$_POST["email"]."')"; 
$add_res = mysql_query($mysql, $add_sql) or die(mysql_error($mysql)); 
$display_block = "<p>Thanks for signing up!</p>"; 

mysql_close($mysql); 
} else { 
$display_block = "<p>You're already subscribed!</p>"; 
} 
} 
} else if (($_POST) && ($_POST["action"] == "unsub")) { 

if ($_POST["email"] == "") { 
header("Location: form.php"); 
exit; 
} else { 

doDB(); 

emailChecker($_POST["email"]); 

if (mysql_num_rows($check_res) < 1) { 

mysql_free_result($check_res); 

$display_block = "<p>Couldn't find your address!</p> 
<p>No action was taken.</p>"; 
} else { 

while ($row = mysql_fetch_array($check_res)) { 
$id = $row["id"]; 
} 


$del_sql = "DELETE FROM subscription WHERE id = '".$id."'"; 
$del_res = mysql_query($mysql, $del_sql) or die(mysql_error($mysql)); 
$display_block = "<p>You're unsubscribed!</p>"; 
} 
mysql_close($mysql); 
} 
} 
?>

Hi ... thanks ... well I do understand that "mysql_connect_errno()" is in my code .... guess I'm just a little TOO new at this ... I used a "subscription.php" file right from Julie Meloni's third edition PHP, MySQL and Apache ... used it exactly ... hosting with GoDaddy - using Mysql 5.0 ... when I went to the site, entered an email ... the Fatal error came up in the browser ... I was then told to change all my "mysqli" to "mysql" ... same errors ... sorry for being so ignorant ... I just can't figure out what I am doing wrong  :'(

If your host does not have the mysqli extension enabled, they probably are not going to do it just because you ask.

 

The equivalent mysql function to mysqli_connect_errno() would be mysql_errno() and the equivalent mysql function to mysqli_connect_error() would be mysql_error().

 

You cannot just remove or add the "i" to change code between mysqli and mysql. The parameter counts and parameter orders are different. For example, mysql_connect() in your posted code typically uses three parameters and the fourth is a flag to cause a new link to be created. mysqli_connect() uses the fourth parameter as the database. The mysql_query() parameters are actually reversed from the mysqli_query() parameters.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.