jandrews3 Posted June 14, 2008 Share Posted June 14, 2008 The following code works on a site I have with PHP version 4.3.9: $query = "SELECT id, lname, fname, mail1, mail2, city, state, country, email, telr, pdthru, active FROM ithf_members WHERE active > '1' AND ".$srch." LIKE '$this%' ORDER BY '$org'"; BUT when I move it to a new site using PHP 5.2.5 the same code generates the error: Could not perform query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIKE '%' ORDER BY 'lname'' at line 1 I'm moving to a new VPS account from a shared account. The new account has a much newer version of PHP. I guess I might end up having to debug have of my code from the last couple of years. Is this particular problem a result of difference in PHP versions? THANKS! Quote Link to comment https://forums.phpfreaks.com/topic/110215-php-version-difference/ Share on other sites More sharing options...
.josh Posted June 14, 2008 Share Posted June 14, 2008 looks like your $this variable is empty. Quote Link to comment https://forums.phpfreaks.com/topic/110215-php-version-difference/#findComment-565553 Share on other sites More sharing options...
PFMaBiSmAd Posted June 14, 2008 Share Posted June 14, 2008 This is not a php version problem. The variable $this is empty in your query, probably because your code relies on register_globals to "magically" populate program variables from post/get data. Your code is also not validating the inputs to your code or your validation logic would have output a message something like "You did not fill in a value to search for!" Post your code showing how the variable $this is being set in your code. Quote Link to comment https://forums.phpfreaks.com/topic/110215-php-version-difference/#findComment-565554 Share on other sites More sharing options...
jandrews3 Posted June 14, 2008 Author Share Posted June 14, 2008 Looks like you're right. I just checked the phpinfo.php of both sites. The one I've been using has the register_globals turned ON, but the new one does not. THANKS! I looked up how to turn it on and it worked! ¡Muchas gracias! Quote Link to comment https://forums.phpfreaks.com/topic/110215-php-version-difference/#findComment-565561 Share on other sites More sharing options...
.josh Posted June 14, 2008 Share Posted June 14, 2008 ...well you don't really want to have them turned on. There's a reason why it's turned off by default now. And by php6 register globals won't even be supported. For a reason. They are evil. Every time someone uses register globals, a server somewhere crashes and a little piece of the internet dies. Quote Link to comment https://forums.phpfreaks.com/topic/110215-php-version-difference/#findComment-565562 Share on other sites More sharing options...
jandrews3 Posted June 14, 2008 Author Share Posted June 14, 2008 Umm .... oops! Uh oh! That's all I've ever used for variable passing. I'll look into the alternatives. Quote Link to comment https://forums.phpfreaks.com/topic/110215-php-version-difference/#findComment-565565 Share on other sites More sharing options...
jandrews3 Posted June 14, 2008 Author Share Posted June 14, 2008 I thought if I turned off the register_globals and used $this=$_POST['this']; that it would solve the problem of $this being empty. A quick look on my part led me to believe that this was how you capture variables passed from a form using POST, but I'm getting the following error: Fatal error: Cannot re-assign $this in /home/ositoweb/public_html/ithf_test/members/member_dsearch.php on line 10 The page code is: <? $this=$_POST['this']; ?> <table width="800" border="0" cellpadding="0" cellspacing="0" style="font-family: helvetica; font-weight: bold;"> <tr> <td align="center" width="800" bgcolor="222255"><font color="white">Search Engine</font></td> </tr> </table> <br> <table border="0" cellpadding="0" cellspacing="0" width="800" style="font-family: helvetica; font-size: 10pt;"> <tr> <td><b>Search results for posted query.</b></td> </tr> <tr> <td height="5"></td> </tr> </table> <br> <table width="800" border="0" cellpadding="0" cellspacing="0" style="font-size: 10pt;"> <tr> <td colspan="4"><b> Select to see full profile</b><br><br></td> <td colspan="3" align="right"><a href="directory2.php?this=<?print $this?>&srch=<?print $srch?>" target="_blank"><b><u>Build Directory</u></b></a></td> </tr> <tr> <td><a href="member_dsearch.php?org=lname&srch=<?print $srch?>&this=<?print $this?>" target="_self"> Name</a></td> <td><a href="member_dsearch.php?org=email&srch=<?print $srch?>&this=<?print $this?>" target="_self"> Email</a></td> <td><a href="member_dsearch.php?org=restel&srch=<?print $srch?>&this=<?print $this?>" target="_self">Phone</a></td> <td><a href="member_dsearch.php?org=city&srch=<?print $srch?>&this=<?print $this?>" target="_self">City</a>, <a href="member_dsearch.php?org=state&srch=<?print $srch?>&this=<?print $this?>" target="_self">State</a></td> <td><a href="member_dsearch.php?org=country&srch=<?print $srch?>&this=<?print $this?>" target="_self">Country</a></td> </tr> <tr> <td colspan="8"><hr></td> </tr> <tr> <?php if ($org == ''){$org = "lname";} $link = mysql_connect("ositowebsolutions.com","••••••••","••••••••") or die("Could not connect: ".mysql_error()); mysql_select_db("my_database") or die("Could not select database: ".mysql_error()); $query = "SELECT id, lname, fname, mail1, mail2, city, state, country, email, telr, pdthru, active FROM ithf_members WHERE active > '1' AND ".$srch." LIKE '$this%' ORDER BY '$org'"; if ($srch == "lang" or $srch == "telr" or $srch == "rinterests" or $srch == "ointerests" or $srch == "ainterests" or $srch == "local" or $srch == "email" or $srch == "keyp"){$query = "SELECT id, lname, fname, mail1, mail2, city, state, country, email, telr, pdthru, active FROM ithf_members WHERE active > '1' AND ".$srch." LIKE '%$this%' ORDER BY '$org'";} $result = mysql_query($query) or die("Could not perform query: ".mysql_error()); $total = mysql_num_rows($result); $counter = 0; while ($row = mysql_fetch_array($result)) { if ($row['active'] == "0"){$changeit = "active"; $act="No";} if ($row['active'] == "2"){$changeit = "inactive"; $act="Yes";} if ($row['active'] == "1"){$changeit = "active"; $act="Pending";} if ($row['active'] == "3"){$changeit = "inactive"; $act="Yes";} if ($row['pdthru'] == ''){$row['pdthru'] = "P";} include 'valgen_v.php'; print "<td nowrap><a href=\"profile.php?validate=".$validate."\" target=\"_blank\"> ".$row['lname'].", ".$row['fname']." </a></td><td nowrap><a href=\"mailto:".$row['email']."\">".$row['email']."</a></td><td nowrap>".$row['telr']." </td><td nowrap>".$row['city'].", ".$row['state']." </td><td nowrap>".$row['country']." </td></tr><tr>"; $counter++; } ?> </tr> </table> <br><?print "Matching entries: ".$counter;?> <table border="0" cellpadding="0" cellspacing="0" width="800" style="font-size: 10pt; font-family: helvetica;"> <tr> <td <?if ($counter < 10){print "height=\"350\"";} else {print "height=\"30\"";}?>></td> </tr> <tr> <td height="30" align="center" valign="middle"><a href="http://www.ositowebsolutions.com" target="_blank"><img src="graphics/poweredby1.jpg" border="0"></a></td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/110215-php-version-difference/#findComment-565569 Share on other sites More sharing options...
wildteen88 Posted June 14, 2008 Share Posted June 14, 2008 The variable $this is a reserved in PHP5, you cannot redeclare it. You'll have to name your variable to something else. Quote Link to comment https://forums.phpfreaks.com/topic/110215-php-version-difference/#findComment-565580 Share on other sites More sharing options...
PFMaBiSmAd Posted June 14, 2008 Share Posted June 14, 2008 Sorry to pick/rant, but register_globals were turned off by default in php4.2 in April 2002. That was a full six years ago. No new code, new tutorials, new books, new servers, or new hosting accounts should have used register_globals after that point in time. In 2008, there should be no one using the php programming language that is still relying on register_globals. Six years in computer/programming time is like decades for any other product. Every script that existed in 2002 (except for perhaps Oscommerce) has undergone at least one revision/update between then and now and should have had any dependencies on register_globals removed. As Crayon Violent mentioned, register_globals have been completely eliminated in php6, so any existing code that still relies on register_globals to "magically" populate program variables (and magically change session variables) from external post/get/cookie data needs to be fixed or it will stop working under php6. Quote Link to comment https://forums.phpfreaks.com/topic/110215-php-version-difference/#findComment-565581 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.