/    Sign up×
Community /Pin to ProfileBookmark

I’m new to PHP and I’m trying to explore the world of databases. I found a script on the internet I wanted to try out but I was having some problems. When I run the script in a browser it gives me back this error:

Parse error: parse error, unexpected T_STRING in /mnt/w0604/d20/s28/b025060c/www/test_calendar2.php on line 52

[code=php]

<!DOCTYPE html PUBLIC
“-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html>
<head>
<title>Adding user input to a database</title>
</head>
<body>
<?php

if( ! empty( $_REQUEST[‘sex’] ) &&
! empty( $_REQUEST[‘domain’] ) &&
! empty( $_REQUEST[‘mail’] ) ) {
//check user input here!
$dberror = “”;
$ret = add_to_database( $_REQUEST[‘domain’],
$_REQUEST[‘sex’],
$_REQUEST[‘mail’], $dberror);
if(! $ret ) {
print “Error: $dberror<br />n”;
} else {
print “Thank you very much<br />n”;
}
} else {
write_form();
}

function add_to_database( $domain, $sex, $mail, &$dberror ) {
$domain = mysql_real_escape_string( $domain );
$sex = mysql_real_escape_string( $sex );
$mail = mysql_real_escape_string( $mail );
$link = mysql_pconnect(“mysql.netfirms.com”, “*hidden for security*”, “**hidden for security**” );
if(! $link ) {
$dberror = mysql_error();
return false;
}
if( ! mysql_select_db(“d60286207″, $link ) ) {
$dberror = mysql_error();
return false;
}
$query =”INSERT INTO domains( domain, sex, mail )
values( ‘$domain’,
if( !mysql_query($query, $link ) ) {
$dberror= mysql_error();
return false;
}
return true;
}

function write_form() {
print <<<EOF
<form method=”post” action=”{$_SERVER[‘PHP_SELF’]}”>//line 52

<p><input type=”text” name=”domain” size=”20″ />
The domain you would like</p>

<p><input type=”text” name=”mail” size=”20″ />
Your mail address</p>

<p><select name=”sex”>
<option value=”F”>Female</option>
<option value=”M”>Male</option>
< /select></p>

<p><input type=”submit” value=”submit!” /></p>
</form>
FORM;
}
?>
</body>
</html>

[/code]

If you have any suggestions on what I should do to fix this script please let me know.

Thanks,
Travis

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@so_is_thisDec 21.2006 — If you pay attention to the colors in your post, the colors themselves will tell you what is the problem. You're missing a closing quote on your SQL statement.
Copy linkTweet thisAlerts:
@chazzyDec 21.2006 — Based on your code above, this part of the code isn't complete.

[code=php]
$query ="INSERT INTO domains( domain, sex, mail )
values( '$domain',
[/code]
×

Success!

Help @TravisMath 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...