PDA

View Full Version : mySQL/PHP error



ItchysPaws
25-04-2006, 02:57 PM
Ok, ive made the script to add to the rares DB, managed to do it myself :D but upon 'Add to the DB' i get this error:
Unknown mysql command etc. error blah.

The code is

<?
$host = "localhost";
$user = "habbowi_rares";
$pass = "rares";
$db = "habbowi_rares";
mysql_connect( $host, $user, $pass ) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
if($_POST['submit'])
{
//checks to see if the form was submitted.
$name = $_POST['name'];
$desc = $_POST['desc'];
$pict = $_POST['pict'];
$value = $_POST['value'];
$submitted = $_POST['submitted'];
$notes = $_POST['notes'];
$date = date("F jS, Y");
if($name < 0|$entry==NULL)
{
//a feild was left blank!
echo "The Name field was left out, please fill in.";
}
else
{
//No feilds were left blank, we continue..
$query = mysql_query("INSERT INTO rares (name, desc, pict, value, submitted, notes,
date) VALUES('$name', '$desc', '$pict', '$value', '$submitted', '$notes', '$date')") or die(mysql_error());

echo "The DB has successfully been updated.";
}
}
else
// the form was not submitted now we show it.
{
?>
<html>
<head>
<title>Habbo-wide.net - Site Management</title>
<style type="text/css">
BODY {
<!--
body {
SCROLLBAR-ARROW-COLOR: #7F552B;
SCROLLBAR-BASE-COLOR: #ECC547;
SCROLLBAR-FACE-COLOR: #ECC547;
SCROLLBAR-HIGHLIGHT-COLOR: #FFF3B7;
SCROLLBAR-SHADOW-COLOR: #B17038;
SCROLLBAR-3DLIGHT-COLOR: #FFF3B7;
SCROLLBAR-TRACK-COLOR: #C9BDCC;
SCROLLBAR-DARKSHADOW-COLOR: #B17038;
}
-->
</style>
</head>
<body link="#991815" vlink="#991815" alink="#991815" bgcolor="#ECC547" text="#7F552B">
<font face="Verdana" size="1">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="100%">
<p align="left"><font face="Verdana" size="1"><b><a href="http://www.habbo-wide.net/sitedb" target="_self">Site
Databases</a> &gt; <a href="http://www.habbo-wide.net/sitedb/rares.php" target="_self">Rares</a>
&gt; </b>Adding</font></td>
</tr>
<tr>
<td width="100%">
<p align="center"><font type="Verdana" size="1" face="Verdana"><b>Adding a
Rare</b></font>
</td>
</tr>
</table> </font> <form method="POST">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="11%" align="right">
<p align="right">
<font face="Verdana" size="1">
Name:</font></td>
<td width="89%">
<font face="Verdana" size="1">
<input type="text" size="57" maxlength="25"
name="name"></font></td>
</tr>
<tr>
<td width="11%" align="right">
<font face="Verdana" size="1">
Description:</font></td>
<td width="89%"><font face="Verdana" size="1"><input type="text" size="57" maxlength="25"
name="desc" ></font></td>
</tr>
<tr>
<td width="11%" align="right">
<font face="Verdana" size="1">
Picture:</font></td>
<td width="89%"><font face="Verdana" size="1"><input type="text" size="57" maxlength="25"
name="pict"></font></td>
</tr>
<tr>
<td width="11%" align="right">
<font face="Verdana" size="1">
Rare Value:</font></td>
<td width="89%"><font face="Verdana" size="1"><input type="text" size="3" maxlength="25"
name="value"> CS</font></td>
</tr>
<tr>
<td width="11%" align="right">
<font face="Verdana" size="1">
Submitted by:</font></td>
<td width="89%">
<font face="Verdana" size="1">
<textarea rows="2" name="submitted" cols="48"></textarea></font></td>
</tr>
<font face="Verdana" size="1">
<tr>
<td width="100%" align="right" colspan="2">
<p align="center"><font face="Verdana" size="1">The ID is automactically
assigned upon 'Add to the DB'</font></td>
</font>
</tr>
<font face="Verdana" size="1">
<tr>
<td width="100%" align="right" colspan="2"></td>
</tr>
</font>
<tr>
<td width="100%" align="right" colspan="2">
<p align="center"><b><font face="Verdana" size="2">Staff
Notes; </font></b><font face="Verdana" size="1">Staff dates
must be written in the following format, 3-letter month (Jan,
Feb, Mar), 2-digit day (01-09,10-31), and 4 digit year (2006),
correct date would be 'Apr 24, 2006'</font></td>
</tr>
<font face="Verdana" size="1">
<tr>
<td width="100%" align="right" colspan="2">
<p align="left"><font face="Verdana" size="1"><textarea rows="9" name="notes" cols="80"></textarea></font></td>
</tr>
<tr>
<td width="11%" align="right"></td>
<td width="89%">
<p align="center"><font face="Verdana" size="1"><input name="submit" type="submit" value="Add to the DB">
</td>
</tr>
</table>
</form> </body>
</html>
<?
}
?>



You can see it in action as there isnt an output page atm, to see the error, go to www.habbo-wide.net/rares.php (http://www.habbo-wide.net/rares.php), please note as ssoon as its fixed, link will not work and it will be pw protected.

Sygon.
25-04-2006, 03:03 PM
Means your sql is wrong =]

ItchysPaws
25-04-2006, 03:09 PM
I know, but the thing is i dont know which bit.

Sygon.
25-04-2006, 03:23 PM
I know, but the thing is i dont know which bit.

tell me the tables you want and ill make you a sql code "/

Splinter
25-04-2006, 03:28 PM
Why use mySQL for such as simple task "/ might as well just write it to a flat file db.. its alot easier..

ItchysPaws
25-04-2006, 03:29 PM
I've made all the tables http://img191.imageshack.us/img191/2787/sql2gt.png, its just it wont write to them for some reason?

ItchysPaws
03-05-2006, 03:28 PM
Sorry this is a double post but I really need help guys

Tomm
03-05-2006, 03:38 PM
It might actaully help if you tell us the FULL error.

ItchysPaws
03-05-2006, 03:40 PM
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc, pict, value, submitted, notes, date) VALUES('test', 'test

Tomm
03-05-2006, 04:16 PM
Check your SQL then.

Dentafrice1
03-05-2006, 09:38 PM
LOL He knows that thats the reason he wants help ;o

Arisham
03-05-2006, 10:12 PM
Create a file called mysql_connect.php
in that file, add:


<?
$connect = mysql_connect("localhost","DATABASE USERNAME","DATABASE PASSWORD");
mysql_select_db(DATABASE NAME) or die(mysql_error());
?>

in rares.php, add this code in:



<?
include("mysql_connect.php");
if($_POST['submit'])
{
//checks to see if the form was submitted.
$name = $_POST['name'];
$desc = $_POST['desc'];
$pict = $_POST['pict'];
$value = $_POST['value'];
$submitted = $_POST['submitted'];
$notes = $_POST['notes'];
$date = date("F jS, Y");
if($name < 0|$entry==NULL)
{
//a feild was left blank!
echo "The Name field was left out, please fill in.";
}
else
{
//No feilds were left blank, we continue..
$query = mysql_query("INSERT INTO rares (name, desc, pict, value, submitted, notes,
date) VALUES('$name', '$desc', '$pict', '$value', '$submitted', '$notes', '$date')") or die(mysql_error());

echo "The DB has successfully been updated.";
}
}
else
// the form was not submitted now we show it.
{
?>
<html>
<head>
<title>Habbo-wide.net - Site Management</title>
<style type="text/css">
BODY {
<!--
body {
SCROLLBAR-ARROW-COLOR: #7F552B;
SCROLLBAR-BASE-COLOR: #ECC547;
SCROLLBAR-FACE-COLOR: #ECC547;
SCROLLBAR-HIGHLIGHT-COLOR: #FFF3B7;
SCROLLBAR-SHADOW-COLOR: #B17038;
SCROLLBAR-3DLIGHT-COLOR: #FFF3B7;
SCROLLBAR-TRACK-COLOR: #C9BDCC;
SCROLLBAR-DARKSHADOW-COLOR: #B17038;
}
-->
</style>
</head>
<body link="#991815" vlink="#991815" alink="#991815" bgcolor="#ECC547" text="#7F552B">
<font face="Verdana" size="1">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="100%">
<p align="left"><font face="Verdana" size="1"><b><a href="http://www.habbo-wide.net/sitedb" target="_self">Site
Databases</a> &gt; <a href="http://www.habbo-wide.net/sitedb/rares.php" target="_self">Rares</a>
&gt; </b>Adding</font></td>
</tr>
<tr>
<td width="100%">
<p align="center"><font type="Verdana" size="1" face="Verdana"><b>Adding a
Rare</b></font>
</td>
</tr>
</table> </font> <form method="POST">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="11%" align="right">
<p align="right">
<font face="Verdana" size="1">
Name:</font></td>
<td width="89%">
<font face="Verdana" size="1">
<input type="text" size="57" maxlength="25"
name="name"></font></td>
</tr>
<tr>
<td width="11%" align="right">
<font face="Verdana" size="1">
Description:</font></td>
<td width="89%"><font face="Verdana" size="1"><input type="text" size="57" maxlength="25"
name="desc" ></font></td>
</tr>
<tr>
<td width="11%" align="right">
<font face="Verdana" size="1">
Picture:</font></td>
<td width="89%"><font face="Verdana" size="1"><input type="text" size="57" maxlength="25"
name="pict"></font></td>
</tr>
<tr>
<td width="11%" align="right">
<font face="Verdana" size="1">
Rare Value:</font></td>
<td width="89%"><font face="Verdana" size="1"><input type="text" size="3" maxlength="25"
name="value"> CS</font></td>
</tr>
<tr>
<td width="11%" align="right">
<font face="Verdana" size="1">
Submitted by:</font></td>
<td width="89%">
<font face="Verdana" size="1">
<textarea rows="2" name="submitted" cols="48"></textarea></font></td>
</tr>
<font face="Verdana" size="1">
<tr>
<td width="100%" align="right" colspan="2">
<p align="center"><font face="Verdana" size="1">The ID is automactically
assigned upon 'Add to the DB'</font></td>
</font>
</tr>
<font face="Verdana" size="1">
<tr>
<td width="100%" align="right" colspan="2"></td>
</tr>
</font>
<tr>
<td width="100%" align="right" colspan="2">
<p align="center"><b><font face="Verdana" size="2">Staff
Notes; </font></b><font face="Verdana" size="1">Staff dates
must be written in the following format, 3-letter month (Jan,
Feb, Mar), 2-digit day (01-09,10-31), and 4 digit year (2006),
correct date would be 'Apr 24, 2006'</font></td>
</tr>
<font face="Verdana" size="1">
<tr>
<td width="100%" align="right" colspan="2">
<p align="left"><font face="Verdana" size="1"><textarea rows="9" name="notes" cols="80"></textarea></font></td>
</tr>
<tr>
<td width="11%" align="right"></td>
<td width="89%">
<p align="center"><font face="Verdana" size="1"><input name="submit" type="submit" value="Add to the DB">
</td>
</tr>
</table>
</form> </body>
</html>
<?
}
?>

That might work.

ItchysPaws
04-05-2006, 02:57 PM
Ty so much it works now, next step, how do I get it to retrieve from the DB? eg i want a page rareview.php?id=0001 with id=0001 retrieving 0001 from the DB

Tomm
04-05-2006, 03:04 PM
Since we dont know your database structure we cant help you.

ItchysPaws
04-05-2006, 03:06 PM
There is an image of my structure in page 1, near the bottom, apart from that only other info is the ID is the PRIMARY key, and a auto_increment

Want to hide these adverts? Register an account for free!