Jump to content


Photo

PHP Form to Mysql


  • Please log in to reply
5 replies to this topic

#1 oceansurfer230

oceansurfer230
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 10 October 2006 - 10:48 PM

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

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;

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

<?
$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.";
?>

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:

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


#2 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 10 October 2006 - 11:02 PM

Your insert statement is wrong.  Look here for correct syntax:  http://dev.mysql.com.../en/insert.html

mainly this line here:

INSERT INTO tbl_name (col1,col2) VALUES(15,col1*2);

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

Here, edited to encompass your 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')");


#3 Firemankurt

Firemankurt
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts
  • LocationWashington State

Posted 10 October 2006 - 11:07 PM

Couple simple things to help find your problem

add this while debuging:
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.";


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

#4 oceansurfer230

oceansurfer230
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 10 October 2006 - 11:37 PM

I made the corrections you said but it still isn't working.... :(

#5 oceansurfer230

oceansurfer230
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 11 October 2006 - 12:15 AM

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.

#6 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 11 October 2006 - 07:35 PM

As long as you put in the code I gave, it should work. I don't get any errors with it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users