|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
Quote:
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. |
|
#4
|
||||
|
||||
|
Repost the modified code. The original code was so syntactically bizarre that I can't confidently troubleshoot without seeing the revision.
|
|
#5
|
||||
|
||||
|
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:
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. |
|
#6
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > PHP MySQL Search |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|