close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

MySQLi recordset changes sporadically

Thread began 8/18/2014 7:04 am by Jason | Last modified 8/21/2014 8:40 am by Jason Byrnes | 5225 views | 36 replies |

Jason

MySQLi recordset changes sporadically

I have a page that contains multiple recordsets (one of which is WADApcms2_users), but for some reason when I make changes or edit any recordest on the page other than WADApcms2_users the code of WADApcms2_users changes and give me an error.

The working code is:

<?php
$ParamUserID_WADApcms2_users = "-1";
if (isset($_GET['UserID'])) {
$ParamUserID_WADApcms2_users = $_GET['UserID'];
}
mysql_select_db($database_local, $local);
$query_WADApcms2_users = sprintf("SELECT UserID, UserEmail, UserFirstName, UserLastName, UserCity, UserState, UserZip, UserPhone, UserCountry, UserGender, UserAddress, UserAddress2, UserDOB, SmallGroup FROM pcms2_users WHERE UserID = %s", GetSQLValueString($ParamUserID_WADApcms2_users, "int"));
$WADApcms2_users = mysql_query($query_WADApcms2_users, $local) or die(mysql_error());
$row_WADApcms2_users = mysql_fetch_assoc($WADApcms2_users);
$totalRows_WADApcms2_users = mysql_num_rows($WADApcms2_users);$ParamUserID_WADApcms2_users = "-1";
if (isset($_GET['UserID'])) {
$ParamUserID_WADApcms2_users = $_GET['UserID'];
}
mysql_select_db($database_local, $local);
$query_WADApcms2_users = sprintf("SELECT UserID, UserEmail, UserFirstName, UserLastName, UserCity, UserState, UserZip, UserPhone, UserCountry, UserGender, UserAddress, UserAddress2, UserDOB, SmallGroup FROM pcms2_users WHERE UserID = %s", GetSQLValueString($ParamUserID_WADApcms2_users, "int"));
$WADApcms2_users = mysql_query($query_WADApcms2_users, $local) or die(mysql_error());
$row_WADApcms2_users = mysql_fetch_assoc($WADApcms2_users);
$totalRows_WADApcms2_users = mysql_num_rows($WADApcms2_users);?>

The error code that it changes to is:

<?php
$ParamUserID_WADApcms2_users = "-1";
if (isset($_GET['UserID'])) {
$ParamUserID_WADApcms2_users = $_GET['UserID'];
}
mysql_select_db($database_local, $local);
$query_WADApcms2_users = sprintf("SELECT UserID, UserEmail, UserFirstName, UserLastName, UserCity, UserState, UserZip, UserPhone, UserCountry, UserGender, UserAddress, UserAddress2, UserDOB, SmallGroup FROM pcms2_users WHERE UserID = %s", GetSQLValueString($ParamUserID_WADApcms2_users, "int"));
$WADApcms2_users = mysql_query($query_WADApcms2_users, $local) or die(mysql_error());
$row_WADApcms2_users = mysql_fetch_assoc($WADApcms2_users);
$totalRows_WADApcms2_users = "-1";
if (isset($_GET['UserID'])) {
$totalRows_WADApcms2_users = $_GET['UserID'];
}
$ParamUserID_WADApcms2_users = "-1";
if (isset()) {
$ParamUserID_WADApcms2_users = ;
}
mysql_select_db($database_local, $local);
$query_WADApcms2_users = sprintf("SELECT UserID, UserEmail, UserFirstName, UserLastName, UserCity, UserState, UserZip, UserPhone, UserCountry, UserGender, UserAddress, UserAddress2, UserDOB, SmallGroup FROM pcms2_users WHERE UserID = %s", GetSQLValueString($ParamUserID_WADApcms2_users, "int"));
$WADApcms2_users = mysql_query($query_WADApcms2_users, $local) or die(mysql_error());
$row_WADApcms2_users = mysql_fetch_assoc($WADApcms2_users);
$totalRows_WADApcms2_users = mysql_num_rows($WADApcms2_users);?>


What is causing this and how can I fix it, other than pasting the working code back into the page? The page is attached to this message also.

Attached Files
kids_insert_shift.php
Sign in to reply to this post

Jason ByrnesWebAssist

the code for the WADApcms2_users recordset is duplicated, it should be:

