sign up code

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
zarkolazarov
Forum Newbie
Posts: 6
Joined: Mon Jun 04, 2007 9:14 pm

sign up code

Post by zarkolazarov »

I have a problem inserting new users in to a database of users through php. I copied some codes from the net and I'm having problems adjusting them.

Here is the addauser.php file

Code: Select all

<?php include("validateform.inc"); ?>
<blockquote>
<blockquote>
<?php include("connect2db.php"); ?>
<?php include("getrecord.inc"); ?>
</blockquote>
</blockquote>
<blockquote>
<p>Add your own username and password, enter your details below and click save.&nbsp; <strong>DO
NOT</strong> use valid details as the information you enter will be displayed above and
the next visitor will be able to view them as you are now.</p>
</blockquote>
</blockquote>

<form
ACTION="savedata.php"
name="saveform" METHOD="POST" align="center">
<div align="center"><center><table border="0" width="93%" cellspacing="0" cellpadding="0">
<tr>
<td width="52%"><div align="center"><center><table border="0" height="59" width="310"
bgcolor="#808080" cellspacing="1" cellpadding="0">
<tr>
<td width="248" height="19" bgcolor="#C0C0C0"><div align="right"><p><font color="#000000"><small>Add
Your test username:</small></font></td>
<td width="123" height="19" bgcolor="#C0C0C0"><div align="left"><p><input NAME="username"
VALUE SIZE="8" MAXLENGTH="16" tabindex="1"></td>
<td width="47" height="19" align="center" bgcolor="#C0C0C0"><div align="center"><center><p><a
href="javascript:alert('The username must be between 4 and 16 characters long.')"><small><small>Help</small></small></a></td>
</tr>
<tr align="center">
<td width="248" height="17" bgcolor="#C0C0C0"><div align="right"><p><font color="#000000"><small>Add
Your test password:</small></font></td>
<td height="17" width="123" bgcolor="#C0C0C0"><div align="left"><p><input type="password"
name="password" size="8" tabindex="2" maxlength="8"></td>
<td width="47" height="17" align="center" bgcolor="#C0C0C0"><a
href="javascript:alert('The password must be between 4 and 8 characters long.')"><small><small>Help</small></small></a></td>
</tr>
<tr align="center">
<td width="248" height="1" bgcolor="#C0C0C0"></td>
<td width="123" height="1" bgcolor="#C0C0C0"><div align="left"><p><input TYPE="button"
NAME="FormsButton2" VALUE="save" ONCLICK="validateForm()" tabindex="3"></td>
<td width="47" height="1" align="center" bgcolor="#C0C0C0"><a
href="javascript:alert('Click to save the details')"><small><small>Help</small></small></a></td>
</tr>
</table>
</center></div></td>
<td width="48%" align="center"><small>When you have added your own username and password <a
href="login.php">move
onto the Login page to test it!</a></small></td>
</tr>
</table>
</center></div>
</form>

<p align="center">&nbsp;</p>

<p align="center"><a
href="addausercode.php">Click
here to view the PHP and JavaScript code</a> used for this page.</p>
and here is the savedata.php file that is being called in the adduser.php in the form:

Code: Select all

<?php
include("connect2db.php");
$qselect = "Select * from members where id = '1'";

function clean_input($string)
{
$patterns[0] = "/'/";
$patterns[1] = "/"/";
$string = preg_replace($patterns,'',$string);
$string = trim($string);
$string = addslashes($string);
return preg_replace("/[<>]/", '_', $string);
}


$username = clean_input($HTTP_POST_VARS ['username']);
$password = clean_input($HTTP_POST_VARS['password']);

$qadd = "
INSERT INTO members
(id, password, username)
VALUES ('1', 'test', '') ";
$qupdate = "
UPDATE members
SET password = '$password',
username = '$username'
WHERE id = '1'";

$result = mysql_query($qselect);

// check the single record exists
if (mysql_num_rows($result)) $result = mysql_query($qupdate); // update original record
else $result = mysql_query($qadd); // if not add an initial record

if ($result) mysql_close();
else
{
echo "ERROR - unable to save new username and password!<br>";
$SQLError = "SQL ERROR: ".mysql_errno().". ".mysql_error()."<BR><BR>";
echo "$SQLError";
mysql_close();
}
include("addauser.php");
?>
Please guys and girls can anuone help me solve this problem [s]coz[/s] because it's really urgent. Any help or suggestion is welcomed.
Thanks infront
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

You can start by helping us.

What is not working?

Do you get an error?

What have parts did you change?

What have you tried already?
User avatar
ReverendDexter
Forum Contributor
Posts: 193
Joined: Tue May 29, 2007 1:26 pm
Location: Chico, CA

Post by ReverendDexter »

And please... the blue text... kindly stop. That's almost as bad as all-caps 8O
User avatar
zarkolazarov
Forum Newbie
Posts: 6
Joined: Mon Jun 04, 2007 9:14 pm

problem solved

Post by zarkolazarov »

Well the problem was when the script tried to connect to the database. There was this error: Cannot connect to MySql using password bla bla. But I have solved the problem by changing some variables and some minor mistakes.
Anyway, thanks for taking interest and for trying to help.
I'm a beginner in PHP, so don't worry, you''ll see a lot of posts from me :))

Thanks again.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

I copied some codes from the net and I'm having problems adjusting them.
The code you copied is essentially trash. The second one is just a test, it could never work with the first one. I didn't take time to read through the first one, it looks like it has been gutted. What are all those <blockquote>s for??

If this is truly urgent, and you haven't learned to program, I'd say you better find a script that actually works just the way you want it to. Otherwise it's going to take a LOT of work to use what you've got.
Post Reply