Friday, 15 July 2011

mysql - Issue in storing data into database in php -



mysql - Issue in storing data into database in php -

i have created register form using php , jquery. need store input details sql database.

i created config.php , included in index.php , submit.php file.

but still didn't store in database, may know error in config.php code, can please help me?

this config.php:

<?php $mysql_hostname = "localhost"; $mysql_user = "root"; $mysql_password = ""; $mysql_database = "crop"; $prefix = ""; $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) die('could not connect: ' . mysql_error()); mysql_select_db($mysql_database, $bd) or die('could not connect: ' . mysql_error()); ?>

and code_exec.php:

<?php session_start(); include('config.php'); $fname=$_post['fname']; $lname=$_post['lname']; $email=$_post['email']; $pass=$_post['pass']; $sex_select=$_post['sex_select']; $month=$_post['month']; $day=$_post['day']; $year=$_post['year']; $result = mysql_query("insert crop(fname, lname, email, pass,`sex_select`, month,day,year) values ('$fname', '$lname', '$email', '$pass','$sex_select', '$month','$day','$year')"); if (!$result) { die('invalid query: ' . mysql_error()); } ?>

as per your posted question has been edited:

firstly, using hyphen sex-select column.

mysql thinking want math equation translates to:

sex (minus) select.

wrap in backticks , missing column photo

(fname, lname, email, pass, phone, photo, `sex-select`, month,day,year) ^^^^^^ missing column

having used mysql_error() mysql_query() have signaled error.

also $sex-select needs $sex_select not utilize hyphens variables also.

so alter of instances $sex_select in values also.

('$fname', '$lname', '$email', '$pass', '$phone', '$photo', '$sex_select', '$month','$day','$year')

i noticed both db , table named crop.

$mysql_database = "crop";

and

mysql_query("insert crop...

one of may incorrect. create sure db name should be, along table. doesn't right me, wrong. know called.

plus mysql_close($con); should mysql_close($bd); since you're using $bd = mysql_connect

add error reporting top of file(s) help during production testing.

error_reporting(e_all); ini_set('display_errors', 1);

which have signaled error also, not doing, checking errors. of import during development.

edit: db connection error checking:

instead of:

$mysql_hostname = "localhost"; $mysql_user = "root"; $mysql_password = ""; $mysql_database = "crop"; $prefix = ""; $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("could not connect database"); mysql_select_db($mysql_database, $bd) or die("could not select database");

use next grab errors, should there any. using die("could not connect database") not enough.

if crop not database, mysql tell you.

<?php $bd = mysql_connect('localhost', 'root', ''); if (!$bd) { die('not connected : ' . mysql_error()); } // create foo current db $db_selected = mysql_select_db('crop', $bd); if (!$db_selected) { die ('can\'t utilize foo : ' . mysql_error()); }

same query:

$result = mysql_query("insert crop(fname, lname, email, pass, phone, photo, `sex-select`, month,day,year) values ('$fname', '$lname', '$email', '$pass', '$phone', '$photo', '$sex-select', '$month','$day','$year')"); if (!$result) { die('invalid query: ' . mysql_error()); }

plus, per html form:

<select name="sex-select" id="sex-select">

should be

<select name="sex_select" id="sex-select">

php mysql

No comments:

Post a Comment