Jump to content

Submit form and php


Davie33

Recommended Posts

Hi am having a few problems if anyone can help me.

When i click submit it takes me back to index.php but would like it to return to forum.php.

Also my avatars not showing the user id so that you can go to that ysers profile.

 

 

<?php
if ($setting['chatdisabled'] == 'yes') {
} else {
if (isset($_SESSION['user'])) { ?>
<div class="container_box1"><div class="forumheader"> ShoutBox:</div>
<!-- Shoutbox #1 Start -->
<div class="table">
<table class="listing" cellpadding="0" cellspacing="0">
<td class="shoutbox">
<?php
if (isset($_SESSION['user'])) {
  if (isset($_POST['name'])){
    $name = $_POST['name'];
  } else if (isset($_SESSION['user'])){
    $name = $_SESSION['user'];
  } else {
    $name = '';
  }
  if (isset($_POST['Submit'])) {
    $id = yasDB_clean($_POST['id']);
    $text = yasDB_clean($_POST['text']);
    $date = yasDB_clean($_POST['date']);
  if (isset($_POST['name'])){
    $name = yasDB_clean($_POST['name']);
  } else if (isset($_SESSION['user'])){
    $name = $_SESSION['user'];
  } else {
    $name = '';
  }
  $date = date("m-j-y G:i"); //create date time
  $sql = yasDB_insert("INSERT INTO `shouts` (id,text,date,name) VALUES ('', '$text', '$date', '$name')");
  $result = $sql;
  if($result){
  if($setting['seo'] == 'yes'){
    $chaturl = $setting['siteurl'].'forum.html';
  } else {
    $chaturl = $setting['siteurl'].'index.php?act=forum';
  }
  ?>
  <META HTTP-EQUIV="refresh" CONTENT="15; URL=<?php echo $chaturl;?>">
  <?php
  }
} else {
  if($setting['seo'] == 'yes'){
    $forumurl = $setting['siteurl'].'forum.html';
  } else {
    $forumurl = $setting['siteurl'].'index.php?act=forum';
  }
?>
<div class="shoutform">
<form id="form1" name="form1" method="post" action="<?php echo $forumurl;?>">
<input name="name" type="hidden" value="<?php echo $name;?>"/>
<input name="name" type="hidden" value=""/>
Shout:<input type="text" name="text" style="width:200px; color:#999" onblur="this.value = this.value || this.defaultValue; this.style.color = '#999';" onfocus="this.value=''; this.style.color = '#000';" value="Chat here!"/>
<input type="submit" class="shoutbutton" name="Submit" value="Shout"/> <a href="<?php echo $forumurl;?>" onlick="location.reload();"><img src="<?php echo $setting['siteurl'].'refresh.png';?>" style="width:25px;height:25px;margin-top:-8px" align="center" title="Refresh"></a>
<input type="hidden" name="id" value="<?php echo $id;?>"/>
</form>
</div>
<?php }
}
?>
<div id="chat">
<?php
  $query = yasDB_select("SELECT * FROM shouts");
  $prefix = $setting['siteurl'].'templates/'.$setting['theme'].'/skins/'.$setting['skin'].'/images/smilys/';
  if($query->num_rows == 0){
    echo '<div id="messageid">Shout box Cleared....</div>';
  } else {
  $query = yasDB_select("SELECT shouts.text,shouts.date,shouts.name,user.id,user.username,user.avatarfile,user.useavatar FROM shouts LEFT JOIN user ON shouts.name = user.username ORDER BY shouts.id DESC LIMIT 20");
    while ($row = $query->fetch_array(MYSQLI_ASSOC)) {
    $id = $row['id'];
    $username = $row['name'];
    $date = $row['date'];
    $text = $row['text'];
    if ($row['useavatar'] == '1'){
      $avatarimage = $setting['siteurl'].'avatars/'.$row['avatarfile'];
    } else {
      $avatarimage = $setting['siteurl'].'avatars/noavatar.JPG';
    }
    if ($setting['seo'] == 'yes'){
      $memberlink = $setting['siteurl'].'showmembers/'.$id.'.html';
    } else {
      $memberlink = $setting['siteurl'].'index.php?act=showmember&id='.$id;
    }
    ?>
    <div id="messageid">
    <a href="<?php echo $memberlink;?>"><img src="<?php echo $avatarimage;?>" width="25" height="25" align="left" style="margin:1px;" title="<?php echo $username;?>"></a> <a href="<?php echo $memberlink;?>" title="<?php echo $username;?>"><?php echo $username;?></a>  :  <?php echo $date;?>  -  <?php echo $text;?>
    </div>
<?php }
}
?>
    </div>
    <div class="clear"></div>
    </td>
    </table>
    </div>
    <div class="clear"></div>
    </div>
<?php }
}
?>
<!--- ShoutBox #1 end -->
Link to comment
Share on other sites

What is output if you add die in these two places?

  if($setting['seo'] == 'yes'){
    $forumurl = $setting['siteurl'].'forum.html';
die("setting['seo'] = yes");
  } else {
    $forumurl = $setting['siteurl'].'index.php?act=forum';
die("setting['seo'] = NOT yes");
  }

Just a guess that $setting['siteurl'] is your problem but you do not show how you form that array.

Link to comment
Share on other sites

You need to see what the action of your form is. Easiest way to do that would be to view the source of the page once it's loaded, then debug back from there.

 

Also, in your description you say you want to go to forum.php, however in the first part of the if statement for settings $forumurl, you've got forum.html there.

 

Denno

Link to comment
Share on other sites

Thanks guys i got it working with the avatars but still can't sort it for going back to forum.php.

If i put die it kills the link.

 

forum.php = forum.html is for seo "yes" otherwise seo will show url like index.php?act=forum

  if($setting['seo'] == 'yes'){
    $forumurl = $setting['siteurl'].'forum.html';
  } else if ($setting['seo'] == 'no'){
    $forumurl = $setting['siteurl'].'index.php?act=forum';
  }

the $setting['siturl'] is in my config file that sorts the seo and $forumurl is to code the url smaller in code.

That's why i can do my url code like this <a href="<?php echo $forumurl;?>">Forum</a> plus adding to action="<?php echo $forumurl" which should work.

Edited by Davie33
Link to comment
Share on other sites

Davie, do you like to eat italian spaghettii :)

 

Are you able to show us the html source view of the generated php code above?

 

Do you have php's error_reporting set to E_ALL and display_errors set to ON so that any php detected errors will be reported and displayed?

 

Try, to set this on the top of this php page, and tell us if you're getting some notices.

<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
ini_set('output_buffering','Off');
error_reporting(-1);
Link to comment
Share on other sites

Then, you have a logic error(s) in your app. The only way to detect logic errors that I know is by testing your program, manually or automatically (using some debugging tools) and verifying that the output is what you expected. Many programmers (me too) are first exposed debugging process attempting to isolate a problem by adding calls to output functions as simple echo() to their code.  Your script is too hard to debug like in the example above. What the value of the form action attribute is before the form being submitted? 

<form id="form1" name="form1" method="post" action="<?php echo $forumurl;?>">
Edited by jazzman1
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.