LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-30-2003, 07:27 PM   #1
lynger
Member
 
Registered: Nov 2003
Posts: 36

Rep: Reputation: 15
syntax


hi forum

I'm now switching from vb to php.. and i'm having problem getting this code to work.. it's suppose to query result from an input but instead, i get a " parse error"..

Pls. see:

<?php
$connection = mysql_connect("localhost", "User", "Password") or die("Error connecting to db");
mysql_select_db("mydb", $connection);
$sql = "select Username, Date from MyTable where Username = '" & $_POST["username"];
$result = mysql_query($sql, $connection) or die("error querying database");

"some code to display result.................."
?>


Pls. help.
 
Old 11-30-2003, 07:42 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Does it by any chance spew out
line numbers along with the error?


Cheers,
Tink
 
Old 11-30-2003, 08:26 PM   #3
lynger
Member
 
Registered: Nov 2003
Posts: 36

Original Poster
Rep: Reputation: 15
hi

yes it does.. line number 15 = to the line:

$sql = "select Username, Date from MyTable where Username = '" & $_POST["username"];


tnx for your time
 
Old 11-30-2003, 08:52 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally posted by lynger
Code:
$sql = "select Username, Date from MyTable where Username = '" &  _POST["username"];
Haven't got that much PHP-experience, but ...

I think that the & bit you in the arse :}

Bloody VB ;) ... all decent languages use
"+" for string concatenation.
/me runs for cover ...

And I'm not sure about that singlequote, either...
And you may need a closing quote behind
_POST["username"] too...

Cheers,
Tink
 
Old 11-30-2003, 09:54 PM   #5
lynger
Member
 
Registered: Nov 2003
Posts: 36

Original Poster
Rep: Reputation: 15
hi

editing the line to this one:
$sql = "select Username, Date from MyTable where Username = $_POST["username"]";

it produced ang error:

Parse error: parse error, unexpected '\"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/myphp.php on line ..

tnx
 
Old 11-30-2003, 10:00 PM   #6
miyake
LQ Newbie
 
Registered: Nov 2003
Location: Socal
Distribution: Slackware, RedHat
Posts: 13

Rep: Reputation: 0
php uses a "." (period) for concatenation.

so try this...

Code:
$sql = "select Username, Date from MyTable where Username = '" . $_POST["username"] . "'";
 
Old 12-02-2003, 01:03 AM   #7
lynger
Member
 
Registered: Nov 2003
Posts: 36

Original Poster
Rep: Reputation: 15
hi all

the code works great.. thank you all

 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
syntax SmithSmith123 Linux - Newbie 2 11-17-2005 04:45 PM
Help with syntax dr3vi1 Linux - Newbie 7 08-09-2005 10:20 AM
Help with lp syntax slick_willie Programming 2 02-03-2005 07:18 PM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM
C syntax help please ... DarkDrive Programming 2 08-07-2003 04:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration