PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?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
}
?>
Last edited by Benjamin on Sat Jul 21, 2012 5:40 pm, edited 1 time in total.
Reason:Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
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')
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.
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.
@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
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering