Solved

script works in php 4 but not 5

Posted on 2011-03-22
17
371 Views
Last Modified: 2012-05-11
I have a php script which checks a table for user registering but counting the id field from a table , and if the count = 0 then it inserts a new record into mysql, but I have just bought a new laptop and set it up with php5 and also new version of mysql (if that makes a difference) and have discovered that it is no longer inserting a record. I was wondering if someone could point me in the right direction or list the things I need to check?
if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'add')
{
	
	
	///Check if email is already registered in the system.
	$user_count = mysql_query("select count(id) sc_count from tblschoollogin where email = '".mysql_real_escape_string($_REQUEST['email'])."'");

	$row_locality = mysql_fetch_assoc($user_count);
	
	///If not registered simply enter into the system
	if($row_locality['sc_count'] == 0){
	mysql_query("insert into tblschoollogin set email = '".mysql_real_escape_string($_REQUEST['email'])."', name = '".mysql_real_escape_string($_REQUEST['name'])."', local_authority_id = ".$_REQUEST['local_authority_id'].", school_learning_est_id = ".$_REQUEST['school_learning_est_id'].", telephonenumber = '".mysql_real_escape_string($_REQUEST['telephonenumber'])."'");


	echo "Thank you for signup. Your profile will be reviewed and password will be emailed to you.<br><br>";
	echo "Please view  invitation ".'<a href="EngaugeUpload/Letter 2 Schools- self assessment pilot study Jan 27 -  010.doc">here</a>'." that is being sent to school's";
	echo '<p><a href="http://engaugeonline.co.uk" class="tab">go to home page</a></p>';
	
// send mail to admin with registration notification message
						$mail = new PHPMailer();
						//$mail->IsSMTP();
						$mail->Host = "auth.smtp.1and1.co.uk";
						$mail->SMTPAuth = false;
						$mail->Username = "info@engaugeonline.co.uk";
						$mail->Password = "frankblack";
						$mail->From = "info@engaugeonline.co.uk";
						$mail->To= "info@engaugeonline.co.uk";
						$mail->FromName = "Registration Administrator";
						$mail->AddAddress("info@engaugeonline.co.uk");
						$mail->IsHTML(true);
						$mail->Subject = "A new user has registered for Engauge Online";
						$mail->Body = "Please go to the Engauge Team Admin webpage to verify user and issue a password";
						if($mail->Send())
                           echo "Registration mail has been sent to the Engauge Team";
						else
							 echo "Mailer Error: " . $mail->ErrorInfo . "<br />";
			
// end of mail notification code
		
		exit;
	}else{
		echo "Email is already registered with us";
		exit;
	}

Open in new window

0
Comment
Question by:jezskill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 4
  • +1
17 Comments
 
LVL 17

Expert Comment

by:Chris Harte
ID: 35188678
First, since it is a new install of mysql, make sure the php has access rights to update the database (in my experience this is usually the problem).

If that is okay then either the insert command is failing or the code never calls the insert command. Test the if first

    ///If not registered simply enter into the system

   echo "count is ".$row_locality['sc_count'];

    if ($row_locality['sc_count'] == 0)

if count is anything other that 0 it will never call the insert.
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35189124
The other thing that regularly screws up websites moving from PHP4 to PHP5 is register_globals. In PHP5 it is OFF by default whereas in early versions of PHP4 it was ON by default.

On your older server run

<?php
phpinfo();
?>

and scan for 'register_globals' - in most browsers pressing CTRL-F will pop a search box.
0
 
LVL 1

Author Comment

by:jezskill
ID: 35198158
bportlock, turning the register_globals on hasnt resolved the issue.
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 5

Expert Comment

by:innotionent
ID: 35198271
Where is your error catching?

Try the below code to see what sort of error you are having.
$mysql_connection = @mysql_pconnect("localhost","user","pass") or die("<hr><b>MySQL Connection Failed</b>: ".mysql_error()."<hr>");
	$mysql_querystring = "select * from table";
	$mysql_result = mysql_db_query($mysql_table,$mysql_querystring,$mysql_connection) or die("<hr><b>MySQL Query Failed</b>: ".mysql_error()."<hr>");

Open in new window

0
 
LVL 1

Author Comment

by:jezskill
ID: 35201562
hi Munterman, I pasted th code into my code and the value is 0 so that bit seems ok, just wont insert the record into mysql table. I;m sure the access rights are ok as other scripts in this web application are inserting records into other tables. Could it be a Mysql thing?
0
 
LVL 5

Expert Comment

by:innotionent
ID: 35201633
@jezskill - Please review the code I posted. You will be able to return a mysql error to better debug your code.
0
 
LVL 1

Author Comment

by:jezskill
ID: 35201936
innotionent:

where in your code script do I declare the database name?
0
 
LVL 1

Author Comment

by:jezskill
ID: 35202110
innotionent,

this is what I get with your code.

Notice: Undefined variable: mysql_table in C:\websites\sustrade\signup.php on line 143

--------------------------------------------------------------------------------
MySQL Query Failed: No database selected
0
 
LVL 17

Expert Comment

by:Chris Harte
ID: 35205891
"Inserts into other tables"

Have these tables got the same access rights as the ones that are working? Add mysql_error to the query line.


Also, echo the query to the screen then run it against the database to make sure it is correct.


mysql_query("insert into tblschoollogin set email = '".mysql_real_escape_string($_REQUEST['email'])."', name = '".mysql_real_escape_string($_REQUEST['name'])."', local_authority_id = ".$_REQUEST['local_authority_id'].", school_learning_est_id = ".$_REQUEST['school_learning_est_id'].", telephonenumber = '".mysql_real_escape_string($_REQUEST['telephonenumber'])."'") or die('the error is ', mysql_error());

Open in new window

0
 
LVL 5

Expert Comment

by:innotionent
ID: 35206484
@jezskill: you need to define the variable $mysql_table. And it should equal the DB you are trying to query  from.
Sorry bout that.
0
 
LVL 1

Author Comment

by:jezskill
ID: 35210856
It seems that it was a table column in the database set to not null but had no defuault value assigned. It was a date field and I was hoping to make the default value todays date i.e. now() but I have read this cannot be done for a date field data type, only timestamp. Please suggest how to divvy the points?
0
 
LVL 17

Expert Comment

by:Chris Harte
ID: 35215147
Before you do anything else make sure register_globals is off. It was a very bad idea to turn them on, and they are now deprecated.

http://php.net/manual/en/security.globals.php

Other than that, were any of the answers useful? If not, you could ask for a refund.

Though personally I would give them all to me, I need them more than portlock. ;)
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35215300
"It was a very bad idea to turn them on, and they are now deprecated."

I wasn't suggesting that they should BE turned on, just that might might have BEEN on for the older server.


"Though personally I would give them all to me, I need them more than portlock. ;)"

:-D

Oh I dunno.... I only need another 50,000 or so to break the 2,000,000 total........ I won't object if Jezskill awards you all the point, my contribution to this was fairly minimal.

Cheers!

BP
0
 
LVL 17

Expert Comment

by:Chris Harte
ID: 35215444
I wasn't suggesting that they should BE turned on, just that might might have BEEN on for the older server.

Yes, but he did turn them on, even though that is not what you suggested. I cannot over emphasise this, they must be turned off.
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35215469
"I cannot over emphasise this, they must be turned off."

I agree.

0
 
LVL 5

Accepted Solution

by:
innotionent earned 500 total points
ID: 35218097
@ jezskill: Correct. Timestamp you can do on update current time stamp.
With a date I suggest using 0000-00-00 00:00:00 as your default.
That way you can filter out those results in your queries.
Though on insert I would just use NOW().
0
 
LVL 1

Author Closing Comment

by:jezskill
ID: 35221086
In direct assistance appreciated
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question