/    Sign up×
Community /Pin to ProfileBookmark

Nedd help with my registration Mysql script

Hi!, the following code returns this error:
” Parse error: parse error, expecting `T_STRING’ or `T_VARIABLE’ or `T_NUM_STRING’ in e:easyphp1-8wwwunnamed site 2untitled-1.php on line 44 “.
The line that the error refers to is marked with an underline.
Nothing i tried so far didn’t help ? .

[code=php]

Code:
<?php
If($_SERVER[‘HTTP_REFERER’]==$_SERVER[‘PHP_SELF’] or isset($_POST[‘check’]))
{
if($_POST[‘name’]!=NULL and $_POST[‘password’]!=NULL and $_POST[‘password2′]!=NULL and
$_POST[’email’]!=NULL and $_POST[’email2′]!=NULL)
{
$meaasge=””;
$submit=1;
function sanitize_input($input)
{
if(get_magic_quotes_gpc())
$input = stripslashes($input);
return(mysql_real_escape_string($input));
}
if($_POST[‘icq’]!=NULL and !is_numeric($_POST[‘icq’]))
{
if($submit==0)
$message=$message.”<br>Please enter an integer number in the “ICQ” field”;
else
$message=”Please enter an integer number in the “ICQ” field”;
$submit=0;
}
$link=mysql_connect(“127.0.0.1”, “root”, “”) or die(mysql_error());
mysql_select_db(“nba”, $link) or die(mysql_error());
if(strcmp($_POST[‘password’], $_POST[‘password2’])!=0)
{
if($submit==0)
$message=$message.”<br>The passwords you entered doesn’t match.”;
else
$message=”The passwords you entered doesn’t match.”;
$submit=0;
}
if(strcmp($_POST[’email’], $_POST[’email2′]) != 0)
{
if($submit==0)
$message=$message.”<br>The email addresses you have entered doesn’t match.”;
else
$message=”The email addresses you have entered doesn’t match.”;
$submit=0;
}
if($submit==1)
{
$query=”INSERT INTO ‘users'(‘name’, ‘password’, ‘date’, ‘msn’, ‘icq’, ’email’)
[U]VALUES(‘$_POST[‘name’]’,’md5($_POST[‘password’])’,’time()’,’$_POST[‘msn’]’, ‘$_POST[‘icq’]’,’$_POST[’email’]’)”;[/U]
$results=mysql_query($query, $link) or die(mysql_error());
print(“$results”);
print(“success”);
}
}
else
print(“Please fill out all the fields marked with “*””);
if(isset($message))
print($message);
}

?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=” />
<title>Untitled Document</title>
</head>

<body>
<form method=”post” action=”<?php print($_SERVER[‘PHP_SELF’]);?>”>
<table width=”70%” border=”0″ cellspacing=”1″ cellpadding=”0″ align=”right” dir=”rtl”>
<tr>
<td width=”20%”>User name*</td>
<td width=”30%”><input type=”text” dir=”rtl” align=”right” name=”name” maxlength=”12″ /></td>
<td width=”20%”>Retype E-mail* </td>
<td><input type=”text” dir=”rtl” align=”right” name=”email2″ maxlength=”30″ /></td>

</tr>
<tr>
<td>password*</td>
<td><input type=”password” dir=”rtl” align=”right” name=”password” maxlength=”20″ size=””/>
</td>
<td width=”20%”>Msn messengr ID</td>
<td><input type=”text” dir=”rtl” align=”right” name=”msn” maxlength=”20″ /></td>

</tr>
<tr>
<td>retype password*</td>
<td><input type=”password” dir=”rtl” align=”right” name=”password2″ maxlength=”20″ /></td>
<td>ICQ number </td>
<td><input type=”text” dir=”rtl” align=”right” name=”icq” maxlength=”12″ /></td>

</tr>
<tr>
<td width=”20%”>Contact E-mail*</td>
<td><input type=”text” dir=”rtl” align=”right” name=”email” maxlength=”30″ /> </td>

</tr>
<tr><td><input type=”submit” dir=”rtl” align=”right” value=”send” /></td></tr>
</table>
<input type=”hidden” name=”check” value=”1″ />
</form>
</body>
</html>[/code]

Screenshot of the DB:
[url]http://img355.imageshack.us/img355/3729/shot4tw.jpg[/url] .

to post a comment
PHP

14 Comments(s)

Copy linkTweet thisAlerts:
@chazzyJan 08.2006 — for starters, I would change your message building logic.

if you declare $message = ""; near the top, you can just replace:
[code=php]
if($submit==0)
$message=$message."<br>Please enter an integer number in the "ICQ" field";
else
$message="Please enter an integer number in the "ICQ" field";
$submit=0;
[/code]

with just
[code=php]
$message.="Please enter....";
[/code]


It's also smart to use proper brackets regularly, not intermittently. Maybe you could rewrite the code w/ those 2 suggestions and try it again?
Copy linkTweet thisAlerts:
@HellgYauthorJan 08.2006 — Thanks, i will apply your advice... but that's doesn't seem to be the problem since I'm passing this condition successfully...

I marked the line that returns the error(at submit), At least i tried to...

the VB code doesn't seem to take effect.
Copy linkTweet thisAlerts:
@chazzyJan 08.2006 — errors like yours are never on the line that they mark, they're somewhere before it.

could you maybe copy that line through 5-10 lines above so we can look?
Copy linkTweet thisAlerts:
@HellgYauthorJan 08.2006 — Hmm this source is the whole page...
Copy linkTweet thisAlerts:
@chazzyJan 08.2006 — use this for your values line of the INSERT.
<i>
</i>VALUES('".$_POST['name']."','".md5($_POST['password'])."','".NOW()."','".$_POST['msn']."','".$_POST['icq']."','".$_POST['email']."')";

PHP sees too many single quotes and cries. let me know if you still get the problem.
Copy linkTweet thisAlerts:
@HellgYauthorJan 08.2006 — I tried that already.... ha a syntax error trying to execute the query(in the line below).
Copy linkTweet thisAlerts:
@HellgYauthorJan 09.2006 — Bump:, thanks to chazzy for his attempts to help me so far.

EDIT: You may want to enter 'NOW()' as a string, because it's an Mysql function

and has no significance for the PHP engine... and should return value when the query is executed.

Also, There shouldn't be quotation marks near the NOW() function, because it's an Mysql function and not a direct value.

here is an example of what i mean:

VALUES('".$_POST['name']."','".md5($_POST['password'])."', NOW(),'".$_POST['msn']."','".$_POST['icq']."','".$_POST['email']."')";

Even with this issue corrected i receive the same error i had when used the same syntax with the function time().

Here's the error i receive now:" 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 ''users'('name', 'password', 'date', 'msn', 'icq', 'email') ".

HERE IS HOW THE DATABASE I'M WORKING WITH LOOKING BROWSWD BY PHPMY ADMIN: http://img355.imageshack.us/img355/3729/shot4tw.jpg .
Copy linkTweet thisAlerts:
@chickenlandJan 09.2006 — You wont be able to use NOW() as the date field is an INT. Not sure if date() function will help, but it is a PHP function. You could always change the datatype to be a DATETIME type perhaps ?

VALUES('".$_POST['name']."','".md5($_POST['password'])."', ".date('Ymd').",'".$_POST['msn']."','".$_POST['icq']."','".$_POST['email']."')";

try that ?
Copy linkTweet thisAlerts:
@chazzyJan 09.2006 — first of all never store a date as anything other than a date, you're cutting yoruself off from all of the functionality that using a date provides (especially in mysql, date/time functions are extremely robust for the little guy)

and you're right aboutt he NOW() thing, it should just be ,NOW(), guess I got a little quote crazy there.

so convert your date format to a real date format and try it out.
Copy linkTweet thisAlerts:
@HellgYauthorJan 10.2006 — Hmm still getting an error, regardless to which phrase I'm using, Maybe its because I'm trying to store MD5 encoded password in a char(150) column?.

Thanks for taking the time to help me!.
Copy linkTweet thisAlerts:
@bokehJan 10.2006 — There's a problem with the query. Here's what you posted above:[code=php]$query="INSERT INTO 'users'('name', 'password', 'date', 'msn', 'icq', 'email')
[U]VALUES('$_POST['name']','md5($_POST['password'])','time()','$_POST['msn']',[/code]
The first line should contain no quotes... backticks maybe... but no quotes. Then the second line [I]VALUES[/I] is incomplete. Also arrays should be in curly braces:[code=php]{$_POST['password']}[/code]With functions like time() and md5() you need to work on an unquoted section.[code=php]'".time()."'[/code]
Copy linkTweet thisAlerts:
@chickenlandJan 10.2006 — I've copied and pasted your code, and reproduced your error:

[CODE]$query="INSERT INTO users(name, password, date, msn, icq, email) VALUES('".$_POST['name']."','".md5($_POST['password'])."','".time()."','".$_POST['msn']."','".$_POST['icq']."','".$_POST['email']."')";[/CODE]

there were some weird extra characters between the end of the INTO line and the beginning of the VALUES line; i dont know if these have been added because I copied it off this page or not... It could be this that is causing PHP to expect something else. Try it all on one line.

This produced no error... but i dont have the database set up, so it might cause 'other problems' later.

edit : Just so you understand, I got this error without actually submitting the form, so the PHP never actually called the SQL statement...
Copy linkTweet thisAlerts:
@HellgYauthorJan 10.2006 — WOW!, I don't know what exactly did you do, but it's working!, i am most grateful!.

As deep as i dig, there seems to be no difference between my and your code.

AH, you just utilized Bokeh's advices... i already used function NOW without quotes...

It seems that the source of my problem was the quoted MD5 function withing the query.
Copy linkTweet thisAlerts:
@chickenlandJan 10.2006 — Glad it works. I just tested the code i posted yesterday though, and that works fine too.
×

Success!

Help @HellgY spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...