chris_rulez001 Posted August 4, 2007 Share Posted August 4, 2007 hi im making a php post message and its not working can someone help me? when i click submit, it is not sumbitting it is just doing nothing <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <?php $host="**************"; // Host name $username="***********"; // Mysql username $password="********"; // Mysql password $db_name="****************"; // Database name $tbl_name4="thunderboardforums"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql4="SELECT * FROM $tbl_name4 ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result4=mysql_query($sql4); $rows4 = mysql_fetch_array($result4); ?> <?php $host="**************"; // Host name $username="***********"; // Mysql username $password="********"; // Mysql password $db_name="****************"; // Database name $tbl_name1="forumusers"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql1="SELECT * FROM $tbl_name1 ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result1=mysql_query($sql1); $rows1 = mysql_fetch_array($result1); ?> <title><?php echo $rows4['forumtitle']; ?> - New Topic</title> <link rel="stylesheet" href="css/stylesheet.css" /> </head> <body text="000000" bgcolor="F1F1F1" link="003399" vlink="003399" alink="003399"> <?php $host="**************"; // Host name $username="***********"; // Mysql username $password="********"; // Mysql password $db_name="****************"; // Database name $tbl_name="boards"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result=mysql_query($sql); ?> <?php $host="**************"; // Host name $username="***********"; // Mysql username $password="********"; // Mysql password $db_name="****************"; // Database name $tbl_name5="boards"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql5="SELECT * FROM $tbl_name5 ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result5=mysql_query($sql5); $rows5 = mysql_fetch_array($result5); ?> <?php $host="**************"; // Host name $username="***********"; // Mysql username $password="********"; // Mysql password $db_name="****************"; // Database name $tbl_name1="forumusers"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql1="SELECT * FROM $tbl_name1 ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result1=mysql_query($sql1); ?> <?php $host="**************"; // Host name $username="***********"; // Mysql username $password="********"; // Mysql password $db_name="****************"; // Database name $tbl_name1="forumusers"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql1="SELECT * FROM $tbl_name1 ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result1=mysql_query($sql1); ?> <br /> <table border="0" width="92%" cellspacing="0" cellpadding="0" style="border-color:#000000" align="center"> <tr> <td width="100%"> <table border="0" width="100%" cellpadding="0" cellspacing="0"> <tr> <td width="27%" height="50" align="center" bgcolor="F1F1F1" class="welcomebg"> </td> <td width="73%" bgcolor="F1F1F1" class="welcomebg" align="center"> <p><font size="2"> <?php if (!isset($_SESSION['username']) == false) { echo "Welcome, ".$_SESSION['displayname']."<br/>"; } else{ echo "Welcome, Guest, Please <a href='login.php'>Login</a> or <a href='register.php'>Register</a><br/>"; }?> <?php $date = date("l F d, g i a"); echo $date; ?> </font><br /></p> </td> </tr> </table> </td> </tr><tr> <td align="center"> <table width="100%" cellspacing="0" cellpadding="0" align="center"> <tr> <td width="100%" align="center"> <table border="0" width="100%" cellpadding="3" cellspacing="0" align="center"> <tr> <td class="menubg" valign="middle" bgcolor="EFEFEF" align="center"><font size="1"> <a href="index.php">Home</a> <a href="help.php">Help</a> <a href="members.php">Members</a> <a href="view_profile.php">Profile</a><?php if ($_SESSION['username'] == "admin") { echo " <a href='admin.php'>Admin Panel</a>"; }else { echo ""; } ?> <?php if (!isset($_SESSION['username']) == false) { echo " <a href='logout.php'>Logout</a>"; }else { echo " <a href='login.php'>Login</a> <a href='register.php'>Register</a>"; } ?> </font></td> </tr> </table> </td> </tr> </table> </td> </tr> </table> <br /> <?php $host="**************"; // Host name $username="***********"; // Mysql username $password="********"; // Mysql password $db_name="****************"; // Database name $tbl_name6="topics"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql6="SELECT * FROM $tbl_name6 ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result6=mysql_query($sql6); ?> <center></center><br /> <?php include('includes/general.php'); if (!isset($_SESSION['username']) == true) { echo "<div style='padding-left: 40px;'><a href='index.php' class='nav'>".$rows4['forumtitle']."</a> - New Topic</div><br/> <table border=0 width='950' cellspacing='0' cellpadding='0' bgcolor='000000' class='bordercolor' align='center'> <input type='hidden' name='action' value='post2'> <tr> <td> <table cellpadding='4' cellspacing='1' border='0' width='950' align='center'> <tr> <td colspan='2' class='titlebg' bgcolor='4080B0' height='18'> <font size='2' class='titletext' color='F1F1F1'> <b>Error</b> </font> </td> </tr> <tr> <td width='30%' class='windowbg' bgcolor='EFEFEF' align='center'> <br/><br/><strong>Error:</strong> <font color='#FF0000'>You need to be logged in to post</font><br/><br/>".$login." </td> </tr> </table> </td> </tr> </table> </td> </tr> </table>"; } else { echo "<div style='padding-left: 40px;'><a href='index.php' class='nav'>".$rows4['forumtitle']."</a> - New Topic</div><br/> <table border=0 width='950' cellspacing='0' cellpadding='0' bgcolor='000000' class='bordercolor' align='center'><form action='".$_SERVER['PHP_SELF']."' method='post' name='postForm' enctype='multipart/form-data'> <input type='hidden' name='action' value='post2'> <tr> <td> <table cellpadding='4' cellspacing='1' border='0' width='950' align='center'> <tr> <td colspan='2' class='titlebg' bgcolor='4080B0' height='18'> <font size='2' class='titletext' color='F1F1F1'> <b>Post Message</b> </font> </td> </tr> <tr> <td width='30%' class='windowbg' bgcolor='EFEFEF'> <font size='2'>Subject:</font> </td> <td width='70%' class='windowbg' bgcolor='EFEFEF'> <input type='text' name='subject' size='40' maxlength='50' tabindex='1'/> </td> </tr> <tr> <td width='30%' class='windowbg2' bgcolor='F6F6F6' valign='top'> <font size='2'>Message:</font> </td> <td width='70%' class='windowbg2' bgcolor='F6F6F6'> <font size='1'> <textarea name='message' rows='12' cols='70' wrap='soft' tabindex='2'></textarea> </td> </tr> <td colspan='2' width='100%' class='windowbg2' bgcolor='F6F6F6' align='center'> <input name='id' type='hidden' id='id'> <input name='submit' type='submit' id='submit' accesskey='s' tabindex='3' value='Post Message'> <input name='reset' type='reset' id='reset' accesskey='r' value='Reset'></td></tr></table></td></tr></form></table></td></tr></table> "; } ?> <?php function post() { $id = $_POST['id']; $username = $_SESSION['username']; $subject = $_POST['subject']; $message = $_POST['message']; $type = "Normal"; $ip = $_SERVER['REMOTE_ADDR']; if ($subject == "") { echo "<strong>Error:</strong><br> You havent entered a message subject<br/><br/>"; } elseif ($message == "") { echo "<strong>Error:</strong><br> You havent entered a message<br/><br/>"; } else { $location = "*******************"; $mysqlusername = "**********"; $mysqlpassword = "***********"; $database = "**************"; $conn = mysql_connect("$location","$mysqlusername","$mysqlpassword"); if (!$conn) die ("Could not connect MySQL"); mysql_select_db($database,$conn) or die ("Could not open database"); $mysqlinsert="INSERT INTO topics(id, topicname, madeby, message, type, ip)VALUES('$id', '$subject', '$username', '$message', '$type', '$ip')"; $result2=mysql_query($mysqlinsert)or die(mysql_error()); if($result2){ echo "<html> <head> <title>Message Posted Successfully</title> <SCRIPT LANGUAGE='JavaScript'> <!-- Begin redirTime = '3000'; redirURL = 'index.php'; function redirTimer() { self.setTimeout('self.location.href = redirURL;',redirTime); } // End --> </script> </head> <body onLoad='redirTimer()'> Message Posted.<br/><br/> </body> </html>"; } } } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/63310-post-message-problem/ Share on other sites More sharing options...
chris_rulez001 Posted August 4, 2007 Author Share Posted August 4, 2007 help?, can someone help me please? Quote Link to comment https://forums.phpfreaks.com/topic/63310-post-message-problem/#findComment-315539 Share on other sites More sharing options...
pyrodude Posted August 4, 2007 Share Posted August 4, 2007 You don't have any conditionals checking to see if the submit button was pressed. Try adding if (isset($_POST['submit'])) { // Code here } Quote Link to comment https://forums.phpfreaks.com/topic/63310-post-message-problem/#findComment-315546 Share on other sites More sharing options...
dbo Posted August 4, 2007 Share Posted August 4, 2007 Finding errors in your code is a lot easier when it's cleaner code. Define connection credentials once and then use them as needed... don't redefine db/username/password etc each time you submit a query. You could cut 20+ lines of code just by doing this. Quote Link to comment https://forums.phpfreaks.com/topic/63310-post-message-problem/#findComment-315569 Share on other sites More sharing options...
chris_rulez001 Posted August 4, 2007 Author Share Posted August 4, 2007 You don't have any conditionals checking to see if the submit button was pressed. Try adding if (isset($_POST['submit'])) { // Code here } ive just tried it and it doesnt work Quote Link to comment https://forums.phpfreaks.com/topic/63310-post-message-problem/#findComment-315721 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.