dexter_sherban Posted April 2, 2007 Share Posted April 2, 2007 I'm trying to make a bulleting board. It has login, submit, edit and delete option. To keep it efficient I want it to have only 2 pages. One with the login(that I've finished) and one with the message output and the edit/delete/submit options. Im relatively new to PHP. I thought of making is menu like. So whenever the user selects an option, the program will go to an IF statement and execute the function needed. Also my database is mysql and I store the messages there. I finlay got it to...well show something. I want the edit to work like this. you click on the edit button under the message u want to edit, and then the page will refresh itself and instead of the old message it will show a input form with the subject/message, you enter new data in it and update it. So I think the if statement should work, And I thought about it a long time, it still hasnt hit me. any ideas. OH and my database key is 'entry' <html> <head> </head> <body> <?php $name=$_POST["username"]; $pass=$_POST["password"]; $entry=$_POST["entry"]; $subject=$_POST["subject"]; $message=$_GET["message"]; $option=$_GET["option"]; $date=date('y-m-d'); //Store initial entry...at one time I though the entry variable kept getting overwritten but still this didnt help... $initialentry=$entry; echo "$initialentry"; $con=mysql_connect("localhost","user","pass"); if (!$con) { die ('could not connect: ' .mysql_error()); } mysql_select_db("Serban",$con); function Forminput() { echo "<form action='Bulletin.php' method='POST'><br><br> <input type='hidden' name='entry' value=$entry> <input type='hidden' name='name' value=$name> Subject: <br><input type='text' name='subject' value='$subject'><br><br> Message: <br>"; echo "<textarea cols='20' rows='10' name='message'>"; if(isset($message)) echo htmlspecialchars($message); echo "</textarea>"; echo "<br><br><input type='submit' value='edit/upload'></form>"; } function Delete() { mysql_query("delete from message where entry='$entry'"); } function Edit() { mysql_query("update message set subject='$subject',message='$message',date='$date' where entry=$entry"); } function Insert() { $result=mysql_query("select * from message"); $entry= mysql_num_rows($result); mysql_query("insert into message (subject, message, date, entry) VALUES ('$subject','$message','$date', '$entry')"); } Edit(); $data=mysql_query("select * from message order by entry desc"); while($row = mysql_fetch_array($data)) { $entry=$row['entry']; //This is the IF im walking about. if ($option==1 && $entry==$initialentry) { $subject=$row['subject']; $message=$row['message']; Forminput(); } elseif (option == 2) { Delete(); } else { echo "Posted on "; echo $row['date']; echo "<br><b>"; echo "Subject : "; echo "</b>"; echo $row['subject']; echo "<br><b>"; echo "Message : "; echo "</b>"; echo $row['message']; echo "<br>"; echo "<br>"; echo "<form> <input type='hidden' name='entry' value=$entry> <input type='hidden' name='option' value=1> <input type='submit' value='edit' action='Bulletin.php' method='POST'> </form>"; echo "<form> <input type='hidden' name='entry' value=$entry> <input type='hidden' name='option' value=2> <input type='submit' value='delete' action='Bulletin.php' method='POST'> </form>"; echo "<br>"; } } Forminput(); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/45274-problems-with-an-if-statement/ Share on other sites More sharing options...
trq Posted April 2, 2007 Share Posted April 2, 2007 Sorry, but Im not sure I see a question here. What is it your asking ezactly? Link to comment https://forums.phpfreaks.com/topic/45274-problems-with-an-if-statement/#findComment-219826 Share on other sites More sharing options...
cuteflower Posted April 2, 2007 Share Posted April 2, 2007 hi, actually u can use switch for this which wil make yr task more easy.... and u will be also saving time!! Link to comment https://forums.phpfreaks.com/topic/45274-problems-with-an-if-statement/#findComment-219829 Share on other sites More sharing options...
per1os Posted April 2, 2007 Share Posted April 2, 2007 function Forminput() { global $message; echo "<form action='Bulletin.php' method='POST'><br><br> <input type='hidden' name='entry' value=$entry> <input type='hidden' name='name' value=$name> Subject: <br><input type='text' name='subject' value='$subject'><br><br> Message: <br>"; echo "<textarea cols='20' rows='10' name='message'>"; if(isset($message)) echo htmlspecialchars($message); echo "</textarea>"; echo "<br><br><input type='submit' value='edit/upload'></form>"; } Try that. Link to comment https://forums.phpfreaks.com/topic/45274-problems-with-an-if-statement/#findComment-219834 Share on other sites More sharing options...
dexter_sherban Posted April 2, 2007 Author Share Posted April 2, 2007 Sorry, Im asking why isnt the IF statement working. Whenever I click the edit button it doesnt even give me the FORMINPUT function. I guess switches help but im more used to IF. Plus I think my problem is in the condition. Link to comment https://forums.phpfreaks.com/topic/45274-problems-with-an-if-statement/#findComment-219836 Share on other sites More sharing options...
per1os Posted April 2, 2007 Share Posted April 2, 2007 My bad, where is $option being set? { $entry=$row['entry']; //This is the IF im walking about. if ($option==1 && $entry==$initialentry) { Link to comment https://forums.phpfreaks.com/topic/45274-problems-with-an-if-statement/#findComment-219848 Share on other sites More sharing options...
dexter_sherban Posted April 2, 2007 Author Share Posted April 2, 2007 Thanks for the previous post. It made me figure out why my form inputs are empty. The $option come from a hidden form. echo "<form> <input type='hidden' name='entry' value=$entry> <input type='hidden' name='option' value=2> <input type='submit' value='delete' action='Bulletin.php' method='POST'> </form>"; echo "<br>"; I guess we can say my problem is resolved. Figured out it was my GET and POST.They were all over the place, and as you can see from the line of code up, my forms were all bad two. It works fine now. Still thanks for your help. Link to comment https://forums.phpfreaks.com/topic/45274-problems-with-an-if-statement/#findComment-219855 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.