GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 09-Apr-2009, 21:57
Pulaskee Pulaskee is offline
New Member
 
Join Date: Apr 2009
Posts: 17
Pulaskee is on a distinguished road

Where variable


First off im new to Php and Mysql, so forgive me if this question is naive.
I have searched the web for a few days and searched here a bit, though i may have missed something.
I am trying to build a search function in to a DB access page. The search is trying to return all instances that a name is listed in the DB the page is in HTML, here is the user interface code.
PHP Code:

<form name="find" id="find" action="find.php" method="POST" target="maine">
<input type="text" value"name" name="find" id="find"> </input><input type="submit" value="Find"></input>
</form> 



the php code follows.
PHP Code:

<?php
$con = mysql_connect("fakehost","fakeuser","fakepass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("shortage", $con);
/Set the variable

$var1 = $_POST["find"];


$result = mysql_query("SELECT * FROM nine2400 WHERE a ='%s' ORDER BY Time DESC",
$var1,
);

while($row = mysql_fetch_array($result))
  {
  echo "<table>";
  echo "<tr>";
  echo "<td>" . $row['Date'] . "</td>";
  echo "<td>" . $row['a'] . "</td>";
  echo "<td>" . $row['b'] . "</td>";
  echo "<td>" . $row[c'] . "</td>";
  echo "<td>" . $row[d'] . "</td>";

  echo "</tr>";

echo "</table>";
}
mysql_close($con);
?>


any help would be appreciated thanks. -Matthew Pulaskee

ps forgot to tell you the our put im seeing. nothing. not a thing, no errors no text, nothing. i know the DB is populated.
Last edited by LuciWiz : 10-Apr-2009 at 00:37. Reason: Please insert your Php code between [php] & [/php] tags
  #2  
Old 10-Apr-2009, 12:09
MisterChucker's Avatar
MisterChucker MisterChucker is offline
Junior Member
 
Join Date: Mar 2009
Location: Cyberspace, Earth
Posts: 53
MisterChucker is a jewel in the roughMisterChucker is a jewel in the roughMisterChucker is a jewel in the rough

Re: Where variable


Your form and your text input have the same ID (id="find"). IDs should be unique within the entire page.

HTML input tags don't have any inner HTML, so
HTML Code:
<input type="text" value"name" name="find" id="find"> </input>
can be
HTML Code:
<input type="text" value"name" name="find" id="find" />
The comment on line 9,
PHP Code:

/Set the variable 


is missing a slash.
PHP Code:

//Set the variable 


The string indexes on lines 25 and 26,
PHP Code:

echo "<td>" . $row[c'] . "</td>";
echo "<td>" . $row[d'] . "</td>"; 


are missing single quotes.
PHP Code:

echo "<td>" . $row['c'] . "</td>";
echo "<td>" . $row['d'] . "</td>"; 


  #3  
Old 10-Apr-2009, 14:45
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Where variable


Also, don't forget value=
HTML Code:
<input type="text" value="name" name="find" id="find" /> <!-- ^^^ -->
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #4  
Old 10-Apr-2009, 15:59
MisterChucker's Avatar
MisterChucker MisterChucker is offline
Junior Member
 
Join Date: Mar 2009
Location: Cyberspace, Earth
Posts: 53
MisterChucker is a jewel in the roughMisterChucker is a jewel in the roughMisterChucker is a jewel in the rough

Re: Where variable


That too... I don't know how I missed that.
  #5  
Old 10-Apr-2009, 16:16
Pulaskee Pulaskee is offline
New Member
 
Join Date: Apr 2009
Posts: 17
Pulaskee is on a distinguished road

Re: Where variable


The single quotes issue was made when i set up the post here, im not using the actual column names. The names are in proper format though, i am useing the same names in a simpler application.
I cant believe i missed the comment slash. or the value =, i noted last night. lol thank for seeing it.

I am posting the code once again, fixed this time. it still wont work. still blank.

Code:
<form name="search" id="search" action="find.php" method="POST" target="maine"> <input type="text" value="Search By Name" name="find" id="find"></input><input type="submit" value="Find"></input> </form>
Code:
<?php $con = mysql_connect("fakehost","fakeuser","fakepass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("shortage", $con); $var1 = $_POST["find"]; $result = mysql_query("SELECT * FROM nine2400 WHERE Employee ='%s' ORDER BY Time DESC", $var1, ); while($row = mysql_fetch_array($result)) { echo "<table>"; echo "<tr>"; echo "<td>" . $row['a'] . "</td>"; echo "<td>" . $row['b'] . "</td>"; echo "<td>" . $row['c'] . "</td>"; echo "<td>" . $row['d'] . "</td>"; echo "<td>" . $row['e'] . "</td>"; echo "</tr>"; echo "</table>"; } mysql_close($con); ?>
  #6  
Old 10-Apr-2009, 17:02
MisterChucker's Avatar
MisterChucker MisterChucker is offline
Junior Member
 
Join Date: Mar 2009
Location: Cyberspace, Earth
Posts: 53
MisterChucker is a jewel in the roughMisterChucker is a jewel in the roughMisterChucker is a jewel in the rough

Re: Where variable


Run this script and post the output.
  #7  
Old 10-Apr-2009, 17:10
MisterChucker's Avatar
MisterChucker MisterChucker is offline
Junior Member
 
Join Date: Mar 2009
Location: Cyberspace, Earth
Posts: 53
MisterChucker is a jewel in the roughMisterChucker is a jewel in the roughMisterChucker is a jewel in the rough

Re: Where variable


There is a comma biting the foot of $var1 in mysql_query(). It needs to be kicked off.

Edit: No, wait a second. $var1 is where the link identifier should be for mysql_query(). I think you meant
PHP Code:

$result = mysql_query(sprintf("SELECT * FROM nine2400 WHERE Employee ='%s' ORDER BY Time DESC", $var1), $con); 


  #8  
Old 10-Apr-2009, 17:47
Pulaskee Pulaskee is offline
New Member
 
Join Date: Apr 2009
Posts: 17
Pulaskee is on a distinguished road

Re: Where variable


WE HAVE A WINNER! thank you.

So what is sprintf?

I seam to have lost my formatting, but i have to take time to look into that issue myself. Unless this code kills the formatting on purpose.
thanks.
  #9  
Old 10-Apr-2009, 17:54
MisterChucker's Avatar
MisterChucker MisterChucker is offline
Junior Member
 
Join Date: Mar 2009
Location: Cyberspace, Earth
Posts: 53
MisterChucker is a jewel in the roughMisterChucker is a jewel in the roughMisterChucker is a jewel in the rough

Re: Where variable


The function sprintf() returns a formatted string. It is similar to printf() which prints a formatted string. It replaces the %s in your query string with the value of $var1.
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Delegates and references to objects BobLewiston .NET Forum 0 02-Feb-2009 20:18
Life Time of Function static variable? ahbi82 C Programming Language 3 16-Oct-2007 02:24
Global variable goes out of scope. Fermat C++ Forum 1 16-Apr-2007 20:41
[Tutorial] Pointers in C (Part II) Stack Overflow C Programming Language 0 27-Apr-2005 18:36
[Tutorial] Pointers in C (Part I) Stack Overflow C Programming Language 1 08-Apr-2005 19:35

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:07.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.