It is currently Tue Mar 19, 2019 6:37 am


All times are UTC


Forum rules


Please click here to view the forum rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Problem Creating Table and inserting table
PostPosted: Wed Oct 10, 2007 10:18 pm 
Newbie
Newbie

Joined: Wed Oct 10, 2007 10:10 pm
Posts: 1
Hi I am a newbie with mysql and php, and I am having trouble creating a table and inserting values into the table. I have a database which I created already and I have connected to. I don't get any error messages when I try connecting to it. The following code is in my main file and I am not receiving any errors with it but when I check phpMyAdmin to view if the table has been created, I see nothing in my database.
Code:
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
mysql_select_db($dbname,$conn) || die ("Error selecting database");

$query = 'CREATE TABLE registration( '.
         'name CHAR(50), '.
         'number CHAR(20), '.
         'title CHAR(50), '.
         'language CHAR(30))';

$result = mysql_query($query) || die('Couldn't create table');


Also on another php page I am processing information from a form and trying to insert it into the above created table but I keep getting an error in inserting the query.
Code:
$query = "INSERT INTO registration values ('".$_POST['name']."','".$_POST['songnum']."','".$_POST['songtitle']."','".$_POST['language']."');";

mysql_query($query) or die('Error, insert query failed');

$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, insert query failed');

Any help would be appreciated. Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 11, 2007 5:34 am 
Getting Started
Getting Started

Joined: Wed Sep 19, 2007 8:15 am
Posts: 51
I think the problem are the fields that you already created, and to those in which you are trying to insert information from webform. I'll try to explain you... with the 1st request your are creating table "registration" in already existing database, which fields are as follows: name, number, title, language.

With the second query your are trying to insert information in this table but in the following fields: name, songnum, songtitle, language. As you can see, you are trying to to insert data in non-existing. Please try to relocate those fields, and i think that you shouldn't have any problems at all.

_________________
Best Regards
James


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ]  Moderators: Moderators, Support Team

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Hosting | Domains | Servers | Extras | Order | Support | Contacts | FreeHostia © 2011