Solved

true false statement mysql php

Posted on 2008-10-31
2
933 Views
Last Modified: 2013-12-13
Looking for a quick  example on how make a php to mysql (true / false) compare.

This would be using a sign up form:

So all the basic stuff I have down (login/sql/query/etc..)



I am guessing....example code ;)
 
// old or new user example //
 
function oldOrNew (signupID)
 
{
    login into db;
    login into myTable ;
	//compare the id against the table//
 
	if(userid on myTable == signupID & oldPassword on myTable == newPassword)
	{
		echo "you already have signed up...but you have uninstalled the application"
 
		echo "please fill out form about what we could have done to make it a better app, and thanks for coming back!"
 
	}   
 
	else
	{
		echo "thanks for signing up"
		doSomeFunction();
    }
 
 
 
 
}
 
// 11223 would be the example var ID to pass to the function //
 
oldOrNew(11223);

Open in new window

0
Comment
Question by:cntmedia
[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
2 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 250 total points
ID: 22855548

<?php
//returns true if user already signed up
//false otherwise
function oldOrNew ($signupID,$newPassword) 
{
	mysql_connect("localhost","username","password") or die(mysql_error());
	mysql_select_db("dbname") or die(mysql_error());
	$rs = mysql_query("SELECT 1 signedUp FROM tableName WHERE tableName.id=$signupID and tableName.password = '$newPassword'") or die(mysql_error());
	if( mysql_num_rows($rs) > 0 )
	{
		echo "you already have signed up...but you have uninstalled the application"
		echo "please fill out form about what we could have done to make it a better app, and thanks for coming back!"
	} 
	else
	{
		echo "thanks for signing up"
		doSomeFunction();
    }
return (mysql_num_rows($rs) > 0);
}
 ?>

Open in new window

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 22862666
I think the easiest way to find out if a user had already signed up would be to select the user's id out of the data table.  If there are no rows, you have not got a user with that id.

HTH, ~Ray
if (!$r = mysql_query("SELECT uid FROM users WHERE ukey = 11223 LIMIT 1")) { die(mysql_error()); }
 
// IF MYSQL NUM ROWS IS ZERO, IT IS THE SAME AS FALSE; IF ONE IT IS TRUE
if (mysql_num_rows($r)) {
   echo "Already signed up";
} else {
   echo "Not signed up yet";
}

Open in new window

0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

628 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