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