PDA

View Full Version : php problem in thread like structer


destrugter
08-02-2007, 10:45 PM
ok, i am makking it to where people can put in stuff such as guides, for runescape, and it is sort of like a forum but not really, i am on my last part and i have an error in my code somehwere...can anyone tell me what i did wrong please? this is the code that inserts the stuff into the db...


<?php
$con = mysql_connect("mysql","cheese","pizza");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("cheese", $con);

mysql_query("INSERT INTO SkillGuides (`$_COOKIE["username"]`,`title`,`skill`,`p&f`,`guide`)

(\''.mysql_escape_string($_COOKIE["username"]).'\',\''.mysql_escape_string($_POST['title']).'\',\''.mysql_escape_string($_POST['skill']).'\',\''.mysql_escape_string($_POST['p&f']).'\',\''.mysql_escape_string($_POST['guide']).'\')';




mysql_close($con);
?>



can you please tell me what i did wrong?

UnlimitedMB
08-02-2007, 11:22 PM
That first $_COOKIE["username"] looks out of place.

destrugter
08-02-2007, 11:43 PM
what do you mean? where should i place it?

UnlimitedMB
08-03-2007, 02:11 PM
Do i really have to write every line of code for you to understand?

Look at
mysql_query("INSERT INTO SkillGuides (`$_COOKIE["username"]`,`title`,`skill`,`p&f`,`guide`)

Now what is out of place here???

destrugter
08-03-2007, 09:05 PM
umm...i should change it to `author` instead and have the value as cookie?

UnlimitedMB
08-03-2007, 09:07 PM
yes if thats what your row name is called.

destrugter
08-03-2007, 09:32 PM
EDIT!-Ok, i figured out what my problem was, and it worked and it printed my echo command of "guide added to database" but when i use the display db code and display it it wont show up as being entered in there =/ i dont know what is wrong, here is my display db code.


<?php
$con = mysql_connect("mysql","cheese","pizza");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("cheese", $con);

$result = mysql_query("SELECT * FROM Skills");

echo "<table border='1'>
<tr>
<th>Author</th>
<th>Skill</th>
<th>P2P or F2P</th>
<th>Title</th>
<th>Guide</th>
</tr>";while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row ['author'] . "</td>";
echo "<td>" . $row ['skill'] . "</td>";
echo "<td>" . $row ['p&f'] . "</td>";
echo "<td>" . $row ['title'] . "</td>";
echo "<td>" . $row ['guide'] . "</td>";
echo "</tr>";
}
echo "</table>";mysql_close($con);
?>


everything looks fine to me, i compared it to the tutorial on w3schools i am using, and compared it to my insert code to see if im making it fetch the right information and everything seems to be in place.

UnlimitedMB
08-05-2007, 02:39 AM
Stop putting spaces before the [
Its $row['author'] NOT $row ['author']
This is very important.