PHP/MySql - putting data to table -


i'm learning put values db php. simple form wrote test (its in table)

<form action="connect2db.php" method="post"> <table width="500" border="0">     <tr>         <td width="200">first name:</td>         <td><input type="text" width="258" name="fname" id="fname"/></td>     </tr>     <tr>         <td width="200">last name:</td>         <td><input type="text" width="258" name="lname" id="lname"/></td>     </tr>     <tr>         <td>         email address:          </td>         <td>         <input type="text" width="258" name="email" id="email"/>         </td>     </tr>     <tr>         <td width="200">your message:</td>         <td><textarea rows="5" cols="45" name="mssg" id="mssg" ></textarea></td>     </tr>     <tr>         <td><input type="submit"></td>     </tr> </table> </form> 

everything works far page 1 sending values page 2, , echoing them out. when time insert them db table. not working. php code:

when select * mytablenamehere, says "empty set", when enter values manually via terminal test, values fine.

here simple code:

<?php  $connection = mysql_connect("127.0.0.1","root","passhere");  if(!$connection) {     die("database connection failed fool!: fix it!" . mysql_error()); }    $db_select = mysql_select_db("storeemail",$connection); if(!$db_select){     die("database selection failed." . mysql_error()); }     else{ echo "connection made ";     }  ?>  <!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>untitled document</title> </head>  <body>   <?php $to = 'email@gmail.com'; $subject = 'test email php script'; $email = $_post['email']; $name = $_post['fname']; $lastname = $_post['lname']; $mssg = $_post['mssg'];   $insertdata = mysql_query("insert myusers(firstname, lastname)  values ('$name', '$lastname', '$email', '$mssg');");    mysql_close($connection)   ?><br/>  first name - <?php echo $name; ?><br/> last name - <?php echo $lastname ; ?><br/> message send - <?php echo $mssg; ?> <br/>  </body> </html> 

for can see, specifying 2 columns insert (firstname, lastname) , 4 values (name, lastname, email, msg), column count not match (either insert 2 or 4 values, , specify of them accordingly).

after insert, issue mysql_error($connection) see errors may arise queries


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -