tommyda Posted January 23, 2009 Share Posted January 23, 2009 I'm real stuck on this one why am I getting a blank page. What I wanted it to do is: if the the submit button is pressed, insert the posted data into the db, if not echo the form. Im still learning so any help would be appreciated. <?php include("include/session.php"); include'inc/mysql_con.php'; $s_id = $_GET['sid']; $title = $_POST['title']; $body = $_POST['body']; $u_id = $_SESSION['userid']; if(isset($_POST['submit'])) if(isset($_POST['submit'])){ mysql_query("INSERT INTO reviews (s_id, title, body, userid) VALUES($s_id, $title, $body, $u_id) ") or die(mysql_error()); } else { echo'<form id="form1" name="form1" method="post" action=""> <label> Title <input name="title" type="text" id="title" /> </label> <p> <label>Body <textarea name="body" cols="60" rows="6" id="body"></textarea> </label> </p> <p> <label> <input type="submit" name="submit" value="Submit" /> </label> </p> </form>'; ;} ?> Quote Link to comment Share on other sites More sharing options...
gevans Posted January 24, 2009 Share Posted January 24, 2009 try this <?php include("include/session.php"); include'inc/mysql_con.php'; $s_id = $_GET['sid']; $title = $_POST['title']; $body = $_POST['body']; $u_id = $_SESSION['userid']; if(isset($_POST['submit'])) { mysql_query("INSERT INTO reviews (s_id, title, body, userid) VALUES($s_id, $title, $body, $u_id) ") or die(mysql_error()); } else { echo'<form id="form1" name="form1" method="post" action=""> <label> Title <input name="title" type="text" id="title" /> </label> <p> <label>Body <textarea name="body" cols="60" rows="6" id="body"></textarea> </label> </p> <p> <label> <input type="submit" name="submit" value="Submit" /> </label> </p> </form>'; } ?> Quote Link to comment Share on other sites More sharing options...
tommyda Posted January 24, 2009 Author Share Posted January 24, 2009 Thanks for the help it shows the form but when I submit it I get a syntax error 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 ')' at line 1 What did you change to make it work this far? EDIT: I found a solution to the sql error just wrapped the variables in quotes. Could you please tell me what I did wrong with the first code and what you changed? Quote Link to comment Share on other sites More sharing options...
gevans Posted January 24, 2009 Share Posted January 24, 2009 ignore that.... Quote Link to comment Share on other sites More sharing options...
gevans Posted January 24, 2009 Share Posted January 24, 2009 Go through your code and mine side by side, see what the differences are and if you can figure out where you went wrong. If you still are unsure give me a shout. Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 24, 2009 Share Posted January 24, 2009 Change mysql_query("INSERT INTO reviews (s_id, title, body, userid) VALUES($s_id, $title, $body, $u_id) ") or die(mysql_error()); to $query = ""INSERT INTO reviews (s_id, title, body, userid) VALUES($s_id, $title, $body, $u_id) "; mysql_query($query) or die(mysql_error().": $query"); We will see if query is well formed. Quote Link to comment Share on other sites More sharing options...
tommyda Posted January 24, 2009 Author Share Posted January 24, 2009 Go through your code and mine side by side, see what the differences are and if you can figure out where you went wrong. If you still are unsure give me a shout. How stupid do I feel now! if(isset($_POST['submit'])) if(isset($_POST['submit'])){ Thanks for the help Quote Link to comment Share on other sites More sharing options...
gevans Posted January 24, 2009 Share Posted January 24, 2009 No worries Quote Link to comment 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.