While it is not showing any errors that I can see, my input from an HTML form is not working. I copied part of the script from Visual QuickPro Guide book on PHP 6 and MYSQL 5. I only had one input , so I modified the script for my uses. My database name is mytestdayabse, the table is userdata, and I have two columns called name and email. I just wanted to post a name. Here is the code for each script:
Morning.HTML :

<html>
  <head><title></title></head>
  <body>
  <form action="php_handler.php" method="post">
  <p>Name:
  <input type="text" name="name" size="20" maxlength="20" />
  <p><select name="occupation">
  <option value="service">Customer Service </option>
  <input type="submit" name="y" value="submit my data" /></body>
  </html>

php_handler.php:

<?php

  if (isset($_POST['submit'])){
  $fn=trim($_POST['name']);
  $errors=array();

  if(empty($_POST['name']))
  {

  $errors[]="You forgot to enter a name";
  }
  else {$fn=trim($_POST['name']);}

  if (empty($errors))
  {
  require_once('/mysqli_connect.php');
  $q="INSERT INTO userdata ('name') VALUES('$fn')";
  $r=mysqli_query($dbc,$q);
  if($r)
  {
  echo"Thank you!";
  }
  else
  {
  echo"System Error";
  }
  mysqli_close($dbc);
  exit();
  }
  }
  ?>

mysqli_connect.php:

 <?php 

  DEFINE ('DB_USER','root');
  DEFINE ('DB_PASSWORD','');
  DEFINE ('DB_HOST','localhost');
  DEFINE ('DB_NAME','mytestdatabase');
  $dbc=mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME) or die ('could not connect to DB'. mysqli_error());

  ?>

By the way I know I will need to change root, it is just I am having a hard time changing privleges for another account. I am using the zwamp environment, and everything is working to my knowledge. It just shows a blank page, which confuses me. Any thoughts? Thanks.

html line 9

<input type="submit" name="y" value="submit my data" />

Your submit-button is called 'y' not submit
either change that line or your php_handler.php line 3:

if (isset($_POST['y'])){

Now it is setting it to error. Would that be on the DB side? I set it to root, so there should not be any issue, as far as I can see. I set the values to X and Y originally to see if it were the variables or what the issue was with it originally.

What do you means by 'Now it is setting it to error'? Is it the connection error or the querying error?
What my suggestion are, change your codes to show more specific errors:

<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?>

and

if (!mysqli_query($dbc,$q)){
    echo("Query error: " . mysqli_error($con));
}

With these code, you can see the detail of the problem and may help you to solve it more easily.

Thank you. It did not show any connection errors, so it must be query errors. DB Image. I don't see anything overly weird. Anything that sticks out? Do I need to include other things as well, or can include only the name variable?

Your database structure does not allowed the 'email' field to be null, that's why when you execute query of $q="INSERT INTO userdata ('name') VALUES('$fn')";, database tempt to insert null into email field which causing errors.

I changed the state to null, and it still is not working. Could it be faulty envirnoment? I even tested by placing a null value in the DB and it allowed it. I am running out of explanations.

Try changing your query into $q="INSERT INTO userdata (name,email,pass) VALUES('$fn','','')"; see if it work. BTW, did anything returned from echo("Query error: " . mysqli_error($con));?

No. That is the weird thing too. Nothing show up error wise besides the standard if else error for $r.

LOL I figured it out. I placed '' around the variable name for MYSQL lol. Thank you for getting me on the right track :) .

Please review your statement again, the userdata (name) instead of userdata ('name')

That is what I was saying. As soon as I read your post I realized I flubbed. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.