MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 3rd, 2004, 05:56 AM
NetDog NetDog is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 NetDog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy PHP MySQL Search

I am attempting to learn php and mysql, I have built a database and now I would like to be able to pull information stored based on the users SID that I entered into the database when creating the user information.

My Tables are as follows with information posted.

SID: 12345
First Name: Phil
Last Name: Collins
Term: 2 Sem
Grade: 80

I need to build a web form that when submitted will post the above information. I would like to make the search based on SID so that the person only needs to submit there SID in order to receive the information stored. The following code is what I have been working with but it is not working at all and I keep getting parsing errors.

<?php
//Handler.php
$sid= $_POST['name'];
$conn= mysql_connect("localhost","root","blahblah");
mysql_select_db("grade");
$do= mysql_query("select * from info where name like '%$sid%'");
while($row = mysql_fetch_array($do)) {or die(mysql_error());
print"$row[0],$row[1]";
}
mysql_close($conn);
?>

and the form

<HTML>
<?php
//Search.php
?>
<form action=handler.php method=get>SID: <input type=text sid=sid size=30><br>
<input type=submit name=sub value='search'>
</form>
</HTML>

Here is the error I get
Parse error: parse error in handler.php on line 7

Reply With Quote
  #2  
Old February 3rd, 2004, 06:57 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Start by putting your die statement after your mysql_query statement (before the semicolon).
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #3  
Old February 3rd, 2004, 03:47 PM
NetDog NetDog is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 NetDog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by dhouston
Start by putting your die statement after your mysql_query statement (before the semicolon).


I have done this still I get the same message, but it says line 9. I do not understand what is wroung with my code. Is there any code out there that will do this function that I can use to follow along with to building my own.

Reply With Quote
  #4  
Old February 4th, 2004, 06:51 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Repost the modified code. The original code was so syntactically bizarre that I can't confidently troubleshoot without seeing the revision.

Reply With Quote
  #5  
Old February 4th, 2004, 06:53 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
But first check the "print" line. Did the forums delete a space between "print" and the quotation mark or does that actually exist in your code? If it's there, add a space and see if that helps. Also consider changing the line to:

PHP Code:
print $row[0] . "," $row[1]; 


Printing arrays within quotes can be problematic, I believe, if you don't do it just right. I'm a big fan of the dot operator.

Reply With Quote
  #6  
Old February 13th, 2004, 10:30 AM
skylar skylar is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 1 skylar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Instead of doing this:

<?php
//Handler.php
$sid= $_POST['name'];
$conn= mysql_connect("localhost","root","blahblah");
mysql_select_db("grade");
$do= mysql_query("select * from info where name like '%$sid%'");
while($row = mysql_fetch_array($do)) {or die(mysql_error());
print"$row[0],$row[1]";
}
mysql_close($conn);
?>

do this:
<?php
//Handler.php
$sid= $_POST['name'];
$conn= mysql_connect("localhost","root","blahblah");
mysql_select_db("grade");
$do= mysql_query("select * from info where name like '%$sid%'");
if(!mysql_num_rows($do)){
echo mysql_error();
exit;
}
while($row = mysql_fetch_array($do)) {
print"$row[0],$row[1]";
}
mysql_close($conn);
?>


if there is more than zero rows everything should be okay, if no rows are returned you can do some more standard error reporting that could take up more than one line. Such as errorReport() that can tell the user that ur database is currently 'broken' or even better, "No results were found for that query" or something like that.

i haven't used the die statement in all my php experience (which is quite a bit). It's confusing and annoying.. I would much rather give my users a detailed explanation and log the error silently than give them gibberish that they could never understand.


btw,
you aren't required to close your mysql connection as far as i know.. unless you want to open up knew connections or to clear up some free space in humungous scripts. I always omit mine because it closes automatically when the script is finished anyways.

/sky

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > PHP MySQL Search


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway