Linode Forum Index Linode Forum
Linode Community Forums
 


Script issue

Click here to go to the original topic

 
       Linode Forum Index -> General Discussion
Author Message
webc0der



Joined: 13 Jun 2007
Posts: 13
Location: Florida

Posted: Mon Sep 14, 2009 11:48 am    Post subject: Script issue  

Hey guys,

Hoping someone can help me out. On my linode I have mysql, php & apache, and im trying to write a script to pull info from my database, but I keep getting this error:

Quote: PHP Parse error: syntax error, unexpected T_LOGICAL_OR in /var/www/vhosts/xxx.net/httpdocs/Tim/dbconnect.php on line 24, referer: http://xxx.net/Tim/Registration.htm

Heres the script:
Code: <?php
//set database connection variables
$host='localhost';
$dbuser='xxx';
$dbpass='xxx';
$dbname='xxx';

$connection = mysql_connect($host, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

require('dbconnect.php');
if($_POST['submit']) {
$firstname = $_POST['firstname'];
$middlename = $_POST['middlename'];
$lastname = $_POST['lastname'];
$sex = $_POST($sex);
$emailaddress = $_POST['emailaddress'];
if((empty($firstname)) OR (empty($middlename)) OR (empty($lastname)) OR (empty($sex)) OR (empty($sex)))
{
echo "Please fill in all fields!";
}
if (empty($you)) OR (empty($others));
{
echo "Please agree to both terms or you cannot be a member! (All members are bound by these terms and if they violate them their membership will be revoked.)";
}
else {
$query = "INSERT INTO ifdbt0 (memberid, firstname, middlename, lastname, sex, emailaddress) VALUES ('', '$firstname', '$middlename', '$lastname', '$sex', '$emailaddress;)";
mysql_query($query) or die(mysql_error());
echo "Thank you for your registration $firstname $middlename $lastname! You are now an official member of the Inspiration Foundation.";
}
mysql_close($connection);
?>

But I cant figure out the prob :/ Can anyone help?

Kind Regards,
Justin

____
Edit by Jed Smith: Removed database credentials.
Back to top  
NeonNero



Joined: 04 Jan 2005
Posts: 214
Location: Ålesund, Norway

Posted: Mon Sep 14, 2009 12:16 pm    Post subject:  

I think you might have to take a closer look at the file dbconnect.php, around, say, line 24 (or thereabouts). You probably have a missing paranthesis or something on that line or the previous one.
Back to top  
hybinet



Joined: 02 May 2008
Posts: 1058

Posted: Mon Sep 14, 2009 12:29 pm    Post subject:  

Code: if (empty($you)) OR (empty($others));
should be
Code: if ((empty($you)) OR (empty($others)))
Back to top  
mjrich



Joined: 16 Jun 2008
Posts: 151

Posted: Mon Sep 14, 2009 3:07 pm    Post subject:  

Code: $firstname = $_POST['firstname'];
$middlename = $_POST['middlename'];
$lastname = $_POST['lastname'];
$sex = $_POST($sex);
$emailaddress = $_POST['emailaddress'];
.
.
$query = "INSERT INTO ifdbt0 (memberid, firstname, middlename, lastname, sex, emailaddress) VALUES ('', '$firstname', '$middlename', '$lastname',
I hope you're going to do some sanity checks on these first...
Back to top  
JshWright



Joined: 27 Oct 2008
Posts: 173

Posted: Mon Sep 14, 2009 3:33 pm    Post subject:  

Like mjrich said, you're asking for trouble if you don't check your inputs before you feed them to the database.

Also, that second to last semicolon in your insert statement should be a single quote.


~JW
Back to top  
Guspaz



Joined: 26 May 2009
Posts: 1147
Location: Montreal, QC

Posted: Mon Sep 14, 2009 4:11 pm    Post subject:  

Also, it's generally a bad idea to post your database hostname, username and password in public.
Back to top  
sweh



Joined: 13 Apr 2004
Posts: 565

Posted: Mon Sep 14, 2009 5:49 pm    Post subject: Re: Script issue  

webc0der wrote:
$query = "INSERT INTO ifdbt0 (memberid, firstname, middlename, lastname, sex, emailaddress) VALUES ('', '$firstname', '$middlename', '$lastname', '$sex', '$emailaddress;)";

Missing ' after $emailaddress (appears to have been replaced with a ; )
Back to top  
BarkerJr



Joined: 02 Aug 2009
Posts: 220
Location: Connecticut, USA

Posted: Mon Sep 14, 2009 5:51 pm    Post subject:  

Yeah, it's much better to not use database passwords and use IP-based authentication instead.
Back to top  
Guspaz



Joined: 26 May 2009
Posts: 1147
Location: Montreal, QC

Posted: Tue Sep 15, 2009 9:53 am    Post subject:  

BarkerJr wrote: Yeah, it's much better to not use database passwords and use IP-based authentication instead.

Woah, no way. IPs can be spoofed, although you'll have trouble getting return traffic unless you're on a LAN. Except Linodes are.

If you want to go the IP-auth route, use it in combination with a password; MySQL makes that easy, especially if you use phpMyAdmin to set it up (it's a dropdown on the create account page).
Back to top  
BarkerJr



Joined: 02 Aug 2009
Posts: 220
Location: Connecticut, USA

Posted: Tue Sep 15, 2009 8:47 pm    Post subject:  

I'm pretty sure that you cannot hijack IPs in the Linode networks.
Back to top  
Stever



Joined: 07 Dec 2007
Posts: 337
Location: NC, USA

Posted: Tue Sep 15, 2009 11:56 pm    Post subject: Re: Script issue  

webc0der wrote: Code: $host='localhost';
Good luck trying to spoof that one from anywhere ;)
Back to top  
Guspaz



Joined: 26 May 2009
Posts: 1147
Location: Montreal, QC

Posted: Wed Sep 16, 2009 9:30 am    Post subject: Re: Script issue  

Stever wrote: webc0der wrote: Code: $host='localhost';
Good luck trying to spoof that one from anywhere ;)

You didn't pay enough attention to his post:

Quote: PHP Parse error: syntax error, unexpected T_LOGICAL_OR in /var/www/vhosts/xxx.net/httpdocs/Tim/dbconnect.php on line 24, referer: http://xxx.net/Tim/Registration.htm

Notice the hostname there :P
Back to top  
tronic



Joined: 04 Dec 2004
Posts: 145

Posted: Sun Sep 27, 2009 3:24 am    Post subject: Re: Script issue  

Guspaz wrote: Stever wrote: webc0der wrote: Code: $host='localhost';
Good luck trying to spoof that one from anywhere ;)

You didn't pay enough attention to his post:

Quote: PHP Parse error: syntax error, unexpected T_LOGICAL_OR in /var/www/vhosts/xxx.net/httpdocs/Tim/dbconnect.php on line 24, referer: http://xxx.net/Tim/Registration.htm

Notice the hostname there :P

True 'nuff but look at the directory pathname -- possible he had /etc/hosts entry like: 127.0.0.1 xxx.net localhost
Back to top  
 
       Linode Forum Index -> General Discussion
Page 1 of 1