dansk Posted January 3, 2007 Share Posted January 3, 2007 okay, i come again for help from my phpfreaks friendsi have this code that i used from a tutorial[code]<?//used from maaking.com $connect = mysql_connect("localhost", "user","pass") or die(mysql_error());//mysql_select_db($announ) or die(mysql_error());$result = mysql_query("SELECT * from Announ.login WHERE session_id = '" . $_COOKIE[id] . "'");$row = mysql_fetch_array($result);if ($row[session_id] == $_COOKIE[id] && $row[user_name] == "admin"){ if($submit) {//begin of if($submit). // Set global variables to easier names // and pervent sql injection and apostrophe to break the db. $post_title = mysql_real_escape_string($_POST['post_title']); $post = mysql_real_escape_string($_POST['post']); $post_status = mysql_real_escape_string($_POST['post_status']); $image = mysql_real_escape_string($_POST['image']); $image_link = mysql_real_escape_string($_POST['link']); //check if (title) field is empty then print error message. if(!$post_title){ //this means If the title is really empty. echo "Error: News title is a required field. Please fill it."; exit(); //exit the script and don't do anything else. }// end of if //run the query which adds the data gathered from the form into the database $result = mysql_query("INSERT INTO Announ.articles (Post_Title, Post_Date,Post, Post_Status, Images,Image_Link) VALUES ('$post_title',NOW(),'$post','$post_status','$image','$image_link'"); //print success message. echo "<b>Thank you! News added Successfully!<br>You'll be redirected to Home Page after (4) Seconds"; echo "<meta http-equiv=Refresh content=4;url=Posts.php>"; }//end of if($submit). // If the form has not been submitted, display it!else {//begin of else ?> <br> <h3>::Add News</h3> <form method="post" action="news_add.php"> Title: <input name="post_title" size="40" maxlength="255"> <br> News: <textarea name="post" rows="7" cols="30"></textarea> <br> Status: <input name="post_status" rows="7" cols="30"> <br> image: <input name="image" rows="7" cols="30"> <br> image_link: <input name="image_link" rows="7" cols="30"> <br> <input type="submit" name="submit" value="Add News"> </form> <? }//end of else}else{header("Location: login.php");}?> <title>Add News</title>[/code]the form displays correctly but for some reason, when i click add news, it goes back to the same page with nothing happening, just like this one http://www.maaking.com/demos/news_for_newbie/add_news.php Link to comment https://forums.phpfreaks.com/topic/32668-code-loox-good-but-not-works/ Share on other sites More sharing options...
corbin Posted January 3, 2007 Share Posted January 3, 2007 Try replacing if($submit) with if($_POST) Link to comment https://forums.phpfreaks.com/topic/32668-code-loox-good-but-not-works/#findComment-152038 Share on other sites More sharing options...
PFMaBiSmAd Posted January 3, 2007 Share Posted January 3, 2007 The [color=red]//[/color]mysql_select_db($announ) or die(mysql_error()); statement is commented out.With no database selected, the mysql_query(...) will fail and the mysql_fetch_array(...) will fail. The $row variable will be NULL and the if(...) test will be false and will skip down to the [b]else[/b] clause. Link to comment https://forums.phpfreaks.com/topic/32668-code-loox-good-but-not-works/#findComment-152040 Share on other sites More sharing options...
corbin Posted January 3, 2007 Share Posted January 3, 2007 He's using the database.table method which works fine and is good for tables across databases... You don't actually have to select a database as long as you use the database.table method (which I'm assuming he is doing), it just relieves strain from mysql. Link to comment https://forums.phpfreaks.com/topic/32668-code-loox-good-but-not-works/#findComment-152041 Share on other sites More sharing options...
dansk Posted January 3, 2007 Author Share Posted January 3, 2007 Corbin, as always, you rock bro!Thank you for your help ;D ;DPFMaBiSmAd, thank you very much Link to comment https://forums.phpfreaks.com/topic/32668-code-loox-good-but-not-works/#findComment-152042 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.