Page 1 of 1

Insert name into Owner column - Pls help!

Posted: Wed Jul 18, 2012 8:02 am
by Ghoz
Hi, I want to insert the name instead of username into the Owner column. I'm not familiar with php. Please help. Thanks.

Code: Select all

<?php 
$visitingfiledirectly = false;
if($visitingfiledirectly)
{
	?>
    <link rel="stylesheet" type="text/css" media="screen" href="../stylus.css">
    <?php
}
?>
<?php 
if(isset($_SESSION["username"]) && isset($_SESSION["password"]))
{
// SET UP BASIC VALUES
$tlimit = 50;
$slimit = 120;
$dlimit = 7000;
$tvalid = TRUE;
$svalid = TRUE;
$dvalid = TRUE;
$printform = TRUE;
$title = "";
$short = "";
$description = "";

// IF SUBMITTED
if(isset($_POST["submitprayer"]) && !empty($_POST["title"]) && !empty($_POST["short"]) && !empty($_POST["description"]))
{
	$title = getMultiLineText($_POST["title"],50);
	$short = getMultiLineText($_POST["short"],50);
	$description = getMultiLineText($_POST["description"],50);
	
	if(strlen($title) > $tlimit)
	{
		$tvalid = FALSE;
	}
	if(strlen($short) > $slimit)
	{
		$svalid = FALSE;
	}
	if(strlen($description) > $dlimit)
	{
		$dvalid = FALSE;
	}
	if($tvalid && $svalid && $dvalid)
	{
		$printform = FALSE;
		$r = mysql_query("SHOW TABLE STATUS LIKE 'prayers'");
		$row = mysql_fetch_array($r);
		$prayerid = $row['Auto_increment'];
		mysql_free_result($r);
		
		$query = 'INSERT INTO prayers (Owner, Title, Short, Description, Date)
        VALUES (\''.$_SESSION["username"].'\',\''.$title.'\',\''.$short.'\',\''.$description.'\',\''.date("Y-m-d|h:i:s").'\')';
		mysql_query($query) or die(mysql_error());
		?>
<div class="success">successfully submitted.</div>
<br><br>
		<a href="index.php?section=readprayer&id=<?php echo $prayerid;?>">Click here following link if you aren't successfully redirected.</a><br>
		<meta HTTP-EQUIV="REFRESH" content="3; url=index.php?section=readprayer&id=<?php echo $prayerid;?>"><?php
	}
}
else if(isset($_POST["submitprayer"]))
{
	?><div class="warning">There is an empty field!</div><?php
	$title = $_POST["title"];
	$short = $_POST["short"];
	$description = $_POST["description"];
}
if(!$tvalid || !$svalid || !$dvalid)
{
	
	?><div class="warning"><?php
	if(!$tvalid)
	{
		$length = strlen($title);
		?>Maximum title length is <?php echo $tlimit;?>. Limit has been exceed by <?php echo ($length-$tlimit);?> characters.<br><?php
	}
	if(!$svalid)
	{
		$length = strlen($short);
		?>Maximum short description length is <?php echo $slimit;?>. Limit has been exceed by <?php echo ($length-$slimit);?> characters.<br><?php
	}
	if(!$dvalid)
	{
		$length = strlen($description);
		?>Maximum description length is <?php echo $dlimit;?>. Limit has been exceed by <?php echo ($length-$dlimit);?> characters.<br><?php
	}
	?></div><?php
	$title = getNormalText($title);
	$short = getNormalText($short);
	$description = getNormalText($description);
}
if($printform) // IF STILL HAVE TO PRINT IT
{
?>
<h1>Submit</h1>
Submit here.
<form method="POST">
<br>Title:<br />
<input type="text" name="title" size="50" <?php echo'value="'.$title.'"';?>/><br />
Short Description:<br />
<textarea name="short" rows="3" cols="50"><?php echo$short;?></textarea><br />
Description:<br />
<textarea name="description" rows="3" cols="50"><?php echo$description;?></textarea><br />
<input type="hidden" name="submitprayer" value="Yes">
<input type="submit" value="Submit">
</form>
<?php 
}
}
else
{
	?><div class="warning">You need to be logged in!</div><?php
}
?>

Re: Insert name into Owner column - Pls help!

Posted: Wed Jul 18, 2012 8:09 am
by social_experiment

Code: Select all

<?php
$query = 'INSERT INTO prayers (Owner, Title, Short, Description, Date)
VALUES (\''.$_SESSION["username"].'\',\''.$title.'\',\''.$short.'\',\''.$description.'\',\''.date("Y-m-d|h:i:s").'\')';
?>
You have to change $_SESSION["username"] to the value containing the data you wish to insert.

:idea: Use the PHP Code button to wrap any php code in. It's a lot easier to read = quicker answers;

Re: Insert name into Owner column - Pls help!

Posted: Wed Jul 18, 2012 8:33 am
by Ghoz
Wow super fast reply!!! I'm not sure what is the value containing the data.
Anyway the script below is taken from another php file which is able to display the name instead of username. Thanks!

<?php
// This will allow to use the css inside includes if editing this file directly... probably
$visitingfiledirectly = false;
if($visitingfiledirectly)
{
?>
<link rel="stylesheet" type="text/css" media="screen" href="../stylus.css">
<?php
}

?>
<b>Search Result</b><br />
<div class="searchlist">
<?php
$uname = "";
if(isset($_POST["u"]) && !empty($_POST["u"]) && strlen($_POST["u"]) > 0)
{
$uname = PHP_slashes($_POST["u"]);
}
$result2 = mysql_query("SELECT Avatar, Name, Username, LastLoginDate, Email FROM users where Name Like '%".$uname."%'");
//where Name Like (search for 'Name')

if(mysql_num_rows($result2) > 0)
{
?>
<table border = "1" width="100%">
<tr>
<td></td>
<td><b><p align="center">Name</b></td>
<?php
if($admin >= 1)
{
?>
<td><b><p align="center"><p align="center">Email Address</b></td>
<?php
}
?>
<td><b><p align="center">Last Login</b></td>
</tr>
<?php

while ($row2 = mysql_fetch_row($result2)){
?>
<tr>
<td><p align="center"><?php useLightbox($row2[0],$row2[1],50,50);?></td>
<td><p align="center"><a href="index.php?section=profile&uid=<?php echo getUserId($row2[2]);?>"><b><?php echo $row2[1];?></b></a></td>
<?php
if($admin >= 1)
{
?><td><p align="center"><?php echo $row2[4];?></td><?php
}
?><td><p align="center"><?php echo referencialHour($row2[3]);?></td>
</tr><?php
}

?>
</table>
</div>
<?php
}
else
{
?>
<font color="#FF0000">No user found!</b></font>
<?php
}

?>

Re: Insert name into Owner column - Pls help!

Posted: Wed Jul 18, 2012 9:05 am
by social_experiment
Ghoz wrote:Anyway the script below is taken from another php file which is able to display the name instead of username
The "name" in this instance, where does it come from? The database or is it user input?

Re: Insert name into Owner column - Pls help!

Posted: Wed Jul 18, 2012 9:22 am
by Ghoz
Hi, from the database. In the first script given, when the user login and send a post, the username will be collected and insert into the 'Owner' column. I want to insert the name instead of the username, but do not know how to get the name.

Re: Insert name into Owner column - Pls help!

Posted: Wed Jul 18, 2012 12:55 pm
by califdon
Ghoz wrote:Hi, from the database. In the first script given, when the user login and send a post, the username will be collected and insert into the 'Owner' column. I want to insert the name instead of the username, but do not know how to get the name.
We understand that you are not experienced with PHP scripting, but (1) most people won't even try to read code posted like that (without using the "PHP Code" button when you enter your post); and (2) it's a little like asking an auto mechanic to tell you how to install a new transmission in a car. There are months and months of learning that you need to do before you can even ask the right questions, much less understand the answers.

The point is, if you have the name stored in the database, you must retrieve it with a query, then you will be able to display it.

Re: Insert name into Owner column - Pls help!

Posted: Wed Jul 18, 2012 8:52 pm
by Ghoz
Hi,
How to retrieve the name base on the given script?
Thanks!

Re: Insert name into Owner column - Pls help!

Posted: Wed Jul 18, 2012 9:41 pm
by califdon
Ghoz wrote:Hi,
How to retrieve the name base on the given script?
Thanks!
The same way you retrieve any other data from a database. You need to learn basic database operations in PHP. There must be hundreds of tutorials online on this subject. I would recommend some of these:
http://www.homeandlearn.co.uk/php/php.html
http://www.freewebmasterhelp.com/tutorials/phpmysql/
http://www.tizag.com/mysqlTutorial/mysqldatabase.php
http://www.keithjbrown.co.uk/vworks/php/

Re: Insert name into Owner column - Pls help!

Posted: Sat Jul 21, 2012 1:15 am
by Ghoz
Topic closed

Re: Insert name into Owner column - Pls help!

Posted: Sat Jul 21, 2012 3:46 am
by social_experiment
@Ghoz An alternative to saying the topic is closed is to modify the subject line of the first post by adding [Solved] or something similar to the end of the line; that way users can see that the issue has been resolved :idea: