Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Drop Down HTML form and PHP problem...
Old 03-02-2009, 11:12 PM Drop Down HTML form and PHP problem...
Novice Talker

Posts: 5
Trades: 0
I have a database set up which assigns a school, and its pertinent information, to a specific id for "calling" purposes. However, I am having a little trouble getting this stuff to come together. The error message that I receive when I click the "go" button is that there is an "Unknown column '$id' in 'where clause' " There definitely is the id column in the database, so I thought defining the variable was the problem, but looking around on some sites, my code seems to be ok. This is very frustrating, and I was wondering if someone could possibly chime in with any help that they could. Thanks in advance. My code is below:


HTML Code:
<form id="form" method="get" action="schoolphp.php">
<select name="id" >
<option value="1">School #1</option>
<option value="2">School #2</option>
<input type="submit" value="Go" />
PHP Code:
<?php
//Connect To Database
$hostname='x.x.com';
$username='uname';
$password='pass';
$dbname='dbname';
$usertable=school;


mysql_connect($hostname,$username$password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);
// Retrieve all the data from the "school" table

$id=$_GET['id'];

$result mysql_query('SELECT * FROM school WHERE id=$id')
or die(
mysql_error());  

// store the record of the "school" table into $row
$row mysql_fetch_array$result );
// Print out the contents of the entry 

echo "Name: ".$row['school'];
echo 
" GPA: ".$row['gpa'];

?>
jb265536 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-03-2009, 01:26 AM Re: Drop Down HTML form and PHP problem...
Jaryth000's Avatar
Skilled Talker

Posts: 59
Name: Jaryth
Location: Canada
Trades: 0
Try this:

PHP Code:
 <?php
//Connect To Database
$hostname='x.x.com';
$username='uname';
$password='pass';
$dbname='dbname';
$usertable=school;


mysql_connect($hostname,$username$password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);
// Retrieve all the data from the "school" table

$id=$_GET['id'];

    
$query "SELECT * FROM school WHERE id={$id}";
    
// execute query
    
$result mysql_query($query) or die ("Error in query: $query. ".mysql_error());

// store the record of the "school" table into $row
$row mysql_fetch_array$result );
// Print out the contents of the entry 

echo "Name: ".$row['school'];
echo 
" GPA: ".$row['gpa'];

?>
Two main changes: the important one: the Inline Variable. When you use a PHP defined Variable in a string, you have to put {} around it. The second change being, just pulling the query into its own Variable.
__________________

Please login or register to view this content. Registration is FREE
My personal website
-Jaryth (UID590)
Jaryth000 is offline
Reply With Quote
View Public Profile Visit Jaryth000's homepage!
 
Old 03-04-2009, 07:44 PM Re: Drop Down HTML form and PHP problem...
Experienced Talker

Posts: 33
Trades: 0
You don't need to use {} in php
PHP Code:
$query "SELECT * FROM school WHERE id={$id}"
you can escape the string and use . to join the string and variable $id

PHP Code:
$query "SELECT * FROM school WHERE id=".$id
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
rambo3 is offline
Reply With Quote
View Public Profile
 
Old 03-05-2009, 12:00 AM Re: Drop Down HTML form and PHP problem...
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Actually, you can just do this
PHP Code:
$query "SELECT * FROM school WHERE id=$id"
As long as your using the double quotes ("). If you use single quotes (') the $id variable will not be replaces by it's value, it will simply print $id as in the error message above.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 03-05-2009, 01:32 AM Re: Drop Down HTML form and PHP problem...
Jaryth000's Avatar
Skilled Talker

Posts: 59
Name: Jaryth
Location: Canada
Trades: 0
<_< All 3 should work fine. I just like the {$ver} method, because my editor (PSPad) will color code them... making them easier to find .
__________________

Please login or register to view this content. Registration is FREE
My personal website
-Jaryth (UID590)
Jaryth000 is offline
Reply With Quote
View Public Profile Visit Jaryth000's homepage!
 
Old 03-09-2009, 01:35 AM Re: Drop Down HTML form and PHP problem...
dark_lord's Avatar
Experienced Talker

Posts: 41
Name: Parijat Roy
Location: INDIA-KOLKATA
Trades: 0
Quote:
Originally Posted by lizciz View Post
Actually, you can just do this
PHP Code:
$query "SELECT * FROM school WHERE id=$id"
As long as your using the double quotes ("). If you use single quotes (') the $id variable will not be replaces by it's value, it will simply print $id as in the error message above.
but for varchar u would need single quotes
__________________
I AM THE BEAUTIFUL NIGHTMARE

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
dark_lord is offline
Reply With Quote
View Public Profile Visit dark_lord's homepage!
 
Reply     « Reply to Drop Down HTML form and PHP problem...
 

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.38347 seconds with 12 queries