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>';
;}

?>

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>';
}
?>

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?

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.