Why isnt the information going into the MYSQL dtaabase?

Soldato
Joined
10 May 2004
Posts
3,759
Location
East Yorkshire, UK
Hi

I am using this code to send my form into a MYSQL database

Code:
    <?php
  } else {
  $email = $_POST['email'];
  $username = $_POST['username'];
  $password = $_POST['password'];
  $titles = $_POST['titles'];
  $forename = $_POST['forename'];
  $othernames = $_POST['othernames'];
  $addressline1 = $_POST['addressline1'];
  $addressline2 = $_POST['addressline2'];
  $addressline3 = $_POST['addressline3'];
  $city = $_POST['city'];
  $county = $_POST['county'];
  $postcode = $_POST['postcode'];
  $homenumber = $_POST['homenumber'];
  $mobile = $_POST['mobile'];
  $credit = $_POST['credit'];
  $creditnumber = $_POST['creditnumber'];
  $sortcode = $_POST['sortcode'];
  mysql_query("INSERT INTO 'form' (email, username, password, titles, forename, othernames, addressline1, addressline2, addressline3, city, county, postcode, homenumber, mobile, credit, creditnumber, sortcode) VALUES ('$email', '$username', '$password', '$titles', '$forename', '$othernames', '$addressline1', '$addressline2', '$addressline3', '$city', '$county', '$postcode', '$homenumber', '$mobile', '$credit', '$creditnumber', '$sortcode')");
  echo "Thank You! You have sucessfully submitted for hosting from Infra-One Solutions";
  }
  ?>

however it will not go into the database, here is a link to the picture of the database



any ideas?
Thanks
 
Unless you have put it somewhere else which you might have, you need to connect to the database first.
i.e:
Code:
mysql_connect(localhost,"username","password") or die("Unable to connect");
@mysql_select_db("database_name") or die( "Unable to select database");

// query code

mysql_close();

EDIT: also try running you query with some test values in phpmyadmin to check its correct, maybe also worth echoing the varibles to check there values arnt empty or anything before there added.

Failing that, make sure you add error checking to your code so that you know whats going wrong, i think mysql_error() will display the error information.
 
Last edited:
this is what I used to connect to the database

Code:
<?php
$db_host = "localhost";
$db_user = "watotron_infraon";
$db_pwd = "12345";
$db_name = "watotron_infraone";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
?>


EDIT]
Tried inserting manually in PHP MYADMIn, I can insert data fine
 
Last edited:
tntcode, I just tried using your connect code and get this error when i press submit

Warning: mysql_query(): Access denied for user 'watotron'@'localhost' (using password: NO) in /home/watotron/public_html/School/Project/InfraOne/signup.php on line 224

Warning: mysql_query(): A link to the server could not be established in /home/watotron/public_html/School/Project/InfraOne/signup.php on line 224
 
Use:
Code:
<?php
$conn = mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
mysql_select_db($db_name,$conn) or die(mysql_error());
?>
And:
Code:
$result = mysql_query("INSERT INTO 'form' (email, username, password, titles, forename, othernames, addressline1, addressline2, addressline3, city, county, postcode, homenumber, mobile, credit, creditnumber, sortcode) VALUES ('$email', '$username', '$password', '$titles', '$forename', '$othernames', '$addressline1', '$addressline2', '$addressline3', '$city', '$county', '$postcode', '$homenumber', '$mobile', '$credit', '$creditnumber', '$sortcode')");

if(!$result) {
   die(mysql_error());
} else {
   echo "Seems to have worked. Whoo.";
}
 
Im getting this now, cannot even fine $end
Parse error: syntax error, unexpected $end in /home/watotron/public_html/School/Project/InfraOne/signup.php on line 238

Just wondering if it would be easier if I post the full source code?


Freak_boy said:
why is your query havent got the $ signs infront of the variables? also you have to do '$email','$username' etec etc

in the database in PHPMYADMIN?
 
Ok the first thing is that you HAVEN'T closed the main conditional. The one that starts with

Code:
if (!isset($_POST['submit'])) {

That hasn't been closed but it should be closed here

Code:
} else {
   echo "Seems to have worked. Whoo.";
}
?>
  </p>
</div>
[b]}[/b]

This is at the end of the file.

Check your DB user. You might of missed off the e on $db_user = "watotron_infraon";


It should work after that. If you get the 'Parse error: syntax error, unexpected $end in /home/watotron/public_html/School/Project/InfraOne/signup.php on line 238' error, it means that you haven't closed a conditional statement :)
 
Post #11 meant that you should change this:

Code:
} else {
   echo "Seems to have worked. Whoo.";
}
?>
  </p>
</div>
  }
To this:
Code:
} else {
   echo "Seems to have worked. Whoo.";
}
}
?>
  </p>
</div>
The } was outside the PHP tags :)
 
Ok that ones now sorted :)

but get this error when I submit

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''form' (email, username, password, titles, forename, othernames, addressline1, a' at line 1
 
Back
Top Bottom