$ParamUserID_WADApcms2_users = "-1";
if (isset($_GET['UserID'])) {
$ParamUserID_WADApcms2_users = $_GET['UserID'];
}
mysql_select_db($database_local, $local);
$query_WADApcms2_users = sprintf("SELECT UserID, UserEmail, UserFirstName, UserLastName, UserCity, UserState, UserZip, UserPhone, UserCountry, UserGender, UserAddress, UserAddress2, UserDOB, SmallGroup FROM pcms2_users WHERE UserID = %s", GetSQLValueString($ParamUserID_WADApcms2_users, "int"));
$WADApcms2_users = mysql_query($query_WADApcms2_users, $local) or die(mysql_error());
$row_WADApcms2_users = mysql_fetch_assoc($WADApcms2_users);
$totalRows_WADApcms2_users = mysql_num_rows($WADApcms2_users);




however, you are mixing standard MySQL recordsets with MySQLi recordset, why not just use all MySQLi recordsets?

Sign in to reply to this post

Jason

I did my best to recreate the query in MySQLi, but I wasn't sure what serveral lines in the original meant. After I'm currently getting the following error, and I don't know what the lines it's referring to are doing (They don't show up in the "Server Behaviors" window). The page is attached.


Notice: Undefined variable: database_local in C:\xampp\htdocs\ALF\public_html\serving\kids\kids_insert_shift.php on line 9
Notice: Undefined variable: local in C:\xampp\htdocs\ALF\public_html\serving\kids\kids_insert_shift.php on line 9
Warning: mysql_select_db() expects parameter 2 to be resource, null given in C:\xampp\htdocs\ALF\public_html\serving\kids\kids_insert_shift.php on line 9
Fatal error: Call to undefined function GetSQLValueString() in C:\xampp\htdocs\ALF\public_html\serving\kids\kids_insert_shift.php on line 10

Attached Files
kids_insert_shift.php
Sign in to reply to this post

Jason ByrnesWebAssist

to convert it to MySQLi, yu remove the entire recordset and recreate the SQL using the MySQL recordset dialog box, that's all that is needed, don't worry about converting the code, just recreate the SQL.

Sign in to reply to this post

Jason

I followed your instructions (I think) but I'm still getting the same error. Current page is attached.

Attached Files
kids_insert_shift.php
Sign in to reply to this post

Jason ByrnesWebAssist

line 4 - 13:

<?php
$ParamUserID_WADApcms2_users = "-1";
if (isset($_GET['UserID'])) {
$ParamUserID_WADApcms2_users = $_GET['UserID'];
}
mysql_select_db($database_local, $local);
$query_WADApcms2_users = sprintf("SELECT UserID, UserEmail, UserFirstName, UserLastName, UserCity, UserState, UserZip, UserPhone, UserCountry, UserGender, UserAddress, UserAddress2, UserDOB, SmallGroup FROM pcms2_users WHERE UserID = %s", GetSQLValueString($ParamUserID_WADApcms2_users, "int"));
$WADApcms2_users = mysql_query($query_WADApcms2_users, $local) or die(mysql_error());
$row_WADApcms2_users = mysql_fetch_assoc($WADApcms2_users);
?>


you still have the old MySQL recordset in place. . .

Sign in to reply to this post

Jason

Sorry, those were the duplicate lines I forgot to delete again. After deleting those I get this error:

Notice: Undefined variable: row_WADApcms2_users in C:\xampp\htdocs\ALF\public_html\serving\kids\kids_insert_shift.php on line 12
Warning: call_user_func_array() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in C:\xampp\htdocs\ALF\public_html\webassist\mysqli\queryobj.php on line 123
Fatal error: Call to a member function execute() on a non-object in C:\xampp\htdocs\ALF\public_html\webassist\mysqli\queryobj.php on line 124

Attached Files
kids_insert_shift.php
Sign in to reply to this post

Jason ByrnesWebAssist

in the insert, you are using a binding from the old recordset, you will need to use the binding from the new recordset and make sure to move the new recordset to be before the insert.

Sign in to reply to this post

Jason

It's not giving me the error anymore, but its not actually submitting any data to the database now. After I hit submit it goes to the next page, but when I check the database there's no new entry.

Attached Files
kids_insert_shift1.php
Sign in to reply to this post

Jason

I added this code back from the previous version:

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

And now it's entering data to the database, but only if the "recurring" checkbox is unchecked, and it's entering 2 identical rows every time I hit submit.

Also, it's no longer inserting the userid into the database, just a 0.

Attached Files
kids_insert_shift.php
Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...