Troubles with PHP code - trying to post to mySQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Troubles with PHP code - trying to post to mySQL

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
etech
Forum Newbie
Posts: 11
Joined: Fri Jan 22, 2010 8:26 am

Re: Troubles with PHP code - trying to post to mySQL

Post 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?
etech
Forum Newbie
Posts: 11
Joined: Fri Jan 22, 2010 8:26 am

Re: Troubles with PHP code - trying to post to mySQL

Post 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();
?>
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Troubles with PHP code - trying to post to mySQL

Post by AbraCadaver »

Code: Select all

$result = mysql_query($query) or die(mysql_error());
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
etech
Forum Newbie
Posts: 11
Joined: Fri Jan 22, 2010 8:26 am

Re: Troubles with PHP code - trying to post to mySQL

Post 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?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Troubles with PHP code - trying to post to mySQL

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
etech
Forum Newbie
Posts: 11
Joined: Fri Jan 22, 2010 8:26 am

Re: Troubles with PHP code - trying to post to mySQL

Post 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?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Troubles with PHP code - trying to post to mySQL

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply