Note that there are some explanatory texts on larger screens.

plurals
  1. POError with simple PHP form with MySQL
    primarykey
    data
    text
    <p>Sirs,</p> <p>I'm getting an error from my PHP script, probably the query, but I can't figure out what's going on. I can connect the database, but I still get the error from de "echo ERROR" line.</p> <p>Does anyone know what's wrong with my code? I appreciate any help! I spent a few hours to solve this issue, but couldn't get nothing.</p> <p><strong>HTML form</strong></p> <pre><code>&lt;form action="insert-info.php" method="post"&gt; &lt;input class="form1" type="text" value="TEXT ONE" name="textone" onfocus="if (this.value=='NTEXT ONE') this.value='';"/&gt; &lt;input class="form1" type="text" value="TEXT TWO" name="texttwo" onfocus="if (this.value=='TEXT TWO') this.value='';"/&gt; &lt;input class="form2" type="text" value="TEXT THREE" name="textthree" onfocus="if (this.value=='TEXT THREE') this.value='';"/&gt; &lt;/form&gt; </code></pre> <p><strong>Database connect and insert</strong></p> <pre><code>&lt;?php $host="localhost"; // Host name $username="***"; // Mysql username $password="***"; // Mysql password $db_name="***"; // Database name $tbl_name="insertinfo"; // 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 $textone=$_POST['textone']; $texttwo=$_POST['texttwo']; $textthree=$_POST['textthree']; // Insert data into mysql $sql="INSERT INTO $tbl_name('textone', 'texttwo', 'textthree') VALUES ('$textone', '$texttwo', '$textthree')"; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; echo "&lt;br /&gt;"; echo "&lt;a href='insert.php'&gt;Back to main page&lt;/a&gt;"; } else { echo "ERROR"; } ?&gt; &lt;?php // close connection mysql_close(); ?&gt; </code></pre> <p><strong>Database structure</strong></p> <pre><code># Type Collation Null Pattern Extra 1 id int(4) None (none) AUTO_INCREMENT 2 textone varchar(50) utf8_bin None (none) 3 texttwo varchar(50) utf8_bin None (none) 4 textthree varchar(50) utf8_bin None (none) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload