Can someon help with my script?

This thing returns no syntax errors, it completes correctly, the DB info in mysql_connect is correct, it worked before I added the email field. It posts nothing to the db now that I added email. Thanks in advance for any help!

<?php
// Connects to your Database
mysql_connect("localhost", "protected_protected", "protected") or die(mysql_error());
mysql_select_db("protected_protected") or die(mysql_error());

//This code runs if the form has been submitted
if (isset($_POST['submit']))
{
//This makes sure they did not leave any fields blank
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] | !$_POST['email'] )
{
die('You did not complete all of the required fields');
}
// checks if the username is in use
if (!get_magic_quotes_gpc())
{
$_POST['username'] = addslashes($_POST['username']);
}
$usercheck = $_POST['username'];
$check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'")
or die(mysql_error());
$check2 = mysql_num_rows($check);
//if the name exists it gives an error
if ($check2 != 0)
{
die('Sorry, the username '.$_POST['username'].' is already in use.');
}
// this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2'])
{
die('Your passwords did not match. ');
}
// here we encrypt the password and add slashes if needed
$_POST['pass'] = md5($_POST['pass']);
if (!get_magic_quotes_gpc())
{
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['username'] = addslashes($_POST['username']);
$_POST['email'] = addslashes($_POST['email']);
}
// now we insert it into the database
$insert = "INSERT INTO users (username, password, email)
VALUES ('".$_POST['username']."', '".$_POST['pass'].", '".$_POST['email']."')";
$add_member = mysql_query($insert);
?>
<h1>Registered</h1>
<p>Thank you, you have registered - you may now login </a>.</p>
<?php
}

else
{
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0">
<tr><td>Please use your Second Life Username, This will be verified</td><tr>
<tr><td>Username:</td><td>
<input type="text" name="username" maxlength="60">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pass" maxlength="60">
</td></tr>
<tr><td>Confirm Password:</td><td>
<input type="password" name="pass2" maxlength="60">
</td></tr>
<tr><td>Email:</td><td>
<input type="text" name="email" maxlength="60">
</td></tr>
<tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr>
</table>
</form>
<?php
}
?>

u have an mysql_syntax error:
[php]$insert = “INSERT INTO users (username, password, email)
VALUES (’”.$_POST[‘username’]."’, ‘".$_POST[‘pass’].", ‘".$_POST[‘email’]."’)";[/php]
has to be:
[php]$insert = "INSERT INTO users (username, password, email)
VALUES (’".$_POST[‘username’]."’, ‘".$_POST[‘pass’]."’, ‘".$_POST[‘email’]."’)";[/php]

use of or die(mysql_error()) would have made it visible:
[php]$add_member = mysql_query($insert) or die(mysql_error());[/php]

Thanks so much for your help! Now I need to go kick myself in the head :). It works flawlessly!!

The previous fix works great, I have 1 more field I need to add to the db that is controlled by this file but it is not defined by a post, If you can tell me how to do this Ill be making a donation! The new varible is not defined as a post becuase it gets it from a URL so I dont know how to make it work :)

<?php
// Connects to your Database
mysql_connect("protected", "protected_protected", "protected") or die(mysql_error());
mysql_select_db("protected_protected") or die(mysql_error());

//This code runs if the form has been submitted
if (isset($_POST['submit']))
{
//This makes sure they did not leave any fields blank
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] | !$_POST['email'] )
{
die('You did not complete all of the required fields');
}
// checks if the username is in use
if (!get_magic_quotes_gpc())
{
$_POST['username'] = addslashes($_POST['username']);
}
$usercheck = $_POST['username'];
$check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'")
or die(mysql_error());
$check2 = mysql_num_rows($check);
//if the name exists it gives an error
if ($check2 != 0)
{
die('Sorry, the username '.$_POST['username'].' is already in use.');
}
// this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2'])
{
die('Your passwords did not match. ');
}
// here we encrypt the password and add slashes if needed
$_POST['pass'] = md5($_POST['pass']);
if (!get_magic_quotes_gpc())
{
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['username'] = addslashes($_POST['username']);
$_POST['email'] = addslashes($_POST['email']);
}
//get key here
$key = file_get_contents('http://w-hat.com/name2key/?terse=1&name=' .urlencode( $_POST['username']));
// now we insert it into the database
$insert = "INSERT INTO users (username, password, email, key, verify)
VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['email']."', '".$key."')";
$add_member = mysql_query($insert) or die(mysql_error());
?>
<h1>Registered</h1>
<p>Thank you, you have registered - you may now login</a>.</p>
<?php
}

