seattletype Posted December 9, 2013 Share Posted December 9, 2013 I'm no PHP whiz, but I get by ok. I have this one chunk of php generated by Dreamweaver (no comments please) and the page (containing a table insert function) works fine, but as soon as I add this to check and see if the 'Email' field already exists in the table causes the page to load blank - the typical unexplained code error display. This has worked fine in the past and I've not changed this code at all from when it was generated. I be curious if anyone can see why it might break the page: // *** Redirect if username exists $MM_flag="MM_insert"; if (isset($_POST[$MM_flag])) { $MM_dupKeyRedirect="duplicate.php"; $loginUsername = $_POST['Email']; $LoginRS__query = sprintf("SELECT Email FROM Registrations WHERE Email=%s", GetSQLValueString($loginUsername, "text")); mysql_select_db($database_midwinter, $midwinter); $LoginRS=mysql_query($LoginRS__query, $midwinter) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); //if there is a row in the database, the username was found - can not add the requested username if($loginFoundUser){ $MM_qsChar = "?"; //append the username to the redirect page if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&"; $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername; header ("Location: $MM_dupKeyRedirect"); exit; } } Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 9, 2013 Share Posted December 9, 2013 but as soon as I add this to check and see if the 'Email' field already exists in the table causes the page to load blank Turn error reporting on, by adding these line at the top the page error_reporting(E_ALL); ini_set('display_errors', 1); or check your sever's error log. Quote Link to comment Share on other sites More sharing options...
seattletype Posted December 9, 2013 Author Share Posted December 9, 2013 Thanks.. VERY helpful. Apparently the line "mysql_select_db($database_midwinter, $midwinter);" is returning a bunch of nulls. Now I know where to go look. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 9, 2013 Share Posted December 9, 2013 Before you can select a database with mysql_select_db you need to connect to mysql first. Quote Link to comment Share on other sites More sharing options...
seattletype Posted December 9, 2013 Author Share Posted December 9, 2013 Yes, there is a connection string making that MySQL connection included at the top of the page... and if I don't have the aforementioned "duplicate" check code in place, the insert happens successfully. It's just when this is added that it 'breaks'. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 9, 2013 Share Posted December 9, 2013 Can you post the error messages in full Quote Link to comment Share on other sites More sharing options...
seattletype Posted December 9, 2013 Author Share Posted December 9, 2013 Notice: Undefined variable: database_midwinter in /var/www/vhosts/midwinterwebcast.com/httpdocs/index.php on line 43 Notice: Undefined variable: midwinter in /var/www/vhosts/midwinterwebcast.com/httpdocs/index.php on line 43 Warning: mysql_select_db() expects parameter 2 to be resource, null given in /var/www/vhosts/midwinterwebcast.com/httpdocs/index.php on line 43 Notice: Undefined variable: midwinter in /var/www/vhosts/midwinterwebcast.com/httpdocs/index.php on line 44 Warning: mysql_query() expects parameter 2 to be resource, null given in /var/www/vhosts/midwinterwebcast.com/httpdocs/index.php on line 44 Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 9, 2013 Share Posted December 9, 2013 What is the database connection code? Quote Link to comment Share on other sites More sharing options...
seattletype Posted December 9, 2013 Author Share Posted December 9, 2013 <?php $hostname_midwinter = "DB_address"; $database_midwinter = "midwinter"; $username_midwinter = "username"; $password_midwinter = "password"; $midwinter = mysql_pconnect($hostname_midwinter, $username_midwinter, $password_midwinter) or trigger_error(mysql_error(),E_USER_ERROR); ?> Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 9, 2013 Share Posted December 9, 2013 Is the connection located in another file? Are you including that file before the duplicate email code? Quote Link to comment Share on other sites More sharing options...
seattletype Posted December 9, 2013 Author Share Posted December 9, 2013 <?php require_once('Connections/midwinter.php'); ?> //this is the connection string page <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } if (!isset($mm_abort_edit) || !$mm_abort_edit) { // *** Redirect if username exists $MM_flag="MM_insert"; if (isset($_POST[$MM_flag])) { $MM_dupKeyRedirect="duplicate.php"; $loginUsername = $_POST['Email']; $LoginRS__query = sprintf("SELECT Email FROM Registrations WHERE Email=%s", GetSQLValueString($loginUsername, "text")); mysql_select_db($database_midwinter, $midwinter); $LoginRS=mysql_query($LoginRS__query, $midwinter) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); //if there is a row in the database, the username was found - can not add the requested username if($loginFoundUser){ $MM_qsChar = "?"; //append the username to the redirect page if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&"; $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername; header ("Location: $MM_dupKeyRedirect"); exit; } }} $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if (!isset($mm_abort_edit) || !$mm_abort_edit) { if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO Registrations (Fname, Lname, Email, Password) VALUES (%s, %s, %s, %s)", GetSQLValueString($_POST['Fname'], "text"), GetSQLValueString($_POST['Lname'], "text"), GetSQLValueString($_POST['Email'], "text"), GetSQLValueString($_POST['Password'], "text")); mysql_select_db($database_midwinter, $midwinter); $Result1 = mysql_query($insertSQL, $midwinter) or die(mysql_error()); $insertGoTo = "select.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); }} ?> Yes... here's the entire code chunk at the top of the page doing the check and the insert... Quote Link to comment Share on other sites More sharing options...
seattletype Posted December 9, 2013 Author Share Posted December 9, 2013 So... any thoughts on what might be going on here? THx Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 9, 2013 Share Posted December 9, 2013 I dont know. The code is ok although it is messy but that is typical of dreamweaver generating garbage. You are better of coding it by hand than using Dreamweaver's code generators. Quote Link to comment Share on other sites More sharing options...
joallen Posted December 9, 2013 Share Posted December 9, 2013 Verify the path to the php file containing your mysql_connect statement. Also I noticed a "p" at the end of mysql_connect. That may be the issue. Quote Link to comment Share on other sites More sharing options...
seattletype Posted December 9, 2013 Author Share Posted December 9, 2013 Bloody brilliant.. yes, the 'p' was the problem. Dunno why I missed that.. sometimes just need a second pair of eyeballs. Thank you so much.. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted December 9, 2013 Share Posted December 9, 2013 the symptom is that of the code on the server not being the actual code you are looking at in your editor. the mysql_pconnect will work just fine (it gets a regular connection when on a server that doesn't support a persistent connection.) it's more likely that when you changed the code, you actually saved it/uploaded it onto the server and replaced whatever was actually running on the server. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.