Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 09-02-2005, 07:32 PM   #1 (permalink)
Odoggy5
Registered User
 
Odoggy5's Avatar
 
Join Date: Aug 2003
Location: SF
Posts: 45
Odoggy5 is on a distinguished road
Send a message via AIM to Odoggy5
ok im going crazy

I know I'm missing something small, somebody help please!

Code:
<?
$field=$_GET['field'];
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query='SELECT * FROM `memfiles` WHERE `field` = \'$field\' '; 
$result=mysql_query($query);
$num=mysql_numrows($result); 
mysql_close();

$i=0;
while ($i < $num) {
$field=mysql_result($result,$i,"field");
$definition=mysql_result($result,$i,"definition");
$file=mysql_result($result,$i,"file");
?>

<form action="updated.php">
<input type="hidden" name="ud_field" value="<? echo "$field"; ?>">
Definition: <input type="text" name="ud_definition" value="<? echo "$definition"?>"><br>
File: <input type="text" name="ud_file" value="<? echo "$file"?>"><br>
<input type="Submit" value="Update">
</form>

<?
++$i;
} 
?>
The URL I am sending is "//hostname/update.php?field=cnfg10", I keep coming up with a blank webpage and I have data for "cnfg10" in my db.

I'm thinking to do what I am doing here I have to use a field type of INT? In my MySQL DB? I don't know just a shot in the dark I guess?
Odoggy5 is offline   Reply With Quote
Old 09-02-2005, 09:59 PM   #2 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
Shouldn't this line
PHP Code:
$query='SELECT * FROM `memfiles` WHERE `field` = \'$field\' '
look like this instead
PHP Code:
$query=sprintf("SELECT * FROM `memfiles` WHERE `field` = '%s'"$field); 
The main thing is $field won't get interpolated into a single quoted string, use sprintf or double quotes.
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Old 09-02-2005, 11:04 PM   #3 (permalink)
Odoggy5
Registered User
 
Odoggy5's Avatar
 
Join Date: Aug 2003
Location: SF
Posts: 45
Odoggy5 is on a distinguished road
Send a message via AIM to Odoggy5
cool, that totally worked. I just looked that sprintf up, very cool. So basically I represented my field "$field", with %s a string. Thank you much!

Last edited by Odoggy5; 09-02-2005 at 11:27 PM.
Odoggy5 is offline   Reply With Quote
Old 09-03-2005, 12:02 AM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,694
redhead is on a distinguished road
Or perhaps simply just:
PHP Code:
$query="SELECT * FROM `memfiles` WHERE `field` = \'$field\' "
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 09-03-2005, 09:11 AM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
i guess it's all the same thing, but the original code just had single quotes inside single quotes which seemed to be the problem, so you could really just use double quotes like in red's last example and shouldn't have to escape the single quotes after that.

backticks arouind table names is proper i believe, but i haven't found that they are necessary unless you have a table name with spaces ( i think )

i'm too lazy to check, but if you escape single quotes when they don't need to be escaped, will that generate an error?

most of my queries are formatted in this style:

PHP Code:
 $query="SELECT * FROM memfiles WHERE field = '{$field}' "
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assignment I have, it's crazy for little 'ol me...help? cleverest Standard C, C++ 13 04-03-2005 01:41 AM
Crazy PC Mods sde Code Newbie News 1 01-05-2005 07:18 AM
crazy stuff. Admin Lounge 3 09-08-2003 08:26 AM
My first post, I need help Zenogear11 Standard C, C++ 14 03-20-2003 11:01 AM
Help!!! Cron Job Gone Crazy!!! sde Linux / BSD / OS X 3 05-23-2002 06:46 PM


All times are GMT -8. The time now is 04:57 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting