Jump to content

SQL newbie help


hoponhiggo

Recommended Posts

ok, so thats worked.

 

But im not getting an error when trying to post a message:

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/chiggo12/public_html/test/insertarNoticia.php:3) in /home/chiggo12/public_html/test/insertarNoticia.php on line 7

 

any ideas?

Link to comment
Share on other sites

Muddy

 

I have had a number of problems trying to get the code you kindly provided to work, but i have manged to take bits of it and mix it with bits i already had to get things to a stage which is further on from my original post!

 

I now have a message posting system which displays the message on my homepage and posts a message id, message text and userid to my database which i believe is ideal.

 

I am still having the original problem tho of displaying only the profile pic of the user who posted the message.

 

The code to display the message and send the data to the database is now:

 

<?php

//initialize the session
if (!isset($_SESSION)) {
  session_start();
}
include("db.php");
// if content has been sent
if(isset($_POST["textarea_noticia"])){
	$msg = $_POST["textarea_noticia"];
	$username = $_SESSION['MM_Username'];
	$userid = $_SESSION['MM_userid'];
	// Insert information
	$sql = mysql_query("INSERT INTO messages(message,username,id_fk)values('$msg','$username','$userid')");
	$result = mysql_query("SELECT * FROM messages order by msg_id desc");
	$row = mysql_fetch_assoc($result);
	$id = $row["msg_id"];
	$msg = $row["message"];
}
?>

 

The following code is used to display the profile pic of the user that is logged in

 

<?php
//to display image from source
$dir = "profpics";

$sql = "SELECT prof_pic FROM users WHERE username = '{$_SESSION['MM_Username']}'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0) die("Username not found in database.");

$row = mysql_fetch_array($res);
echo "<img src='$dir/{$row['prof_pic']}' width='38' height='38'><br>";
?>

 

Can this, inparticular the

 

 "SELECT prof_pic FROM users WHERE username = '{$_SESSION['MM_Username']}'"

 

just be changed from who is logged in, to who posted the message??

 

Im sorry if this has gone in a massive circle!!

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.