Jump to content

[SOLVED] problems selecting/creating a table...


Derleek

Recommended Posts

i'm completely stumped... granted i'm not all that experienced with php/mySQL but i can't figure out what exactly is wrong with my code here.

 

i'm sure there is a bunch though.

 

the object of this program is to take user input/varify it. then if it is valid store it into a database (moto) under the table fans...  the table doesn't seem to be created correctly (obviously an issue with my code)

 

so here it is... sorry if its sloppy...

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Sign Up!</title>
</head>
<body>
<p>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<label for="name">Name:  </label>
<input id="name" type="text" name="realName" maxlength="25" /><br />

<label for="name">Screen Name:  </label>
<input id="name" type="text" name="screenName" maxlength="25" /><br />

<label for="name">Password:  </label>
<input id="name" type="password" name="password" maxlength="25" /><br />

<label for="name">Confirm Password:  </label>
<input id="name" type="password" name="cPassword" maxlength="25" /><br />

<input id="submit" type="submit" value="Sign UP!" /><br />
</p>
<?php
function sanityCheck($string, $type, $length){

  // assign the type
  $type = 'is_'.$type;

  if(!$type($string))
    {
    return FALSE;
    }
  // to check if there is anything in the string
  elseif(empty($string))
    {
    return FALSE;
    }
  // to check how long the string is
  elseif(strlen($string) > $length)
    {
    return FALSE;
    }
  else
    {
    // if all is well, we return TRUE
    return TRUE;
    }
}

function checkSet(){
  return isset($_POST['realName'], $_POST['screenName'], $_POST['password'], $_POST['cPassword']);
}
if(checkSet() != FALSE)
{
if(empty($_POST['realName'])==FALSE && sanityCheck($_POST['realName'], 'string', 25)!=FALSE && empty($_POST['screenName'])==FALSE && sanityCheck($_POST['screenName'], 'string', 25)!=FALSE && empty($_POST['password'])==FALSE && sanityCheck($_POST['password'], 'string', 25)!=FALSE)
                {
        //If all is well  the value of the POST is assigned to a variable...
                $realName = $_POST['realName'];
			$screenName = $_POST['screenName'];
			$password = $_POST['password'];
			$cPassword = $_POST['cPassword'];
			if($password !=$cPassword)
				{
				echo 'your passwords don not match';
				exit();
				}
			$link = @mysql_connect('localhost', 'root', 'zOinks12');
			if (!$link) 
			    {
			    die('Not connected : ' . mysql_error());
			    }

			$db_selected = mysql_select_db('moto', $link);
			if (!$db_selected)
			    {
			    die ("Database not selected : " . mysql_error());
			    }

				$input = "CREATE TABLE fans (
				realName VARCHAR( 25 ) NOT NULL ,
				screenName VARCHAR( 100 ) NOT NULL ,
				password VARCHAR( 25 ) NOT NULL ,
				)";
			mysql_query($input,$link);
			// Query
			$uInput = sprintf("INSERT INTO fans (realName,screenName,password)
			    VALUES( '%s', '%s','%s')",
				mysql_real_escape_string($realName),
			    mysql_real_escape_string($screenName),
			    mysql_real_escape_string($password));
			// run the query
			if(!mysql_query($uInput))
			    {
			    echo 'Query failed '.mysql_error();
			     exit();
			    }
			  else
			    {
					echo "welcome to Pro Moto Fan bench racing!!!";
			    }
                }
		else
                {
                echo 'You did not fill out all of the fields!!';
                exit();
                }
}
else
{
	echo "Please fill out all of the above!";
}
?>
</body>

</html>

Link to comment
Share on other sites

sorry, new to this php/mySQL stuff...

 

here is the query

 

$uInput = sprintf("INSERT INTO fans (realName,screenName,password)
			    VALUES( '%s', '%s','%s')",
				mysql_real_escape_string($realName),
			    mysql_real_escape_string($screenName),
			    mysql_real_escape_string($password));
			// run the query
			if(!mysql_query($uInput))
			    {
			    echo 'Query failed '.mysql_error();
			     exit();
			    }
			  else
			    {
					echo "welcome to Pro Moto Fan bench racing!!!";
			    }
                }

 

i believe this is what you're looking for?

Link to comment
Share on other sites

well, i checked out phpMyAdmin  and the it appears that the table isn't even being created... here is that code that is right before the previously posted query code.

 

$input = "CREATE TABLE fans (
				realName VARCHAR( 25 ) NOT NULL ,
				uID bigint(20) NOT NULL AUTO_INCREMENT,
				screenName VARCHAR( 25 ) NOT NULL ,
				password VARCHAR( 25 ) NOT NULL ,
				PRIMARY KEY (`uID`),
				)";
			mysql_query($input,$link);

 

this code does not appear to be working...

Link to comment
Share on other sites

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.