else
{
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0">
<tr><td>Please use your Second Life Username, This will be verified</td><tr>
<tr><td>Username:</td><td>
<input type="text" name="username" maxlength="60">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pass" maxlength="60">
</td></tr>
<tr><td>Confirm Password:</td><td>
<input type="password" name="pass2" maxlength="60">
</td></tr>
<tr><td>Email:</td><td>
<input type="text" name="email" maxlength="60">
</td></tr>
<tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr>
</table>
</form>
<?php
}
?>

i don’t know what u mean with “it gets it from a URL”.
could u specify that, maybe give an example?

More specifically it gets it from the body of the URL, If you run Draco Kamachi as the name it will return a long string of numbers, The same holds true for 7million other names in Second life, I need it in the database for communication purposes. I have verified that $key is returning the proper number but this is day 1 with SQL and day 4 in php so Im very new and don’t know what im doing 100% yet.

i’m still not sur whether i got where ur problem is.
i’m still confused about the the mysql field called verify. wich gets no value assigned.
Do you need to get a value for this? Or is this another syntaxerror?

Its an error I thought I had removed, Verify is an account verification with a default value of 0 nothing gets wrote to it now.

I am unsure of what you are asking for as well, but are talking about the

$_GET[’’] function?

http://www.mysite.com/index.php?id=123

$id = $_GET[‘id’];

Now if you were to echo $id you would get 123.

Maybe thats not what you wanted, but I thought I would mention it.

The url example is
http://w-hat.com/name2key/?terse=1&name=Draco%20Kamachi
It pulls the full body of that into the varible of $key, put an echo $key; under it is shows that part is woking flawlessly, so $key is fine, what im having trouble with is key, Im not sure why its returning an SQL error

ok, i got it.

key is a reseved keyword in sql. like e.g. select.

best is not to use a field called like a reseved keyword.

