Jump to content

Archived

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

oceansurfer230

PHP Form to Mysql

Recommended Posts

Well I'm not really sure why this isn't working but it definitly isn't.

[code]CREATE TABLE `guides` (
  `title` varchar(255) NOT NULL default '',
  `summary` text NOT NULL,
  `screenshot` varchar(255) NOT NULL default '',
  `content` text NOT NULL,
  `overallrating` varchar(3) NOT NULL default '',
  `media` varchar(255) NOT NULL default '',
  `gameplay` varchar(1) NOT NULL default '',
  `graphics` varchar(1) NOT NULL default '',
  `sound` varchar(1) NOT NULL default '',
  `value` varchar(1) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1;[/code]

The above is the mysql database I am using to store the form data. Here is the page I am using to process it:

[code]<?
$host = 'localhost';
$user = 'XXXXX';
$pass = 'XXXXX';
$db = 'XXXXX';
$table = 'guides';
$title=$_POST['title'];
$summary=$_POST['summary'];
$screenshot=$_POST['screenshot'];
$content=$_POST['content'];
$overallrating=$_POST['overallrating'];
$media=$_POST['media'];
$gameplay=$_POST['gameplay'];
$graphics=$_POST['graphics'];
$sound=$_POST['sound'];
$value=$_POST['value'];
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
mysql_query("INSERT INTO 'guides' VALUES ('$title','$summary','$screenshot','$content','$overallrating','$media','$gameplay','$graphics','$sound','$value')");
Print "Your information has been successfully added to the database.";
?>[/code]

The problem is that the data is not being inserted into the database. I sure the form is correct but just incase here it is too:

[code]<form method='post' action='process.php'>

Title:<input type="Text" name="title" size="100" value=""><br><br>

Summary:<textarea name="summary" cols="100" rows="10" value=""></textarea><br><br>

Screenshot:<input type="Text" name="screenshot" size="100" value=""><br><br>

Content:<textarea name="content"  cols="100" rows="20" value=""></textarea><br><br>

Overall Rating:<input type="Text"  size="10" name="overallrating" value=""><br><br>

Media:<input type="Text"  size="100" name="media" value=""><br><br>

Gameplay:<select name="gameplay" value="">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
  <option>6</option>
  <option>7</option>
  <option>8</option>
  <option>9</option>
  <option>10</option>
</select><br><br>

Graphics:<select name="graphics" value="">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
  <option>6</option>
  <option>7</option>
  <option>8</option>
  <option>9</option>
  <option>10</option>
</select><br><br>

Sound:<select name="sound" value="">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
  <option>6</option>
  <option>7</option>
  <option>8</option>
  <option>9</option>
  <option>10</option>
</select><br><br>

Value:<select name="value" value="">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
  <option>6</option>
  <option>7</option>
  <option>8</option>
  <option>9</option>
  <option>10</option>
</select><br><br>

<input type='hidden' name='submitted' value='set'>

<input type="Submit" name="submit" value="Enter information">

  </form>[/code]

Share this post


Link to post
Share on other sites
Your insert statement is wrong.  Look here for correct syntax:  http://dev.mysql.com/doc/refman/5.0/en/insert.html

mainly this line here:

[code]
INSERT INTO tbl_name (col1,col2) VALUES(15,col1*2);
[/code]

see how they tell the column names, and then list the values for each respectivly?

Here, edited to encompass your code:

[code]
mysql_query("INSERT INTO 'guides' (title,summary,screenshot,content,overallrating,mediat,gameplay,graphics,sound,value) VALUES ('$title','$summary','$screenshot','$content','$overallrating','$media','$gameplay','$graphics','$sound','$value')");[/code]

Share this post


Link to post
Share on other sites
Couple simple things to help find your problem

add this while debuging:
[code]
var_dump($_POST);

...

mysql_select_db($db) or die(mysql_error());
mysql_query("INSERT INTO 'guides' VALUES ('$title','$summary','$screenshot','$content','$overallrating','$media','$gameplay','$graphics','$sound','$value')");
$ErrNum = mysql_errno ();
$ErrText  = mysql_error();
echo "Error : ".$ErrNum."  ".$ErrText;
Print "Your information has been successfully added to the database.";

[/code]

Then you can see what was recieved in the post and then see any MySQL errors.

Share this post


Link to post
Share on other sites
The fixes suggested do not work. The problem is with the MYSQL database. It is written wrong as I don't really know how to write a SQL database.

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.