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
error in executing mysql query
Old 03-14-2009, 12:09 PM error in executing mysql query
Skilled Talker

Posts: 54
Trades: 0
the query below is not executing and i can not figure out the reason.please help.this is my first time of developing a web page. [php] Untitled Document
kani alavi is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-14-2009, 01:28 PM Re: error in executing mysql query
Skilled Talker

Posts: 54
Trades: 0
i'm i could not upload the code.i try uploading the code by pasting it in the new thread textarea and enclosing it between the tags: , to my surprise it did not work . it is the reason why the tag [php] untitled Document is attached to the post.if any one can help me post the code it will be appreciated. any help is welcome. thank you.
kani alavi is offline
Reply With Quote
View Public Profile
 
Old 03-14-2009, 03:53 PM Re: error in executing mysql query
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
You post php code with

[ php]
All your code here
[ /php]

without the spaces.
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 03-15-2009, 04:30 AM Re: error in executing mysql query
dark_lord's Avatar
Experienced Talker

Posts: 41
Name: Parijat Roy
Location: INDIA-KOLKATA
Trades: 0
Quote:
Originally Posted by kani alavi View Post
i'm i could not upload the code.i try uploading the code by pasting it in the new thread textarea and enclosing it between the tags: , to my surprise it did not work . it is the reason why the tag [php] untitled Document is attached to the post.if any one can help me post the code it will be appreciated. any help is welcome. thank you.

your [php] Untitled Document is not working (and it is not an attachment) probably you need to post as said in above post to make us understand about your code.
__________________
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!
 
Old 03-15-2009, 07:49 AM Re: error in executing mysql query
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
I think you will find this is a PLBKAC based problem.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 03-17-2009, 04:12 AM Re: error in executing mysql query
Skilled Talker

Posts: 54
Trades: 0
this is the code which is not executing.it produces the message:"post could not be added to forum".
PHP Code:
mysql_select_db($database_sql1$sql1);
if(isset(
$_POST['addpost']))
{
  if(!empty(
$_POST["posts"])){
   foreach(
$_POST["posts"] as $postid){
   
$postid=mysql_real_escape_string($postid);
 
$confirmpost="UPDATE forum_post SET confirm='yes' WHERE post_id={$postid}";
 
$rs_confirmpost=mysql_query($confirmpost,$sql1) or die("post could not be added to forum");
 }
 }

thanks for any help.
kani alavi is offline
Reply With Quote
View Public Profile
 
Old 03-17-2009, 04:54 AM Re: error in executing mysql query
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
remove the brackets in the WHERE clause
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-18-2009, 07:41 AM Re: error in executing mysql query
dark_lord's Avatar
Experienced Talker

Posts: 41
Name: Parijat Roy
Location: INDIA-KOLKATA
Trades: 0
@kani alavi your code is absolutely ok, maybe you should check your run time queries, what value you are passing through post_id etc.

And also check the database connection if it's really working or not.
__________________
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!
 
Old 03-19-2009, 06:25 AM Re: error in executing mysql query
Skilled Talker

Posts: 54
Trades: 0
thanks for all the helps you have given so far. i remove the curly brackets in the where clause and error still exist. this is the code again and the form whose data is to be stored in the database. any help is appreciated
PHP Code:
<?php require_once('../Connections/sql1.php'); ?>
<?phpmysql_select_db
($database_sql1$sql1);
$query_rs_uncertpost "SELECT topic_id, post_owner, post_description FROM forum_post WHERE confirm='no'";
$query_limit_rs_uncertpost sprintf("%s LIMIT %d, %d"$query_rs_uncertpost$startRow_rs_uncertpost$maxRows_rs_uncertpost);
$rs_uncertpost mysql_query($query_limit_rs_uncertpost$sql1) or die(mysql_error());
$row_rs_uncertpost =mysql_fetch_assoc($rs_uncertpost);mysql_select_db($database_sql1$sql1);
if(isset(
$_POST['addpost']))
{
  if(!empty(
$_POST["posts"])){
   foreach(
$_POST["posts"] as $postid){
   
$postid=mysql_real_escape_string($postid);
 
$confirmpost="UPDATE forum_post SET confirm='yes' WHERE post_id=$postid";
 
$rs_confirmpost=mysql_query($confirmpost,$sql1) or die(mysql_error());
 }
 }
}
if(isset(
$_POST['delpost']))
{
  if(!empty(
$_POST["posts"])){
   foreach(
$_POST["posts"] as $postid){
    
$deletepost="DELETE FROM forum_post WHERE post_id={$postid}";
    
$rs_deletepost=mysql_query($deletepost,$sql1) or die("could not remove post from forum");
   }
  
  }
}
?>
<body>
<form action="manageuncertpost.php" method="post">
<table border="1">
  <tr>
    <td>topic_id</td>
    <td>post_owner</td>
    <td>post_description</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><input name="posts[]" type="checkbox" multiple="multiple" value="<?php echo $row_rs_uncertpost['post_id'];?>" /></td>
      <td><input name="owner" type="text" value="<?php echo $row_rs_uncertpost['post_owner']; ?>" readonly="true" /></td>
      <td><textarea name="postdesc" type="text" value="<?php echo $row_rs_uncertpost['post_description']; ?>" cols="40" rows="10"><?php echo $row_rs_uncertpost['post_description']; ?></textarea></td>
    </tr>
    <?php } while ($row_rs_uncertpost mysql_fetch_assoc($rs_uncertpost)); ?>
