Help with code I´m dessperate !!!!!

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

Post Reply
eddyraz
Forum Newbie
Posts: 2
Joined: Sat Nov 05, 2005 11:45 pm
Contact:

Help with code I´m dessperate !!!!!

Post by eddyraz »

Hi friends i´m about to go crazy with this piece of code i´ve written it makes new users´ registration data be written into a mySQL database . The environment is windows XP Professional apache 1.3.26 PHP 4.2.3 and MySQL 3.23.52 with phpmyadmin 2.3.0 here´s the code Please help me it shows the message Sorry your data couldn´t be inserted into our database , plase check them that I´ve put for exception management but I´ve checked the Mysql code and it´s alright and as soon as i check with phpmyadmin there´s nothing in the tables. I gave permission to the user and it connects but writes nothing into the tables.Pleae help!!!!.


PS I have installed Service pack 2 because i also use MS Vstudio .NET beta 2 and I´ve included the following exceptions in the WXPSP2 personal firewalls thinking this might help but nothing

httpd.exe
mysqld-nt.exe
mysqld-opt.exe

Code: Select all

<?php

//user session start  up 

session_start () ;


//New Users registration data 

$reg_firstname=trim($_POST[´reg_first_name´]);
$reg_lastname=trim($_POST[´reg_last-name]);
$reg_username=trim($_POST[´reg-username´]);
$reg_password=trim($_POST[´reg-password´]);
$reg_email=trim($_POST[´reg_password´]);

// user  sex  choice   

switch ($_POST[´reg_sex´])
{
case "M":
$reg_sex="M";
break;

case "F" :
$reg_sex="F";
break;

default:
 
break;
}


$reg_icq=trim($_POST[´reg_icq´]);
$reg_yahoo_id=trim($_POST[´reg_yahoo_id´]);
$reg_msn_id=trim($_POST[´reg_msn_id´]);

//Variables for the conection to the users table in the asian dreams database

$db_host="localhost";
$db_user="eddy";
$db_password="ishikawa";
$db_name="asiandreams";
$table_name="users";

$link=mysql_connect($db_host,$db_user,$db_password)

or die ("Im sorry the database connection to localhost couldn´t be executed , try later.");

mysql_select_db($db_name,$link);

$reg_data_insert=mysql_query("INSERT INTO ´$table_name´ (index,firstname,lastname,username,password,email,sex,ICQ,Yahoo_Messenger,MSN,Country,City) VALUES (´0´,´$reg_firstname´,´$reg_last_name´,´$reg_username´,password(´$reg_password´),´$reg_email´,´reg-sex´,´$reg_icq´,´$reg_yahoo_id´,´$reg_msn_id´)");

if ($reg_data_insert)
{
header("location: http://localhost/asiandreams/welcome.html"); 

$_SESSION[´logged_username´]="$reg_username";

exit();
}
else

die("Sorry your data couldn´t be inserted into our database , plase check them" );

?>

Thanxs !!!!!!!!!!!.
cyberstryke
Forum Newbie
Posts: 15
Joined: Sun Nov 06, 2005 1:34 pm

Post by cyberstryke »

Do not use the single quotes when u specify the variables in your SQl statement.


What you can do to test this is as follows:


put your final SQL statement in a varibale just before execution.

ie:


something like:

$myqyery = "insert into $mytable.........";


u then echo this variable in your browser.

if it does not execute sucessfully...copy it from your browser and try to run it from my sql.

it will give you an indication whether the query u`ve written is a good one.

Hope this helps you.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Use php tags when posting php code
sheila
Forum Commoner
Posts: 98
Joined: Mon Sep 05, 2005 9:52 pm
Location: Texas

Post by sheila »

The INSERT lists Country and City in the column list but you don't send any values for either of them.
Also, is 'index' an autoincrement column? If so you should leave that out and let MySQL assign the value.

See the thread viewtopic.php?t=17096
for some tips on debugging database problems, especially useful is mysql_error().
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Is `index` the Primary Key? If it is your code is telling your database to duplicate values in the table with a value that is not acceptable for a primary key value. Try removing the '0' from your insert query and see what that gives you.

Another thing you can do is some error trapping. Using an if...else statement to test the success of the query gives you the opportunity to see what mysql_error() throws in the event your database is throwing an error on your query.
Post Reply