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>'; ;} ?> Link to comment https://forums.phpfreaks.com/topic/142190-solved-can-you-see-a-reason-why-im-getting-no-output/ 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>'; } ?> Link to comment https://forums.phpfreaks.com/topic/142190-solved-can-you-see-a-reason-why-im-getting-no-output/#findComment-744845 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? Link to comment https://forums.phpfreaks.com/topic/142190-solved-can-you-see-a-reason-why-im-getting-no-output/#findComment-744850 Share on other sites More sharing options...
gevans Posted January 24, 2009 Share Posted January 24, 2009 ignore that.... Link to comment https://forums.phpfreaks.com/topic/142190-solved-can-you-see-a-reason-why-im-getting-no-output/#findComment-744853 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. Link to comment https://forums.phpfreaks.com/topic/142190-solved-can-you-see-a-reason-why-im-getting-no-output/#findComment-744855 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. Link to comment https://forums.phpfreaks.com/topic/142190-solved-can-you-see-a-reason-why-im-getting-no-output/#findComment-744857 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 Link to comment https://forums.phpfreaks.com/topic/142190-solved-can-you-see-a-reason-why-im-getting-no-output/#findComment-744876 Share on other sites More sharing options...
gevans Posted January 24, 2009 Share Posted January 24, 2009 No worries Link to comment https://forums.phpfreaks.com/topic/142190-solved-can-you-see-a-reason-why-im-getting-no-output/#findComment-744879 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.