Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

PHP to MySQL database woes :(!!

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

PHP to MySQL database woes :(!!

Postby PaulBoland » Sat Dec 29, 2012 6:25 pm

Hi Folks.

I have a college assignment to do, deadline next week 4th January. It's a website linked to a MySQL database created in XAMPP. I'm using PHP to handle the data being passed from the webform but after three days of coding and recoding and Recoding and RECODING the PHP file, it is just not working! Not only is my database table remaining empty, but the PHP is not even responding with giving back error messages as to why things are not working!

I'm sorry to say it, long story, but the college has a lot to answer for with regards to the problems I'm experiencing. Despite having a PHP project land on my lap, the college did NOT teach PHP and I had to spend time and money in trying to learn it. It has NOT been fun, I'm not confident in my knowledge of the language, and I'm very annoyed at the college over this whole situation!

Since my PHP is not working, not even responding to tell me why it's not working, and time running out, I'm now trying to get help. Below are my two files:

Register.htm:
...
...
...
<form action="Insert.php" method="post">
<p>
<strong>Email Address:</strong><br />
<input type="text" name="email" /></p>
<p>
<strong>Password:</strong><br />
<input type="password" name="password" /></p>
<p>
<input type="button" name="register" value="Register" /></p>
</form>
...

Insert.php:
<?php
//Initiate the database.
$mysqli = new mysqli();
//Connect to the database.
$mysqli->connect("127.0.0.1","ofuser","ofpw");
//Select the Our Family database.
$mysqli->select_db("ourfamily");
//Insert the new information
mysql_query("INSERT INTO Login (Email_Address, Password)
VALUES (email, password)");
//Close the database.
mysql_close($mysqli);
?>

For some reason this does nothing at all!! A call for help to my fellow classmates saw one of them send me this new PHP code:

<?php
// replace your insert.php file with this
$error = 'Sorry but there seems to have been a problem connecting to our database!';
mysql_connect('localhost', 'ofuser', 'ofpw') or die($error);
$error = 'Sorry but there has been a problem connecting to our database!';
mysql_select_db('ourfamily')or die($error);
mysql_query("INSERT INTO `Login` (Email_Address, Password) VALUES (email, password)"); // I think this might be wrong. Usually when you send a value you need to put $ (dollar sign) before it. But try that anyway.
mysql_close();
?>

This, too, does NOTHING! With zero feedback as to what's going on and a deadline approaching, I need to try and get some answers. Does anyone here have any idea why this is not working??? Or at least give me some idea as to why the PHP doesn't even seem to respond with error messages telling me why it is not working??? It's totally infurating to code and recode over and over again, it not working, but getting no feedback as to WHY it's not working !!

Any input much appreciated.
PaulBoland
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sat Dec 29, 2012 6:22 pm

Re: PHP to MySQL database woes :(!!

Postby Snaek » Mon Dec 31, 2012 1:58 pm

In your register.html file, try changing the code of <input type="button"... to <input type="submit" ...

That may be the problem because currently, the input type button is not doing anything because you don't even have a JS event on it, but that's alright, try changing 'button' to 'submit'.

hope this works.

Edit:

Also, how does how insert.php file know what the user typed in the forms?

Because, you have: mysql_query("INSERT INTO Login (Email_Address, Password) VALUES (email, password)");

and the "VALUES" are email, password, where are you getting these? Im assuming they are the 'names' in your HTML form, but that's not how it works. try this:

insert.php

Code: Select all
// CONNECTION CODE HERE...

$email = $_POST['email']; // << that right there is posting the HTML form's value and putting it in a variable called '$email'
$password = $_POST['password']; // same thing here, but for the password

// INSERT THE NEW INFORMATION HERE...
mysql_query("INSERT INTO Login (Email_Address, Password) VALUES ($email, $password)");
// in the above line, the only thing changed in the variables in the VALUES section.


I think this should solve your problem.

If you have any more problems, feel free to reply here.

Also, write down your code in the code tags given in this editor. Thanks

Hope this helped!
Snaek
New php-forum User
New php-forum User
 
Posts: 11
Joined: Sat Dec 29, 2012 6:02 pm

Re: PHP to MySQL database woes :(!!

Postby PaulBoland » Mon Dec 31, 2012 6:25 pm

Thank You!!!! I had to do a bit of tinkering but I got it to work, you definitely put me in the right direction. Thank You!!!

Code: Select all
<?php
   //Initiate the database.
   $error = 'Problem connecting to the OurFamily database!  ';
   $con = mysql_connect("localhost","ofuser","ofpw") or die($error.mysql_error());
   //Select the Our Family database.
   $error = 'Problem selecting to the OurFamily database!  ';
   mysql_select_db("ourfamily", $con) or die($error.mysql_error());
   //Take in email from form, store in $email.
   $email = $_POST["email"];
   //Take in password from form, store in $password.
   $password = $_POST["password"];
   //Insert the new information into the database.
   $error = 'Problem with the INSERT statement!  ';
   mysql_query("INSERT INTO Login (Email_Address, Password)
   VALUES ('$email', '$password')") or die($error.mysql_error());
   //Close the database.
   mysql_close();
?>
PaulBoland
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sat Dec 29, 2012 6:22 pm

Re: PHP to MySQL database woes :(!!

Postby Snaek » Mon Dec 31, 2012 9:18 pm

It's nice to see that you got it to work!!
Snaek
New php-forum User
New php-forum User
 
Posts: 11
Joined: Sat Dec 29, 2012 6:02 pm

Re: PHP to MySQL database woes :(!!

Postby gether » Tue Jan 01, 2013 5:53 am

glad it worked
User avatar
gether
New php-forum User
New php-forum User
 
Posts: 16
Joined: Tue Dec 25, 2012 7:38 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron