Jump to content

Recommended Posts

am i wrong in thinking that $id = $emailresult, would have the id in of a user that already exists.

 

HEres the code. its basically just a check to see if a user exists and if he doesnt add him and if he does dont and print out the id of the user that exists.

 

/*sql query to find if email address exists for client*/
			$emailquery = "SELECT id FROM clients WHERE email = '$email'";
			$emailresult = mysql_query($emailquery);

			/* if there are rows returned for the contact id
			the below code will return true*/
			if(!mysql_num_rows($emailresult))
			{
				/* if no row is returned insert to db*/
				$addClientSQL = "INSERT INTO clients(title, name, surname, email, telephone, address1, address2, town, county, postcode, country, emailMarketing, mailMarketing) VALUES ('$title','$name','$surname','$email','$telephone','$address1','$address2','$town','$county','$postcode','$country','$emailMarketing','$mailMarketing')";

				$db->execute($addClientSQL);
				echo mysql_error();
				$client_id = mysql_insert_id();
				header('location: index.php');
			}

			else
			{	
				/*pass the id through url to get that users records*/
				$id = $emailresult;		
				echo $id;		

Link to comment
https://forums.phpfreaks.com/topic/187386-whats-being-passed-to-my-variable/
Share on other sites

am i wrong in thinking that $id = $emailresult, would have the id in of a user that already exists.

 

Yes. In your example $emailresult is a result resource. You would need to pass this resource to mysql_fetch_assoc (or similar) to actually get any data out of the resource.

Thanks for your help guys, im getting this error now

 

Catchable fatal error: Object of class stdClass could not be converted to string in D:\Inetpub\wwwroot\dhcottages.co.uk\testsite\admin\clients\saveClients.php on line 174

 

my code is now

/*sql query to find if email address exists for client*/
			$emailquery = "SELECT id FROM clients WHERE email = '$email'";
			$emailresult = mysql_query($emailquery);

			/* if there are rows returned for the contact id
			the below code will return true*/
			if(!mysql_num_rows($emailresult))
			{
				/* if no row is returned insert to db*/
				$addClientSQL = "INSERT INTO clients(title, name, surname, email, telephone, address1, address2, town, county, postcode, country, emailMarketing, mailMarketing) VALUES ('$title','$name','$surname','$email','$telephone','$address1','$address2','$town','$county','$postcode','$country','$emailMarketing','$mailMarketing')";

				$db->execute($addClientSQL);
				echo mysql_error();
				$client_id = mysql_insert_id();
				header('location: index.php');
			}

			elseif(mysql_num_rows($emailresult))
			{	
				/*pass the id through url to get that users records*/
				$id = mysql_fetch_field($emailresult, 0);

				echo $id;		
				echo "Sorry a user with that email address exists in our database <br />";

 

 

ive used mysql_fetch_field thing.

 

 

And line 174 is?

 

Also, you seem to be using two different database access methods. One, an object ($db) and the other, the standard mysql extension. You should use one and stick to it unless you need multiple connections to multiple database types or something.

Hi, sorry i know i use 2 diff db types, one was written before me and was ridiculous so im just using standered connection, plus my boss has told me that this is what he wants.

 

 

line 172 is

$id = mysql_fetch_field($emailresult, 0 );

and the complete code is

 

/*sql query to find if email address exists for client*/
			$emailquery = "SELECT id FROM clients WHERE email = '$email'";
			$emailresult = mysql_query($emailquery);

			/* if there are rows returned for the contact id
			the below code will return true*/
			if(!mysql_num_rows($emailresult))
			{
				/* if no row is returned insert to db*/
				$addClientSQL = "INSERT INTO clients(title, name, surname, email, telephone, address1, address2, town, county, postcode, country, emailMarketing, mailMarketing) VALUES ('$title','$name','$surname','$email','$telephone','$address1','$address2','$town','$county','$postcode','$country','$emailMarketing','$mailMarketing')";

				$db->execute($addClientSQL);
				echo mysql_error();
				$client_id = mysql_insert_id();
				header('location: index.php');
			}

			elseif(mysql_num_rows($emailresult))
			{	
				/*pass the id through url to get that users records*/
				$id = mysql_fetch_field($emailresult, 0 );

				echo $id;		
				echo "Sorry a user with that email address exists in our database <br />";

 

Thank you it works now using result, cheers.

One last question i thought that because i was 

/*sql query to find if email address exists for client*/
			$emailquery = "SELECT id FROM clients WHERE email = '$email'";
			$emailresult = mysql_query($emailquery);

 

it would only return the id but does it bring back the whole row still? and thats why its an array?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.