Jump to content

INSERT help


helpmeplease2

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.  :)
Link to comment
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.
Link to comment
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]
Link to comment
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?
Link to comment
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]
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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