Jump to content

Archived

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

helpmeplease2

INSERT help

Recommended Posts

I made this form to insert data into a mysql database but its not working. Its not giving me any error messages either.

[code]<form action="?p=newfile" method="post" style="margin:0px">
<strong>File Details:</strong>
<br>
<table border="0" cellspacing="1" cellpadding="0">
<tr>
<td>Title/Name </td>
<td><input type="text" name="name" size="30"></td>
</tr>
<tr>
<td colspan="2">Description </td>
</tr>
<tr>
<td colspan="2"><textarea name="desc" rows="7" cols="35"></textarea></td>
</tr>
<tr>
<td>Type </td>
<td>
<select name="type" size="1">
<option value="1">type1</option>
<option value="2">type2</option>
</select>
</td>
</tr>
<tr>
<td>Link </td><td><input type="text" name="link" size="30" value="downloads/"></td>
</tr>
<tr>
<td>Format </td><td><input type="text" name="format" size="30"></td>
</tr>
<tr>
<td>Size </td><td><input type="text" name="size" size="30"></td>
</tr>
<tr>
<td>Picture </td><td><input type="text" name="pic" size="30" value="images/"></td>
</tr>
<tr>
<td></td><td><button type="submit">Add file!</button></td>
</tr>
</table>[/code]

newfile.php:

[code]<?php
$name=$_POST['name'];
$pic=$_POST['pic'];
$format=$_POST['format'];
$size=$_POST['size'];
$type=$_POST['type'];
$link=$_POST['link'];
$desc=$_POST['desc'];
mysql_query("INSERT INTO downloads (name, desc, pic, type, link) VALUES ('$name','$desc/n/n$format/n$size','$pic','$type','$link')");
?>[/code]

Whats wrong with my code? Help is appreciated.  :)

Share this post


Link to post
Share on other sites
DESC is a MySQL reserved word and definitely should NOT be used as a column name.  I'd suggest you change it to descr.

And if you're not getting any error messages, 'someone' has turned them off because that query would definitely generate an error.

Share this post


Link to post
Share on other sites
Add or die(mysql_error(); to the end of this:
[code]mysql_query("INSERT INTO downloads (name, desc, pic, type, link) VALUES ('$name','$desc/n/n$format/n$size','$pic','$type','$link')");[/code]

So its now this:
[code]mysql_query("INSERT INTO downloads (name, desc, pic, type, link) VALUES ('$name','$desc/n/n$format/n$size','$pic','$type','$link')") or die(mysql_errot());[/code]

However I think its becuase you have a coloumn name called desc and desc is a reserver MySQL keyword. use backticks around the desc so its this:
`desc`

[code]mysql_query("INSERT INTO downloads (name, `desc`, pic, type, link) VALUES ('$name','$desc/n/n$format/n$size','$pic','$type','$link')") or die(mysql_errot());[/code]

Share this post


Link to post
Share on other sites
I changed desc to descr everywhere and its doing the same thing as before. I added the mysql_error code and I'm getting this:

Parse error: parse error, unexpected T_LOGICAL_OR in /home/www/includes/newfile.php on line 25

Share this post


Link to post
Share on other sites
[quote author=helpmeplease2 link=topic=105725.msg422458#msg422458 date=1156612267]
Parse error: parse error, unexpected T_LOGICAL_OR in /home/www/includes/newfile.php on line 25
[/quote]

Line 25? How strange. The newfile.php you posted has less than a dozen lines.  Is there more of it we're not seeing?

Share this post


Link to post
Share on other sites
Thats the full newfile.php file. The only stuff I'm not showing you at the moment is in index.php which just contains html layout and the mysql connection.

Share this post


Link to post
Share on other sites
OK, which of the eight lines of newfile.php is line 25?

Share this post


Link to post
Share on other sites
YTM, notepad says "line number out of range".

Edit: I opened newfile.php in wordpad instead of notepad and there were extra blank lines, I removed them and the error says its on line 10 now. Here are my updated files.

[code]<br>
All fields must be filled.<br><br>


<form action="?p=newfile" method="post" style="margin:0px">

<strong>File Details:</strong>
<br>

<table border="0" cellspacing="1" cellpadding="0">

<tr>
<td>Title/Name </td>
<td><input type="text" name="name" size="30"></td>
</tr>

<tr>
<td colspan="2">Description </td>
</tr>
<tr>
<td colspan="2"><textarea name="descr" rows="7" cols="35"></textarea></td>
</tr>
<tr>
<td>Type </td>
<td>
<select name="type" size="1">
<option value="1">type1</option>
<option value="2">type2</option>
<option value="3">type3</option>
<option value="4">type4</option>
<option value="5">type5</option>
<option value="6">type6</option>
</select>

</td>
</tr>
<tr>
<td>Link </td><td><input type="text" name="link" size="30" value="downloads/"></td>
</tr>
<tr>
<td>Format </td><td><input type="text" name="format" size="30"></td>
</tr>
<tr>
<td>Size </td><td><input type="text" name="size" size="30"></td>
</tr>
<tr>
<td>Picture </td><td><input type="text" name="pic" size="30" value="images/"></td>
</tr>
<tr>
<td></td><td><button type="submit">Add file!</button></td>
</tr>
</table>
</form>[/code]

newfile.php:
[code]<?php
$name=$_POST['name'];
$pic=$_POST['pic'];
$format=$_POST['format'];
$size=$_POST['size'];
$type=$_POST['type'];
$link=$_POST['link'];
$descr=$_POST['descr'];
mysql_query("INSERT INTO downloads (name, descr, pic, type, link) VALUES ('$name','$descr/n/n$format/n$size','$pic','$type','$link')");
or die(mysql_error());
?>[/code]

Share this post


Link to post
Share on other sites
This:
[code]mysql_query("INSERT INTO downloads (name, descr, pic, type, link) VALUES ('$name','$descr/n/n$format/n$size','$pic','$type','$link')");
or die(mysql_error());[/code]

Should be this:
[code]mysql_query("INSERT INTO downloads (name, descr, pic, type, link) VALUES ('$name','$descr/n/n$format/n$size','$pic','$type','$link')") or die(mysql_error());[/code]

Share this post


Link to post
Share on other sites
Ok thanks, after I changed that code I received an error saying it couldn't find the column named 'type', it should have been 'cat'. Well its working now, thanks for everything wildteen88 and AndyB!

Share this post


Link to post
Share on other sites

×

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.