Jump to content

PHP Form to Mysql


oceansurfer230

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]
Link to comment
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]
Link to comment
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.
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.