Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 379
  • Last Modified:

script works in php 4 but not 5

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
jezskill
Asked:
jezskill
  • 6
  • 4
  • 4
  • +1
1 Solution
 
Chris HarteThaumaturgeCommented:
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
 
Beverley PortlockCommented:
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
 
jezskillAuthor Commented:
bportlock, turning the register_globals on hasnt resolved the issue.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
innotionentCommented:
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
 
jezskillAuthor Commented:
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
 
innotionentCommented:
@jezskill - Please review the code I posted. You will be able to return a mysql error to better debug your code.
0
 
jezskillAuthor Commented:
innotionent:

where in your code script do I declare the database name?
0
 
jezskillAuthor Commented:
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
 
Chris HarteThaumaturgeCommented:
"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
 
innotionentCommented:
@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
 
jezskillAuthor Commented:
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
 
Chris HarteThaumaturgeCommented:
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
 
Beverley PortlockCommented:
"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
 
Chris HarteThaumaturgeCommented:
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
 
Beverley PortlockCommented:
"I cannot over emphasise this, they must be turned off."

I agree.

0
 
innotionentCommented:
@ 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
 
jezskillAuthor Commented:
In direct assistance appreciated
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now