473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Why cannot send just one post comment in PHP?

I am trying to write a PHP project.In this site people can share photos by logining and the photos are displayed in the index.php that is the main page of the program.Now I have three database users images and messages.I can provide users to share their photos by saved the information about the photos, and then get them from the database from images table.Now I want to provide a user to make a comment about a photo in the main page.There are textarea and post button under the images.But when I make a comment for an image it is registered not only related picture id but also for the other picture ids.Why does this happen?

Here is the some part of the php code, I also open and close the database connection in the necessary parts.

Expand|Select|Wrap|Line Numbers
  1.  while($x < mysql_num_rows($result))
  2.         {   
  3.       $picid=mysql_result($result, $x, 'id');
  4.       $name=mysql_result($result, $x, 'imageName');
  5.       $date=mysql_result($result, $x, 'imageDate');
  6.  
  7.         echo "<div><img src = 'upload/$name' height='300 width='300' /></div>";
  8.         echo "Name: $name   Date: $date";
  9.         echo "<br/>";
  10.        ?>
  11.        <p>Post a Comment</p>
  12.  
  13.       <form action="<?= $_SERVER['PHP_SELF']?>" method="POST">
  14.       <textarea name="message" cols="70" rows="6" placeholder="Enter a comment">
  15.  
  16.      </textarea><br/><br/><br/><br/><br/><br/>
  17.       <input type="submit" name="submit" value="Post" style="float:left"><br/><br/>    
  18.       <br/>
  19.       </form>
  20.      <!--<textarea name="message" cols="70" rows="6" ></textarea><br/><br/><br/><br/>   
  21.      <br/><br/>-->
  22.        <?php
  23.  
  24.         extract($_REQUEST);
  25.         if (isset($submit)) {
  26.           $y=0;
  27.           $email=$_SESSION['email'];
  28.            $asdf = mysql_query("SELECT * from users WHERE email='$email'");
  29.            //var_dump(mysql_error());
  30.             while( $y<mysql_num_rows($asdf) )
  31.            { 
  32.             $iduser=mysql_result($asdf,$y,'id');
  33.              $y++;
  34.           }
  35.  
  36.                echo "$iduser";
  37.                $sql ="INSERT INTO messages (id_user, message,picid) VALUES   
  38.                ('$iduser','$message','$picid');";
  39.  
  40.                $rslt = mysql_query($sql);
  41.  
  42.                if ($rslt== false) {
  43.                 echo '<p>Error: cannot execute query</p>';
  44.                }
  45.  
  46.               } ?>
  47.               <?php
  48.  
  49.       $x++;
  50.  
  51.     }
May 23 '13 #1
3 2365
Rabbit
12,516 Expert Mod 8TB
One of the reasons is that your insert is inside your loop that you established on line 1.
May 23 '13 #2
@Rabbit When I try to write out of of the loop it just take the last picid for all forms.
May 24 '13 #3
Rabbit
12,516 Expert Mod 8TB
That's because you're pulling your picid from the loop. You need to use the picid that the user put their comment on.
May 24 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Bob | last post by:
Seem to have a problem ending a session. I get the following message. Warning: session_start(): Cannot send session cookie - headers already sent by (output started at...
13
by: stam | last post by:
hello guys, i have met a problem that i can send the html e-mail by using MIME via php to yahoo mail and hotmail, but when i was try to send to gmail, it show all the html coding. can someone help...
3
by: lawrence k | last post by:
I'm getting this warning: PHP Warning: session_start(): Cannot send session cache limiter - headers already sent in...
19
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache...
1
by: juergen | last post by:
Hi, there are many postings on this subject, I have read them put don't have an answer. I get these warnings: Cannot send session cookie - headers already sent in, but my php-scripts are okay. ...
14
by: bb nicole | last post by:
I using session when creaate a forum. But it display error like: Warning: session_start(): Cannot send session cookie - headers already sent by (output started at...
1
by: =?Utf-8?B?c2VjYWc=?= | last post by:
Lately I cannot send a web page or link in e-mail using "File, Send, Link by e-mail. I get a message that says "the operation failed." HELP!! It's driving me nuts. I have to save it to my...
4
by: three-eight-hotel | last post by:
I'm somewhat of a newbie to PHP coding, but have developed a site using the technology, and have been pleasantly surprised by the capabilities offered. I am more comfortable in the ASP world,...
4
by: arashi | last post by:
I get this msg: Warning: session_start() : Cannot send session cache limiter - headers already sent (output started at /web/www/frac/users/s/students/katalog/brukere/login.php:2) in...
11
by: craigtomo | last post by:
i have changed my login .php file to the following this file is opened directly and is not called from any other file <?php // dBase file $host=""; // Host name $username=""; // Mysql...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.