Page 1 of 1
posting stuff in php
Posted: Thu Nov 25, 2010 2:15 pm
by VZdemon
hi i'm new to this forum. i joined here to get help on my php projects and other programming languages. so can any1 pliz help me with this post.php code:
Code: Select all
<html>
<link href="style.css" rel="stylesheet" type="text/css" />
<body bgcolor="BLUE" text="#00FF66" link="#990000" vlink="#CC0000">
<div id="trasitepages">
<?php
include "connect.php";
include "authenticate.php";
include "postreview.php";
$name = $_POST['pname'];
$desc = $_POST['desc'];
$link = $_POST['link'];
if (isset($_SESSION['user'])){
$user = $_SESSION['user'];
}
if($name&&$desc&&$link){
$query = mysql_query("INSERT INTO tools
('name','link','desc','poster','rating')
VALUES('$name','$link','$desc','$user','1')");
if($query){
echo "<big>Post successfully uploaded<br/><a href='links.php'>Continue</a></big>";
}else{
die("Unable to post");
}
}
?>
</div>
</body>
</html>
i can't seem to post anything with it. i use wampserver v2.0 and dreamweaver
Re: posting stuff in php
Posted: Thu Nov 25, 2010 3:27 pm
by Chris
Where's your form?
Re: posting stuff in php
Posted: Sat Nov 27, 2010 2:12 am
by sdevaney
You also failed to say what the problem is. Is there an error?
Re: posting stuff in php
Posted: Sat Nov 27, 2010 4:24 pm
by VZdemon
the problem is that it won't post anything, when ever i test it it just says "unable to post".
here is the form code:
Code: Select all
<form enctype="multipart/form-data" action='apr.php' method='POST'>
<link href="style.css" rel="stylesheet" type="text/css" />
<body bgcolor="BLUE" text="#00FF66" link="#990000" vlink="#CC0000">
</body>
<table background="images/pnl.png" width='70' height='140'>
<tr>
<td>
Program/game/ect name:
<input type='text' align='right' name='pname' size="40"/>
</td>
</tr>
<tr>
<td>
Program/game/ect official website:
<input type='text' align='right' name='link' size="40"/>
</td>
</tr>
<tr>
<td>
Program/game/ect description:
<textarea cols='30' rows='5' wrap="hard" name="desc"></textarea>
</td>
</tr>
<tr>
<td>
Program/game/ect image:
<input type="hidden" name="file" value='1'/>
<input name="file" type="file"/>
<input type="submit" align="middle" name="post" value="post"/>
</td>
</tr>
</table>
</form>
Re: posting stuff in php
Posted: Sat Nov 27, 2010 6:32 pm
by Jackolantern
You should not have single-quotes around the column names in your insert statement. Also, number literals should not have quotes around them in the list of values to be inserted.
This:
Code: Select all
$query = mysql_query("INSERT INTO tools
('name','link','desc','poster','rating')
VALUES('$name','$link','$desc','$user','1')");
if($query){
echo "<big>Post successfully uploaded<br/><a href='links.php'>Continue</a></big>";
}else{
die("Unable to post");
}
Should be:
Code: Select all
$query = mysql_query("INSERT INTO tools
(name, link, desc, poster, rating)
VALUES('$name', '$link', '$desc', '$user', 1)");
if($query){
echo "<big>Post successfully uploaded<br/><a href='links.php'>Continue</a></big>";
}else{
die("Unable to post");
}
Re: posting stuff in php
Posted: Sat Nov 27, 2010 7:28 pm
by Chris
Jackolantern wrote:You should not have single-quotes around the column names in your insert statement. Also, number literals should not have quotes around them in the list of values to be inserted.
This:
Code: Select all
$query = mysql_query("INSERT INTO tools
('name','link','desc','poster','rating')
VALUES('$name','$link','$desc','$user','1')");
if($query){
echo "<big>Post successfully uploaded<br/><a href='links.php'>Continue</a></big>";
}else{
die("Unable to post");
}
Should be:
Code: Select all
$query = mysql_query("INSERT INTO tools
(name, link, desc, poster, rating)
VALUES('$name', '$link', '$desc', '$user', 1)");
if($query){
echo "<big>Post successfully uploaded<br/><a href='links.php'>Continue</a></big>";
}else{
die("Unable to post");
}
"desc" is also a reserved character in MySQL.
Code: Select all
$query = mysql_query("INSERT INTO tools (name, link, `desc`, poster, rating) VALUES('$name', '$link', '$desc', '$user', 1)");
if($query)
{
echo "<big>Post successfully uploaded<br/><a href='links.php'>Continue</a></big>";
}
else
{
die("Unable to post");
}
Re: posting stuff in php
Posted: Sat Nov 27, 2010 9:04 pm
by Jackolantern
Chris wrote:"desc" is also a reserved character in MySQL.
Oh snap, didn't even see that.
Re: posting stuff in php
Posted: Sun Nov 28, 2010 2:37 pm
by VZdemon