Jump to content

[SOLVED] Can you see a reason why im getting no output?


tommyda

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.