an othe option that works fine as well is to surround the fieldname with ` (not a single quote but an acent)

if u cange that line to:
[php]$insert = “INSERT INTO users (username, password, email, key, verify)
VALUES (’”.$_POST[‘username’]."’, ‘".$_POST[‘pass’]."’, ‘".$_POST[‘email’]."’, ‘".$key."’)";[/php]
it will work fine

Well at least this time it was something I didn’t know any better about :slight_smile: .

good to know that it works.

if u wanna link to this side u may use:

<a href="http://phphelp.com/" target="_blank"><img src="http://phphelp.com/forums/templates/newSilver/images/logo_phpBB.gif" border="0" alt="phphelp.com" width="180" height="48"></a>

if u need a different size u have to ask peg110.

P.S.: if u gonna post some more php-code put it inside [php] instead of [code]

That size should be fine, I will be putting it on my 3 other sites as well so perhaps traffic will increase! I am trying to write a registration program (you fixed it for me) that will verify that someone is using the same name as they are in the game second life because it will interact with several communication programs I plan to launch, and I don’t want someone pretending to be someone else. I have moved to the verification part, and I have the in world program wrote so it sends the owners name of te verification device to the php and the php converts it to key then compares it, that way it can not be fooled without inside knowledge here is an example URL
http://www.sltrinkets.com/pro/pro.php?d … %20Kamachi
Thats a dead link on purpose. Heres the program that receives it

[php]

<?php $data = $_GET['data']; $key = file_get_contents('http://w-hat.com/name2key/?terse=1&name=' .urlencode( $data)); $link = mysql_connect("localhost", "protected_protected", "protected") or die('Could not connect: ' . mysql_error()); echo 'Connected successfully'; mysql_select_db("protected_protected") or die('Could not select database'); $query = mysql_query("SELECT * FROM users WHERE username = '".$data."'")or die(mysql_error()); $result = mysql_query($query) or die('Query failed: ' . mysql_error()); //find $data in the username section of the database, becuase it is a name if not found return error //if found get the key from the same line, if the key matches $key write a 1 to the verify of the same line //echo for testing purposes echo "n"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "tn"; foreach ($line as $col_value) { echo "ttn"; } echo "tn"; } echo "
$col_value
n"; mysql_free_result($result); mysql_close($link); echo "success"; ?>

[/php]

Now I have not tested that it is straight from notepad, I can almost guarantee Ill be getting sql errors, if you see some point them out, but I need to know how to do something.
That should find the username and print the whole line of the database its on, I need to know how to only print the key Is that possible? Thanks!

[php]echo $line[‘key’];[/php]

P.S.: u are using notepad? have a look at weaverslave!

Looks great, thanks. The Germans always did make the best software! Unfortunately during the day Im on a MAC but ill be sure to put it on my PC a home. Im using Host monster and it has a built in PHP editor so Ill have to stick with it and notepad for the mac :(

While Im posting, can you tell me what this error means

Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘Resource id #3’ at line 1

Line 1 is <?php and I dont have a clue about resource ID

wasn’t that app always called simpeltext?

u are using query twice:
[php]
$query = mysql_query(“SELECT * FROM users WHERE username = '”.$data."’")or die(mysql_error());
$result = mysql_query($query) or die('Query failed: ’ . mysql_error());
[/php]

the secont time u use it php converts the mysql result to a string wich is “Resource id #3”, and of cause trying to run “Resource id #3” as mysql-code that creates a mysql-syntax errror.

[php]
$query = “SELECT * FROM users WHERE username = '”.$data."’";
$result = mysql_query($query) or die('Query failed: ’ . mysql_error());
[/php]

edit: i had forgotten to delete the or die(mysql_error())

It may have been, Im not sure. What im using now is called text edit. The sql query I was using was a moded example, so I thought it was supposed to be like that. proved Genius once again that worked! Ill email the site I got it from and tell them they should post their work here :stuck_out_tongue: Thanks again

I LOVE THIS FORUM!

Let me ask you one last question about echo. 241affc6-98dc-4cbc-bddd-8fdc3869906a This is the value stored in the key section
241affc6-98dc-4cbc-bddd-8fdc3
869906a241affc6-98dc-4cbc-bd
dd-8fdc3869906a241affc6-98dc-4c
bc-bddd-8fdc3869906a241affc6-98dc-4
cbc-bddd-8fdc3869906a241affc6-98dc-4cb
c-bddd-8fdc3869906a241affc6-98dc-4cbc-bd
dd-8fdc3869906a
thats what it echos
and Idea why? Im posting the new script below.
I have seen /n and /t in echo, but the PHP book doesnt cover them what are they?

[php]

<?php $data = $_GET['data'];//gets the info after data= in the url and declares it $data $key = file_get_contents('http://w-hat.com/name2key/?terse=1&name=' .urlencode( $data)); $link = mysql_connect("localhost", "bizcards_admin", "dbase73354") or die('Could not connect: ' . mysql_error()); mysql_select_db("bizcards_database") or die('Could not select database'); $query = "SELECT * FROM users WHERE username = '".$data."'" or die(mysql_error()); $result = mysql_query($query) or die('Query failed: ' . mysql_error()); //find $data in the username section of the database, becuase it is a name if not found return error //if found get the key from the same line, if the key matches $key write a 1 to the verify of the same line while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { foreach ($line as $col_value) echo $line['key']; { } } mysql_free_result($result); mysql_close($link); ?>

[/php]
[/code]

Sponsor our Newsletter | Privacy Policy | Terms of Service