PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP 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:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old March 30th, 2004, 11:47 AM
gizmoh gizmoh is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 gizmoh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation php code for executing any select and insert query

Am trying to have a code that executes any Select and Insert query to any table and echoes the results.Am new to programming so plz excuse my dumb errors
Please test and complete this code for me.
Thanks
PHP Code:
require("../../../forum/admin/config.php"); //connection settings
$db $dbname;  $link mysql_connect$servername$dbusername$dbpassword );
        if ( ! 
$link )            die( "no" );        mysql_select_db$db$link )                
                                        or die ( 
"no" );


$query =$HTTP_POST_VARS['en'];
mysql_query$query$link );
$result = @mysql_query($query);            
while(
$query_datamysql_fetch_array($result) )
{

    echo$ = 
$query_data[0]; //plz anyone complete that part so that any data is outputted



Reply With Quote
  #2  
Old March 30th, 2004, 12:27 PM
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
Your main problem is probably that you're suppressing errors in your call to mysql_query(). That's what the "@" does. Remove that and add a die statement afterward as you've done above. To make your die statement more meaningful, try "die(mysql_error())" to get the actual mysql error. Also, you've got a weird $ after your echo. Dump that. Also, this shouldn't cause an error, but consider using $_POST rather than $HTTP_POST_VARS. It's easier to type in addition to being more up to date.
__________________
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 March 30th, 2004, 12:54 PM
gizmoh gizmoh is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 gizmoh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ok.here is what i come with.But queries passed with single or double quote are not working. the following \ is added before each double quote.Any way to solve that?
PHP Code:
require("../../../forum/admin/config.php"); 
$db $dbname;  $link mysql_connect$servername$dbusername$dbpassword ); 
      if ( ! 
$link )         die( "no" );      mysql_select_db$db$link )             
                              or die ( 
"no" ); 


$query $_POST['en']; 
mysql_query$query$link ); 
$result mysql_query($query) or die(mysql_error());          
while(
$query_datamysql_fetch_assoc($result) ) 

    foreach(
$query_data as $value) echo $value."<br />"


Reply With Quote
  #4  
Old March 30th, 2004, 01:01 PM
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
What error do they come back with? You probably just need to wrap addslashes() around the query to escape quotes.

Incidentally, it's a very bad idea to allow people to post arbitrary queries to be executed. Imagine somebody guesses (correctly) that you've got a table named "users" and they send the query "DELETE FROM users."

Reply With Quote
  #5  
Old March 30th, 2004, 01:27 PM
gizmoh gizmoh is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 gizmoh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I think its the contrary that needs to be done.I am passing a query not the data that needs to be inserted in the DB.
If i use the addslashes function the the query us again modified and added a slash for every quote..
How to preserve the query with its quotes?
Error:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '\"nm\"' at line 1

Reply With Quote
  #6  
Old March 30th, 2004, 01:29 PM
gizmoh gizmoh is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 gizmoh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
LOL
the contrary:
stripslashes()
dhouston thanks for putting me on the path

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > php code for executing any select and insert query


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