</table>
<input name="addpost" type="submit" value="add to post" />
<input name="delpost" type="submit" value="delete" />
</form>
</body>
</html>

Last edited by kani alavi; 03-19-2009 at 06:27 AM..
kani alavi is offline
Reply With Quote
View Public Profile
 
Old 03-19-2009, 10:05 AM Re: error in executing mysql query
Skilled Talker

Posts: 84
Trades: 0
I would say you just echo the query and understand what its querying..


try some thing like

echo $confirmpost;

__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
- 1-888-869-HOST(4678)
Award winning Managed Hosting -
Please login or register to view this content. Registration is FREE

Managed Dedicated Servers. Reseller Discounts. 24/7 Impressive Tech Support
HivelocityDD is offline
Reply With Quote
View Public Profile
 
Old 03-20-2009, 01:02 AM Re: error in executing mysql query
dark_lord's Avatar
Experienced Talker

Posts: 41
Name: Parijat Roy
Location: INDIA-KOLKATA
Trades: 0
yes the variable $confirmpost will yield 1 if the query executes successfully else it'll die!
__________________
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!
 
Old 03-21-2009, 03:57 AM Re: error in executing mysql query
Skilled Talker

Posts: 54
Trades: 0
i am doubting whether the way i used the foreach function might be the cause since the $postid is initialised there. could it be the cause? else what other information do i need to provide in order for someone to be able figure out where things are getting wrong.or is there any other way i can fix it. please help i am comfuse
kani alavi is offline
Reply With Quote
View Public Profile
 
Old 03-21-2009, 08:37 AM Re: error in executing mysql query
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
If your post_id field is filled with integers, this might help you a bit:

PHP Code:
<?php 
require_once('../Connections/sql1.php');
$error_message '';
if (
$selected_db mysql_select_db($database_sql1$sql1)) {
  if (isset(
$_POST['addpost']) && !empty($_POST['posts'])) {
    
$confirmed_posts ''$confirmed_posts_prefix '';
    foreach(
$_POST['posts'] as $postid){
      
$confirmed_posts .= $confirmed_posts_prefix.((int)$postid);
      
$confirmed_posts_prefix ',';
    }
    if (
strlen($confirmed_posts) > 0) {
      
$confirmpost "UPDATE forum_post SET confirm='yes' WHERE confirm='no' AND post_id IN (".$confirmed_posts.")";
      
$rs_confirmpost mysql_query($confirmpost$sql1);
      if ((
$errno mysql_errno()) > 0) {
        
$error_message '['.__line__.'] DATABASE UPDATE FAILED.  MySQL reported &quot;['.$errno.']'.mysql_error().'&quot;<br />';
      }
    }
  }
  if (isset(
$_POST['delpost']) && !empty($_POST['posts'])) {
    
$deletable_posts ''$deletable_posts_prefix '';
    foreach(
$_POST['posts'] as $postid){
      
$deletable_posts .= $deletable_posts_prefix.((int)$postid);
      
$deletable_posts_prefix ',';
    }
    if (
strlen($deletable_posts) > 0) {
      
$deletepost "DELETE FROM forum_post WHERE post_id IN (".$postid.")";
      
$rs_deletepost mysql_query($deletepost$sql1);
      if ((
$errno mysql_errno()) > 0) {
        
$error_message '['.__line__.'] DATABASE DELETION FAILED.  MySQL reported &quot;['.$errno.']'.mysql_error().'&quot;<br />';
      }
    }
  }
} else {
  
$error_message '['.__line__.'] DATABASE SELECTION FAILED.  MySQL reported &quot;'.mysql_error().'&quot;<br />';
}
?>
<html>
<body>
<form action="manageuncertpost.php" method="post">
<table border="1">
<tr>
<td>topic_id</td>
<td>post_owner</td>
<td>post_description</td>
</tr>
<?php
$query_rs_uncertpost 
"SELECT topic_id, post_owner, post_description FROM forum_post WHERE confirm='no' LIMIT ".$startRow_rs_uncertpost.", ".$maxRows_rs_uncertpost;
if (
$query_results mysql_query($query_rs_uncertpost$sql1)) {
  if (
mysql_num_rows($query_results) > 0) {
    while (
$row_rs_uncertpost mysql_fetch_assoc($query_results)) {
?>
<tr>
<td><input name="posts[]" type="checkbox" value="<?php echo $row_rs_uncertpost['post_id'];?>" /></td>
<td><?php echo htmlspecialchars($row_rs_uncertpost['post_owner']);?></td>
<td><textarea cols="40" rows="10"><?php echo htmlspecialchars($row_rs_uncertpost['post_description']); ?></textarea></td>
</tr>
<?php 
    
}
  }
}
?>
</table>
<input name="addpost" type="submit" value="add to post" />
<input name="delpost" type="submit" value="delete" />
</form>
</body>
</html>
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 03-21-2009, 12:57 PM Re: error in executing mysql query
Average Talker

Posts: 22
Name: adoc fish
Trades: 0
As your SQL looks ok. I assume you have tested the SQL with a tool like myPHPAdmin to make sure it's correct?

If so, that leaves the value of post_id. Focus on the values in the POST. I assume you're expecting integers. Check to see what is really being passed.

Add some bullet proofing in your code to make sure that only valid integers are being converted into SQL statements.

You could also add some logging to make it easier to debug.
_coda_ is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to error in executing mysql query
 

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.44612 seconds with 12 queries