Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

The form I have created does not receive entries.

Here is index.html:

<html>
<body>
<iframe name = "main_frame" src = "http://stelucir.com/entry_ac.php" style = "position:absolute; width:80%; height:70%; left:10%; top:12%;">
</iframe>
<form name="form1" method="post" action="http://stelucir.com/entry_ac.php" target = "main_frame">
<div style = "position:absolute; width:80%; height:5%; left:0%; top:84%;">Image:</div> <input type="text" name="one" id="one" style = "position:absolute; width:80%; height:5%; left:10%; top:83%;"><br>
<div style = "position:absolute; width:80%; height:5%; left:0%; top:89%;">Part Descr:</div><input type="text" name="two" id="two" style = "position:absolute; width:80%; height:5%; left:10%; top:88%;"><br>
<div style = "position:absolute; width:80%; height:5%; left:0%; top:94%;">Email:</div>  <input type="text" name="three" id="three" style = "position:absolute; width:80%; height:5%; left:10%; top:93%;">
<input type="submit"  name="Submit" value="Submit" style = "position:absolute; height:5%; left:90%; top:93%;">
</form>
</body>
</html> 

Here is entry_ac.php:

<?php

$host="mysql7.namesco.net"; // Host name
$username="djangofawkes"; // Mysql username
$password="mypass"; // Mysql password
$db_name="PH392701_corpses"; // Database name
$tbl_name="part"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form
$one=$_POST['one'];
$two=$_POST['two'];
$three=$_POST['three'];

// Insert data into mysql
$sql="INSERT INTO $tbl_name(one, two, three)VALUES('$one', '$two', '$three')";
$result = mysql_query("SELECT one, two, three FROM part");

//loops through results
echo "<table border='1'>"; 
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr><td>";
    echo $row['one'];
    echo "</td><td>";
    echo $row['two'];
    echo "</td><td>";
    echo $row['three'];
    echo "</td></tr>"; 
}
echo "</table>"; 
mysql_free_result($result);
?>

<?php
// close connection
mysql_close();
?>

In phpmyadmin in the mysql database I input:

CREATE TABLE `test_mysql` (
`id` int(4) NOT NULL auto_increment,
`one` varchar(65) NOT NULL default '',
`two varchar(65) NOT NULL default '',
`three` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=0 ;

When I input into the form it does not display the results of the database, the problem seems to be that it does not go into the database at all as the loop seems to work. It does however go into the database on localhost and works partially. On localhost, the loop works as well. Plz help.

share|improve this question
    
does it insert data properly??? –  Manish Jangir May 18 '13 at 13:39
    
just in case, DO NOT give your db informations! –  rcpayan May 18 '13 at 13:40
add comment

closed as too localized by John Conde, andrewsi, rekire, brasofilo, dda May 19 '13 at 6:04

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

3 Answers

You put the SQL query into $sql, but you haven't actually run the query...

Look here: http://www.w3schools.com/php/php_mysql_insert.asp

share|improve this answer
add comment

You are not executing your INSERT query

$sql="INSERT INTO $tbl_name(one, two, three)VALUES('$one', '$two', '$three')";

Just add after

$mysql = mysql_query($sql) or die(mysql_error());

Then I would like to remember you that mysql_ functions are deprecated so i would advise you to switch to mysqli or PDO and indeed you are at risk of sql injection, have a look here How to prevent SQL injection in PHP?. You should use prepared statment to avoid any risk

share|improve this answer
add comment

Note that you do not issue (forgot?) the INSERT command...

// Insert data into mysql
$sql="INSERT INTO $tbl_name(one, two, three)VALUES('$one', '$two', '$three')";
$result = mysql_query("SELECT one, two, three FROM part");
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.