![](https://forums.phpfreaks.com/uploads/set_resources_1/84c1e40ea0e759e3f1505eb1788ddf3c_pattern.png)
contra10
-
Posts
402 -
Joined
-
Last visited
Never
Posts posted by contra10
-
-
btw sry forr the length of the code
-
hi i keep getting redirected to another post when i click submit
and the values are entered in the other post. however if i click back in the browser and refresh the page the value is entered into that post
when i click into the group i get a usrl such as
http://localhost/groupsio/post.php?id=2
when i click on post i get a url such as
http://localhost/groupsio/post.php
heres my code
<?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); if(is_numeric($_GET['id'])){ $id = $_GET['id']; $insert1= "SELECT * FROM groups WHERE id = '$id'"; $topic1 = mysql_query($insert1) or die(mysql_error()); while ($topica = mysql_fetch_assoc($topic1)) { $grpname= "{$topica['name']}"; } } //This code runs if the form has been submitted if (isset($_POST['post'])) { //This makes sure they did not leave any fields blank if (!$_POST['userpost']){ die('You did not complete all of the required fields'); } $query2= "SELECT id FROM users WHERE username = '$username'"; $result2 = mysql_query($query2) or die(mysql_error()); $usera = mysql_fetch_assoc($result2); $userid = "{$usera['id']}"; $userpost = mysql_real_escape_string($_POST['userpost']); $grpnamea = mysql_real_escape_string($_POST['grpname']); $ida = mysql_real_escape_string($_POST['grpid']); //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 $insert = "INSERT INTO post_grp (grpid, grpname, userid, username, grppost, month, day, year) VALUES ('$ida', '$grpnamea', '$userid', '$username', '$userpost', '$month', '$day', '$year')"; $add_group = mysql_query($insert) or die(mysql_error()); ?> <?php echo($grpname);?> <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><?php echo "<input type='hidden' name='grpname' value='$grpname'>";?></tr></td> <tr><td><?php echo "<input type='hidden' name='grpid' value='$id'>";?></td> </tr> <tr><td align="center"><input type="submit" name="post" 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><td><?php echo "<input type='hidden' name='grpname' value='$grpname'>";?></tr></td> <tr><td><?php echo "<input type='hidden' name='grpid' value='$id'>";?></td> </tr> <tr><td align="center"><input type="submit" name="post" value="Post"></td></tr> </table> </form> <?php } ?> <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); if(is_numeric($_GET['id'])){ $id = $_GET['id']; $insert3= "SELECT * FROM post_grp WHERE grpid = '$id' ORDER BY pgid DESC"; $topic3 = mysql_query($insert3) or die(mysql_error()); } //This checks to see if there is a page number. If not, it will set it to page 1 if (!isset($pagenum)) { $pagenum = (isset($_GET['pagenum'])) ? $_GET['pagenum'] : 1; } //Here we count the number of results //Edit $data to be your query $data = mysql_query("SELECT * FROM post_grp WHERE grpid = '$id' ORDER BY pgid DESC") or die(mysql_error()); $rows = mysql_num_rows($data); //This is the number of results displayed per page $page_rows = 4; //This tells us the page number of our last page $last = ceil($rows/$page_rows); //this makes sure the page number isn't below one, or more than our maximum pages if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //This sets the range to display in our query $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; //This is your query again, the same one... the only difference is we add $max into it $data_p = mysql_query("SELECT * FROM post_grp WHERE grpid = '$id' ORDER BY pgid DESC $max") or die(mysql_error()); //This is where you display your query results while($info = mysql_fetch_array( $data_p )) { $userpost= "{$info['grppost']}"; $username= "{$info['username']}"; $usermonth= "{$info['month']}"; $userday= "{$info['day']}"; $useryear= "{$info['year']}"; echo "<table border='1' align='center'>"; echo "<tr>"; echo"<td width= '500' align='center'> $userpost</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='right'>Posted by $username on $usermonth, $userday $useryear</td>"; echo "<tr>"; echo"</table>"; } echo "<p>"; // This shows the user what page they are on, and the total number of pages echo " --Page $pagenum of $last-- <p>"; // First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page. if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; } //just a spacer echo " ---- "; //This does the same as above, only checking if we are on the last page, and then generating the Next and Last links if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } ?>
-
sry, the code works its just that that was for a particular group.
when i create another group and let them have their own post everytime i click the submit button i get redirected to the other post. but when i cleck back and refresh the page the post loads where its suppose to be...
i guess my qustion is, can i click post withou being redirected to the other post?
-
makes perfect sense, thank u
-
i changed that to the isset but it does the same thing it did before...my problem is that when i first go onto the page i'm shown this url
http://localhost/groupsio/post.php?id=1
PAGE 1 of 4
when i click next or in this case last i get
http://localhost/groupsio/post.php?pagenum=2
PAGE 1 of 2
but when i click previous i don't get anything it just stays on the same page
-
hi my data is being shown but when i click last or try to connect back to the first page i don't get anywhere
heres my code
<?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); if(is_numeric($_GET['id'])){ $id = $_GET['id']; $insert3= "SELECT * FROM post_grp WHERE grpid = '$id' ORDER BY pgid DESC"; $topic3 = mysql_query($insert3) or die(mysql_error()); } //This checks to see if there is a page number. If not, it will set it to page 1 if (!(isset($pagenum))) { $pagenum = 1; } //Here we count the number of results //Edit $data to be your query $data = mysql_query("SELECT * FROM post_grp WHERE grpid = '$id' ORDER BY pgid DESC") or die(mysql_error()); $rows = mysql_num_rows($data); //This is the number of results displayed per page $page_rows = 4; //This tells us the page number of our last page $last = ceil($rows/$page_rows); //this makes sure the page number isn't below one, or more than our maximum pages if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //This sets the range to display in our query $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; //This is your query again, the same one... the only difference is we add $max into it $data_p = mysql_query("SELECT * FROM post_grp WHERE grpid = '$id' ORDER BY pgid DESC $max") or die(mysql_error()); //This is where you display your query results while($info = mysql_fetch_array( $data_p )) { $userpost= "{$info['grppost']}"; $username= "{$info['username']}"; $usermonth= "{$info['month']}"; $userday= "{$info['day']}"; $useryear= "{$info['year']}"; echo "<table border='1' align='center'>"; echo "<tr>"; echo"<td width= '500' align='center'> $userpost</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='right'>Posted by $username on $usermonth, $userday $useryear</td>"; echo "<tr>"; echo"</table>"; } echo "<p>"; // This shows the user what page they are on, and the total number of pages echo " --Page $pagenum of $last-- <p>"; // First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page. if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; } //just a spacer echo " ---- "; //This does the same as above, only checking if we are on the last page, and then generating the Next and Last links if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } ?>
-
i fixed it
-
heres my code
<?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); if (isset($_POST['post'])){ if(is_numeric($_GET['id'])){ $id = $_GET['id']; $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']}"; $userpost = mysql_real_escape_string($_POST['userpost']); $month = mysql_real_escape_string($_POST['month']); $day = mysql_real_escape_string($_POST['day']); $year = mysql_real_escape_string($_POST['year']); } //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_grp (grpid, grpname, userid, username, grppost, month, day, year) VALUES ('$groupid', '$groupname', $userid', '$username', '$userpost', '$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='day' value='<?php $date = time () ; $day = date('d', $date); echo ($day); ?>'></td></tr> <tr><input type='hidden' name='month' value='<?php $date = time () ; $month = date('F', $date); echo ($month); ?>'></td></tr> <tr><input type='hidden' name='year' value='<?php $date = time () ; $year = date('Y', $date); echo ($year); ?>'></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='day' value='<?php $date = time () ; $day = date('d', $date); echo ($day); ?>'></td></tr> <tr><input type='hidden' name='month' value='<?php $date = time () ; $month = date('F', $date); echo ($month); ?>'></td></tr> <tr><input type='hidden' name='year' value='<?php $date = time () ; $year = date('Y', $date); echo ($year); ?>'></td></tr> <tr><td align="center"><input type="submit" name="post" value="Post"></td></tr> </table> </form> <?php } ?>
and i get
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'asd', '', '', '', '')' at line 2
-
nvm still having trouble
-
ill jus figure it out
-
is there any other way
-
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 } ?>
-
still not entering for some reason
-
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>
-
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
-
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>
-
also did i set it when i said
$id = $_GET['id'];
-
i thought i set it when i said
$grpname= "{$topica['name']}";
how should i change that
-
my variables can be seen if i echo them
-
I get
INSERT INTO notes_groups (gid, gname, uid, uname, notename, note, link, month, day, year) VALUES ('', '', '2', 'asd', 'asdasd', 'asdsadas', '', 'December', '26', '2008')
first 2 variables arn't entering
-
the script works fine its just that the values $id and $grpname don't enter into the database it shows 0 for the id and nothing for the grpname
-
i'm having trouble entering 2 values that are get values from another page heres my code
<?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); if(is_numeric($_GET['id'])){ $id = $_GET['id']; $insert1= "SELECT * FROM groups WHERE id = '$id'"; $topic1 = mysql_query($insert1) or die(mysql_error()); while ($topica = mysql_fetch_assoc($topic1)) { $grpname= "{$topica['name']}"; } } //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['name'] | !$_POST['note']) { die('You did not complete all of the required fields'); } // checks if the name is in use if (!get_magic_quotes_gpc()) { $_POST['name'] = ($_POST['name']); } $topiccheck = $_POST['name']; $check = mysql_query("SELECT notename FROM notes_groups WHERE notename = '$topiccheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the topic '.$_POST['name'].' is already in use.'); } // this makes sure both name and group entered match if ($_POST['name'] == $_POST['note']) { die('Input a different name please. '); } $query2= "SELECT id FROM users WHERE username = '$username'"; $result2 = mysql_query($query2) or die(mysql_error());; $usera = mysql_fetch_assoc($result2); $userid = "{$usera['id']}"; $name = mysql_real_escape_string($_POST['name']); $note = mysql_real_escape_string($_POST['note']); $link = mysql_real_escape_string($_POST['link']); //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 $insert = "INSERT INTO notes_groups (gid, gname, uid, uname, notename, note, link, month, day, year) VALUES ('$id', '$grpname', '$userid', '$username', '$name', '$note', '$link', '$month', '$day', '$year')"; $add_group = mysql_query($insert) or die(mysql_error()); ?>
the values $id and $grpname do not enter, but they are on the page as before i echoed thevalues on that same page. So i know that they are on the page
-
that only inputted the username not in the row where i wanted it to be apart of othe values
-
please tell me if that is clear enough?
[SOLVED] i keep getting redirected to another post
in PHP Coding Help
Posted
is there a way to stop the redirection
from example