contra10 Posted December 27, 2008 Share Posted December 27, 2008 hey i have a code and its not entering the values into php...im wondering if its because i have other forms on the same page and its follwing that php script instead of this one...well here it is <?php // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submitpost'])) { //This makes sure they did not leave any fields blank if (!$_POST['userpost']) { die('You did not enter a post'); } $userpostg = mysql_real_escape_string($_POST['userpost']); //This gets today's date $date = time () ; //This puts the day, month, and year in seperate variables $day = date('d', $date) ; $month = date('F', $date) ; $year = date('Y', $date) ; // now we insert it into the database $insertpost = "INSERT INTO posts_groups (gid, gname, uid, uname, post, month, day, year) VALUES ('$id', '$groupname', '$userid', '$username', '$userpost', '$month', '$day', '$year')"; echo ($insertpost); } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0" width="800" align="center" height="100"> <tr> <td align="center"><textarea name="userpost" type="description" cols="50" rows="5" maxlength="10" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td></tr> <tr><td align="center"><input type="hidden" name="postuserid" value="<?php echo ($userid);?>"></td></tr> <tr><td align="center"><input type="hidden" name="postusername" value="<?php echo ($username);?>"></td></tr> <tr><td align="center"><input type="submit" name="submitpost" value="Post"></td></tr> </table> </form> <table border="1" width="800" align="center"> <tr><td width="800"height="500">Posts2</td></tr> </table> Link to comment https://forums.phpfreaks.com/topic/138566-solved-entering-no-variables/ Share on other sites More sharing options...
premiso Posted December 27, 2008 Share Posted December 27, 2008 Where is $id, $groupname, $userid being populated at? I do not see that. The code you have is assuming that register_globals is on. You should access it by $_POST['id'], $_POST['groupname'] etc.. Link to comment https://forums.phpfreaks.com/topic/138566-solved-entering-no-variables/#findComment-724544 Share on other sites More sharing options...
contra10 Posted December 28, 2008 Author Share Posted December 28, 2008 ok i tried to enter it with one variable ($id) <?php // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submitpost'])) { //This makes sure they did not leave any fields blank if (!$_POST['userpost']) { die('You did not enter a post'); } $userpostg = mysql_real_escape_string($_POST['userpost']); $userid = mysql_real_escape_string($_POST['useridpost']); //This gets today's date $date = time () ; //This puts the day, month, and year in seperate variables $day = date('d', $date) ; $month = date('F', $date) ; $year = date('Y', $date) ; // now we insert it into the database $insertpost = "INSERT INTO posts_groups (gid, gname, uid, uname, post, month, day, year) VALUES ('$id', '$groupname', '$userid', '$username', '$userpost', '$month', '$day', '$year')"; echo ($insertpost); } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0" width="800" align="center" height="100"> <tr> <td align="center"><textarea name="userpost" type="description" cols="50" rows="5" maxlength="10" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td></tr> <tr><?php echo"<input type='hidden' name='useridpost' value='$userid'>"?></td></tr> <tr><td align="center"><input type="hidden" name="postusername" value="<?php echo $_POST['username'];?>"></td></tr> <tr><td align="center"><input type="submit" name="submitpost" value="Post"></td></tr> </table> </form> <table border="1" width="800" align="center"> <tr><td width="800"height="500">Posts2</td></tr> </table> thats wat i did jus to see if it was going to work but it didn't enter I have other issets on the page is it possible that the code is following the other issets...note this isset is submitpost as $_POST the other one is just submit Link to comment https://forums.phpfreaks.com/topic/138566-solved-entering-no-variables/#findComment-724865 Share on other sites More sharing options...
PFMaBiSmAd Posted December 28, 2008 Share Posted December 28, 2008 Your code has no mysql_query() statement in it to execute the query that is being built in $insertpost. You are echoing $insertpost, but you are never executing it as a mysql query. Where is your mysql_query() statement? Link to comment https://forums.phpfreaks.com/topic/138566-solved-entering-no-variables/#findComment-724868 Share on other sites More sharing options...
omarh2005 Posted December 28, 2008 Share Posted December 28, 2008 try to replace this code $insertpost = "INSERT INTO posts_groups (gid, gname, uid, uname, post, month, day, year) VALUES ('$id', '$groupname', '$userid', '$username', '$userpost', '$month', '$day', '$year')"; by this code $insertpost = "INSERT INTO posts_groups (gname, uid, uname, post, month, day, year) VALUES ('$groupname', '$userid', '$username', '$userpost', '$month', '$day', '$year')"; but you ought to enable auto increment for the table Link to comment https://forums.phpfreaks.com/topic/138566-solved-entering-no-variables/#findComment-724869 Share on other sites More sharing options...
contra10 Posted December 28, 2008 Author Share Posted December 28, 2008 woops but i do the mysql query() b4 and still never got anywhere here was the statments <?php // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submitpost'])) { //This makes sure they did not leave any fields blank if (!$_POST['userpost']) { die('You did not enter a post'); } $userpostg = mysql_real_escape_string($_POST['userpost']); $userid = mysql_real_escape_string($_POST['useridpost']); //This gets today's date $date = time () ; //This puts the day, month, and year in seperate variables $day = date('d', $date) ; $month = date('F', $date) ; $year = date('Y', $date) ; // now we insert it into the database $insertpost = "INSERT INTO posts_groups (uid, uname) VALUES ('$userid', '$username', '$userpostg')"; $add_post2 = mysql_query($insertpost) or die(mysql_error()); } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0" width="800" align="center" height="100"> <tr> <td align="center"><textarea name="userpost" type="description" cols="50" rows="5" maxlength="10" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td></tr> <tr><?php echo"<input type='hidden' name='useridpost' value='$userid'>"?></td></tr> <tr><?php echo"<input type='hidden' name='username' value='$username'>"?></td></tr> <tr><td align="center"><input type="submit" name="submitpost" value="Post"></td></tr> </table> </form> Link to comment https://forums.phpfreaks.com/topic/138566-solved-entering-no-variables/#findComment-725037 Share on other sites More sharing options...
contra10 Posted December 29, 2008 Author Share Posted December 29, 2008 still not entering for some reason Link to comment https://forums.phpfreaks.com/topic/138566-solved-entering-no-variables/#findComment-725048 Share on other sites More sharing options...
contra10 Posted December 29, 2008 Author Share Posted December 29, 2008 updated... <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); if (isset($_POST['submitpost'])){ if(is_numeric($_POST['grp'])){ $id = $_POST['grp']; $query= "SELECT * FROM groups WHERE id = '$id'"; $result = mysql_query($query) or die(mysql_error());; $group = mysql_fetch_assoc($result); $groupname = "{$group['name']}"; $groupid = "{$group['id']}"; $query2= "SELECT id FROM users WHERE username = '$username'"; $result2 = mysql_query($query2) or die(mysql_error());; $usera = mysql_fetch_assoc($result2); $userid = "{$usera['id']}"; $userpostg = mysql_real_escape_string($_POST['userpost']); //This gets today's date $date = time () ; //This puts the day, month, and year in seperate variables $day = date('d', $date) ; $month = date('F', $date) ; $year = date('Y', $date) ; } //This makes sure they did not leave any fields blank if (!$_POST['userpost']) { die('You did not enter a post'); } // now we insert it into the database $insertpost = "INSERT INTO posts_groups (gid, gname, uid, uname, post, month, day, year) VALUES ('$groupid', '$groupname', $userid', '$username', '$userpostg', '$month', '$day', '$year')"; $add_post2 = mysql_query($insertpost) or die(mysql_error()); ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0" width="800" align="center" height="100"> <tr> <td align="center"><textarea name="userpost" type="description" cols="50" rows="5" maxlength="10" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td></tr> <tr><input type='hidden' name='grp' value='<?php echo $_GET['grp']; ?>'></td></tr> <tr><td align="center"><input type="submit" name="submitpost" value="Post"></td></tr> </table> </form> <?php } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0" width="800" align="center" height="100"> <tr> <td align="center"><textarea name="userpost" type="description" cols="50" rows="5" maxlength="10" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td></tr> <tr><input type='hidden' name='grp' value='<?php echo $_GET['grp']; ?>'></td></tr> <tr><td align="center"><input type="submit" name="submitpost" value="Post"></td></tr> </table> </form> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/138566-solved-entering-no-variables/#findComment-725056 Share on other sites More sharing options...
contra10 Posted December 29, 2008 Author Share Posted December 29, 2008 is there any other way Link to comment https://forums.phpfreaks.com/topic/138566-solved-entering-no-variables/#findComment-725063 Share on other sites More sharing options...
contra10 Posted December 29, 2008 Author Share Posted December 29, 2008 ill jus figure it out Link to comment https://forums.phpfreaks.com/topic/138566-solved-entering-no-variables/#findComment-725071 Share on other sites More sharing options...
contra10 Posted December 29, 2008 Author Share Posted December 29, 2008 nvm still having trouble Link to comment https://forums.phpfreaks.com/topic/138566-solved-entering-no-variables/#findComment-725079 Share on other sites More sharing options...
Chappers Posted December 29, 2008 Share Posted December 29, 2008 Try this: <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); if (isset($_POST['submitpost'])) { $test = $_POST['grp']; $test2 = $_POST['userpost']; echo "Right here... $test ...there should be the grp field data<br>"; echo "Here should be the textarea data... $test2 ...if submit's working"; if(is_numeric($_POST['grp'])) { $id = $_POST['grp']; $result = mysql_query("SELECT * FROM groups WHERE id = '$id'") or die(mysql_error()); $group = mysql_fetch_array($result, MYSQL_ASSOC); $groupname = $group['name']; $groupid = $group['id']; $result2 = mysql_query("SELECT id FROM users WHERE username = '$username'") or die(mysql_error()); $usera = mysql_fetch_array($result2, MYSQL_ASSOC); $userid = $usera['id']; $userpostg = mysql_real_escape_string($_POST['userpost']); // This gets today's date $date = time(); //This puts the day, month, and year in separate variables $day = date('d', $date); $month = date('F', $date); $year = date('Y', $date); } // This makes sure they did not leave any fields blank if (empty($_POST['userpost'])) { die('You did not enter a post'); } // Now we insert it into the database $add_post2 = mysql_query("INSERT INTO posts_groups (gid, gname, uid, uname, post, month, day, year) VALUES ('$groupid', '$groupname', $userid', '$username', '$userpostg', '$month', '$day', '$year')") or die(mysql_error()); echo <<<chappers <form action="{$_SERVER['PHP_SELF']}" method="post"> <table border="0" width="800" align="center" height="100"> <tr> <td align="center"><textarea name="userpost" type="description" cols="50" rows="5" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td></tr> <tr><input type='hidden' name='grp' value='{$_GET['grp']}'></td></tr> <tr><td align="center"><input type="submit" name="submitpost" value="Post"></td></tr> </table> </form> chappers; } else { echo <<<chappers <form action="{$_SERVER['PHP_SELF']}" method="post"> <table border="0" width="800" align="center" height="100"> <tr> <td align="center"><textarea name="userpost" type="description" cols="50" rows="5" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td></tr> <tr><input type='hidden' name='grp' value='{$_GET['grp']}'></td></tr> <tr><td align="center"><input type="submit" name="submitpost" value="Post"></td></tr> </table> </form> chappers; } ?> And if it doesn't work, say what's happening or not happening. You'll notice I've added echo "Right here... $_POST['grp'] ...there should be the grp field data"; and same for textarea field. That's to make sure that when you submit the form, everything's being sent across. Link to comment https://forums.phpfreaks.com/topic/138566-solved-entering-no-variables/#findComment-725124 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.