Jump to content


Photo

INSERT help


  • Please log in to reply
9 replies to this topic

#1 helpmeplease2

helpmeplease2
  • Members
  • PipPipPip
  • Advanced Member
  • 87 posts

Posted 26 August 2006 - 04:57 PM

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

<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>

newfile.php:

<?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')");
?>

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

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 26 August 2006 - 05:00 PM

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.
Legend has it that reading the manual never killed anyone.
My site

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 August 2006 - 05:02 PM

Add or die(mysql_error(); to the end of this:
mysql_query("INSERT INTO downloads (name, desc, pic, type, link) VALUES ('$name','$desc/n/n$format/n$size','$pic','$type','$link')");

So its now this:
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());

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`

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());


#4 helpmeplease2

helpmeplease2
  • Members
  • PipPipPip
  • Advanced Member
  • 87 posts

Posted 26 August 2006 - 05:11 PM

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

#5 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 26 August 2006 - 05:21 PM

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


Line 25? How strange. The newfile.php you posted has less than a dozen lines.  Is there more of it we're not seeing?
Legend has it that reading the manual never killed anyone.
My site

#6 helpmeplease2

helpmeplease2
  • Members
  • PipPipPip
  • Advanced Member
  • 87 posts

Posted 26 August 2006 - 05:50 PM

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.

#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 26 August 2006 - 05:58 PM

OK, which of the eight lines of newfile.php is line 25?
Legend has it that reading the manual never killed anyone.
My site

#8 helpmeplease2

helpmeplease2
  • Members
  • PipPipPip
  • Advanced Member
  • 87 posts

Posted 26 August 2006 - 07:00 PM

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.

<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>

newfile.php:
<?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());
?>


#9 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 August 2006 - 09:16 PM

This:
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());

Should be this:
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());


#10 helpmeplease2

helpmeplease2
  • Members
  • PipPipPip
  • Advanced Member
  • 87 posts

Posted 27 August 2006 - 01:00 AM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users