riceje7 Posted September 4, 2009 Share Posted September 4, 2009 i can't for the life of me figure out why my form data from the form at the bottom of my code is not passing through when i submit it. i'm looking to get the post and newthreadname to insert it into my database but it keeps returning blank strings from $_POST. any help would be great. <?php session_start(); $username = $_SESSION['username']; $threadname = $_GET['threadname']; $dbuser = ""; $bdpass = ""; $time = date('h:i:s M dS, Y'); $post = $_POST['post']; $post = stripslashes($post); $post = mysql_real_escape_string($post); $newthreadname = $_POST['newthreadname']; $newthreadname = str_replace(' ', ' ', $newthreadname); $newthreadname = stripslashes($newthreadname); $newthreadname = mysql_real_escape_string($newthreadname); echo $post."<br/>"; echo $newthreadname."<br/>"; //echo $time; $connect = mysql_connect(localhost, $dbuser, $dbpass); mysql_select_db(forum); $sql = "SELECT * FROM `thread_names`"; $result = mysql_query($sql); $num = mysql_num_rows($result); //echo $num; //echo "<br/>"; //listing out hyperinks to different forums threads echo "<a href='forum.php'>Home</a>"; echo "<br/>"; for($i = 0; $i < $num; $i ++) { $names = mysql_result($result, $i, 1); $names = str_replace(' ', ' ', $names); echo "<a href='forum.php?threadname=".$names."'>".$names."</a>"; echo "<br/>"; } if(isset($threadname)) { $sql = "SELECT * FROM `".$threadname."`"; $result = mysql_query($sql); $postdata = mysql_fetch_row($result); echo $postdata[0]; echo "<br/>"; echo $postdata[1]; echo "<br/>"; echo $postdata[2]; echo "<br/>"; echo $postdata[3]; echo "<br/>"; echo $postdata[4]; echo "<br/>"; } if(array_key_exists('submit', $_POST)) { echo "hello1"; if($post == "" or $newthreadname == "") { echo "<center>Post and Thread Name Required</center>"; } else { echo "hello2"; //thread creation $sql = "CREATE TABLE `forum`.`".$newthreadname."` (`postid` INT(4) NOT NULL AUTO_INCREMENT, `threadname` VARCHAR(50) NOT NULL, `username` VARCHAR(50) NOT NULL, `timestamp` VARCHAR(25) NOT NULL, `post` TEXT NOT NULL, PRIMARY KEY (`postid`)) ENGINE = MyISAM;"; mysql_query($sql); echo "hello3"; //adding thread name to threadname list for hyperlinks above $sql = "INSERT INTO `forum`.`thread_names` (`id`, `threadname`) VALUES (NULL, '".$newthreadname."');"; mysql_query($sql); echo "hello4"; //insertion $post = stripslashes($post); $post = mysql_real_escape_string($post); $sql = "INSERT INTO `forum`.`".$newthreadname."` (`postid`, `threadname`, `username`, `timestamp`, `post`) VALUES (NULL, '$newthreadname', '$username', '$time', '$post');"; if(mysql_query($sql)) { echo "<center>Thread Created</center>"; //header("location:forum.php"); } echo "hello5"; } } if($threadname != "") { echo '<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">'; echo ' <tr>'; echo '<td>'; echo '<table width="500" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">'; echo '<form name="createreply" id="createreply" method="post" action="forum.php" enctype="multipart/form-data">'; echo '<tr>'; echo '<td><table width="%100" >'; echo '<tr><center>Reply to this thread:</center>'; echo "<td>User: <input type='text' maxlength='50' width='50' name='username' id='username' value=".$username." readonly='readonly'/></td>"; echo "<td>Thread Name: <input type='text' name='threadname' id='threadname' value='".$threadname."'/><input type='hidden' name='time' id='time' value=".$time." readonly='readonly'/></td>" ; echo '</tr>'; echo '</table>'; echo '<table width="500" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">'; echo '<tr>'; echo '<td align="center"><textarea rows="6" cols="60" name="post" id="post"/></textarea>'; echo '</tr>'; echo '<table width="500" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">'; echo '<tr>'; echo '<td align="right"><input type="submit" name="reply" value="Reply" /></td></td>'; echo '</tr>'; echo '</table>'; echo '</table>'; echo '</td>'; echo '</tr>'; echo '</table>'; echo '</td>'; echo '</tr>'; echo '</table>'; } ?> <!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=UTF-8" /> <title>Untitled Document</title> </head> <body> <br/> <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td> <table width="500" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <form name="createthread" id="createthread" method="post" action="forum.php" enctype="text/plain"> <tr> <td><table width="%100" > <tr><center>Create A New Thread:</center> <td>User: <input type="text" maxlength="50" width="50" name="username" id="username" value="<?php echo $username; ?>" readonly="readonly"/></td> <td>New Thread Name: <input type="text" name="newthreadname" id="newthreadname" /><input type="hidden" name="time" id="time" value="<?php echo $time; ?>"/></td> </tr> </table> <table width="500" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td align="center"><textarea rows="6" cols="60" name="post" id="post"/></textarea> </tr> <table width="500" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td align="right"><input type="submit" name="submit" value="Submit New Thread" /></form)</td></td> </tr> </table> </table> </td> </tr> </table> </td> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/173049-solved-data-not-passing-through-_post/ Share on other sites More sharing options...
sKunKbad Posted September 4, 2009 Share Posted September 4, 2009 what happens when you var_dump the post array at the top of the code? Quote Link to comment https://forums.phpfreaks.com/topic/173049-solved-data-not-passing-through-_post/#findComment-912109 Share on other sites More sharing options...
BinaryG Posted September 4, 2009 Share Posted September 4, 2009 all i can see at the moment is that your start of the form is outside of the table td tag here <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td> <table width="500" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <form name="createthread" id="createthread" method="post" action="forum.php" enctype="text/plain"> <tr> <td><table width="%100" > <tr><center>Create A New Thread:</center> <td>User: <input type="text" maxlength="50" width="50" name="username" id="username" value="<?php echo $username; ?>" readonly="readonly"/></td> <td>New Thread Name: <input type="text" name="newthreadname" id="newthreadname" /><input type="hidden" name="time" id="time" value="<?php echo $time; ?>"/></td> </tr> </table> <table width="500" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td align="center"><textarea rows="6" cols="60" name="post" id="post"/></textarea> </tr> <table width="500" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td align="right"><input type="submit" name="submit" value="Submit New Thread" /></form)</td></td> </tr> </table> </table> </td> </tr> </table> </td> </tr> </table> it should look like this <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td> <table width="500" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td><table width="%100" > <tr><form name="createthread" id="createthread" method="post" action="forum.php" enctype="text/plain"><center>Create A New Thread:</center> <td>User: <input type="text" maxlength="50" width="50" name="username" id="username" value="<?php echo $username; ?>" readonly="readonly"/></td> <td>New Thread Name: <input type="text" name="newthreadname" id="newthreadname" /><input type="hidden" name="time" id="time" value="<?php echo $time; ?>"/></td> </tr> </table> <table width="500" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td align="center"><textarea rows="6" cols="60" name="post" id="post"/></textarea> </tr> <table width="500" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td align="right"><input type="submit" name="submit" value="Submit New Thread" /></form)</td></td> </tr> </table> </table> </td> </tr> </table> </td> </tr> </table>[code] Quote Link to comment https://forums.phpfreaks.com/topic/173049-solved-data-not-passing-through-_post/#findComment-912110 Share on other sites More sharing options...
.josh Posted September 4, 2009 Share Posted September 4, 2009 remove enctype="text/plain" from your form tags Quote Link to comment https://forums.phpfreaks.com/topic/173049-solved-data-not-passing-through-_post/#findComment-912111 Share on other sites More sharing options...
riceje7 Posted September 4, 2009 Author Share Posted September 4, 2009 sKunKbad - i did a var_dump for both newthreadname and post and it returned bool(false) for each. BinaryG - i changed what you pointed out and it is still acting the same Crayon Violet - tried what you said and it still isn't passing through Quote Link to comment https://forums.phpfreaks.com/topic/173049-solved-data-not-passing-through-_post/#findComment-912113 Share on other sites More sharing options...
PFMaBiSmAd Posted September 4, 2009 Share Posted September 4, 2009 Did you cause your browser to reload the page after you made that change? Otherwise it did not take effect. Edit: and the code is just a mess. To start with, you are using mysql_real_escape_string() before you have established a connection to the database server. Are you developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your php.ini so that php would help you? Here is a list of all the errors that occur on your page prior to the point that the database connection is made - Notice: Undefined index: username in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\forum.php on line 4 Notice: Undefined index: threadname in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\forum.php on line 5 Notice: Undefined index: post in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\forum.php on line 11 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'SYSTEM'@'localhost' (using password: NO) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\forum.php on line 13 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\forum.php on line 13 Notice: Undefined index: newthreadname in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\forum.php on line 14 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'SYSTEM'@'localhost' (using password: NO) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\forum.php on line 17 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\forum.php on line 17 Notice: Use of undefined constant localhost - assumed 'localhost' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\forum.php on line 22 Notice: Undefined variable: dbpass in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\forum.php on line 22 Edit2: And the format in this - $time = date('h:i:s M dS, Y'); will make any sorting or comparison of the data directly impossible. Use a mysql DATETIME data type, that is what it exists for. Quote Link to comment https://forums.phpfreaks.com/topic/173049-solved-data-not-passing-through-_post/#findComment-912114 Share on other sites More sharing options...
BinaryG Posted September 4, 2009 Share Posted September 4, 2009 also delete all the form at the bottom and tables and replace it with this it dont look pretty but at least there is not about 6 open td and tr tags <form name="createthread" id="createthread" method="post" action="forum.php"> <table width="100%" border="0"> <tr> <td><center> Create A New Thread: </center>User: <input type="text" maxlength="50" width="50" name="username" id="username" value="<?php echo $username; ?>" readonly="readonly"/></td> </tr> <tr> <td>New Thread Name: <input type="text" name="newthreadname" id="newthreadname" /></td> </tr> <tr> <td> <input type="hidden" name="time" id="time" value="<?php echo $time; ?>"/></td> </tr> <tr> <td><textarea rows="6" cols="60" name="post" id="post"/> </textarea></td> </tr> <tr> <td><input type="submit" name="submit" value="Submit New Thread" /></td> </tr> </table> </form> yep just tested the post dat and it works now put this at the top to echo the post vars echo "test====================================="; foreach($_POST as $key => $value) echo $key."=".$value; echo "test====================================="; Quote Link to comment https://forums.phpfreaks.com/topic/173049-solved-data-not-passing-through-_post/#findComment-912118 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.