Page 2 of 2
Re: Troubles with PHP code - trying to post to mySQL
Posted: Mon Jan 25, 2010 9:56 am
by AbraCadaver
That function is used to get the last id that was inserted. If the id in that table is an auto increment then you don't supply it. Remove that line and remove the id references in your query.
Re: Troubles with PHP code - trying to post to mySQL
Posted: Mon Jan 25, 2010 12:30 pm
by etech
Excellent, I did that. Does anyone know of the code I would need to add to get what I requested on my last post?
Re: Troubles with PHP code - trying to post to mySQL
Posted: Mon Jan 25, 2010 1:56 pm
by etech
Just checked...the form is no longer giving me errors, but at the same time, it's also not posting to my SQL Database. Any reasons this would be happening?
Code:
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$username = $_POST['username'];
$password = $_POST['pwd'];
$hear = $_POST['hear'];
$empbus = $_POST['empbus'];
$favtravel = $_POST['favtravel'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$resourceId = mysql_connect('localhost','root','probiz123');
mysql_select_db('blueplanet',$resourceId);
$query = "INSERT INTO users (`username`,`password`,`address1`,`address2`,`city`,`state`,`zip`,`email`,`hear`,`empbus`,`favtravel`,`phone`) VALUES ('$username','$password','$address1','$address2','$city','$state','$zip','$email','$hear','$empbus','$favtravel','$phone')";
mysql_query($query);
mysql_close();
?>
Re: Troubles with PHP code - trying to post to mySQL
Posted: Mon Jan 25, 2010 2:21 pm
by AbraCadaver
Code: Select all
$result = mysql_query($query) or die(mysql_error());
Re: Troubles with PHP code - trying to post to mySQL
Posted: Wed Jan 27, 2010 2:25 pm
by etech
I did this, but it's still simply not posting to MySQL, and I am getting the following error:
"Out of range value for column 'phone' at row 1"
What would be the cause of this?
Re: Troubles with PHP code - trying to post to mySQL
Posted: Wed Jan 27, 2010 2:44 pm
by AbraCadaver
etech wrote:I did this, but it's still simply not posting to MySQL, and I am getting the following error:
"Out of range value for column 'phone' at row 1"
What would be the cause of this?
The data type and/or the length of the `phone` column is not big enough to hold what you are trying to insert.
Re: Troubles with PHP code - trying to post to mySQL
Posted: Fri Jan 29, 2010 3:49 pm
by etech
I've got everything working now! But one more question, how do I have the form do a check against the database for similar usernames and email addresses?
Re: Troubles with PHP code - trying to post to mySQL
Posted: Fri Jan 29, 2010 5:37 pm
by AbraCadaver
etech wrote:I've got everything working now! But one more question, how do I have the form do a check against the database for similar usernames and email addresses?
Do a select query for the username OR email. If it returns rows then they already exist and you can display an error or something.