Page 1 of 1

Php post to a mysql database

Posted: Thu Feb 02, 2006 1:20 am
by tombstone
Ok so first off i have regester_globals vales to on (i know its unsecure)
Here is the PHP code add.php all in CASE Sensitive:

Code: Select all

<?php
$user="root";
$pass="password";
$db="movielist";
$movie_name=$movie_name;
$web_address=$web_address;
$type_Action=$type_Action;
$type_Adventure=$type_Adventure;
$type_Animation=$type_Animation;
$type_Family=$type_Family;
$type_Comedy=$type_Comedy;
$type_Crime=$type_Crime;
$type_Documentary=$type_Documentary;
$type_Drama=$type_Drama;
$type_Fantasy=$type_Fantasy;
$type_Horror=$type_Horror;
$type_Independent=$type_Independent;
$type_Musical=$type_Musical;
$type_Mystery=$type_Mystery;
$type_Romance=$type_Romance;
$type_ScienceFiction=$type_ScienceFiction;
$type_Thriller=$type_Thriller;
$type_War=$type_War;
$type_Western=$type_Western;
$type_Holiday=$type_Holiday;
$rating=$rating;
$book=$book;



mysql_connect(localhost,$user,$pass);
mysql_select_db($db) or die( "Unable to select database, Please contact your administrator");
$query="INSERT INTO movie_list VALUES ('','$movie_name','$web_address','$type_Action',
'$type_Adventure','$type_Animation','$type_Family','$type_Comedy','$type_Crime',
'$type_Documentary','$type_Drama','$type_Fantasy','$type_Horror','$type_Independent',
'$type_Musical','$type_Mystery','$type_Romance','$type_ScienceFiction','$type_Thriller',
'$type_War','$type_Western','$type_Holiday','$rating','$book')";
echo "done";
?>

Here is the code i used to create the table:

Code: Select all

<?php
$user="root";
$pass="password";
$db="movielist";
mysql_connect(localhost,$user,$pass);
mysql_select_db($db) or die( "Unable to select database Please contact the administrator.");
$query="CREATE TABLE movie_list (id int(7) NOT NULL auto_increment,movie_name varchar(100) NOT NULL,web_address varchar(150) NOT NULL,
type_Action int(1) NOT NULL,type_Adventure int(1) NOT NULL,type_Animation int(1) NOT NULL,type_Family int(1) NOT NULL,type_Comedy int(1) NOT NULL,
type_Crime int(1) NOT NULL,type_Documentary int(1) NOT NULL,type_Drama int(1) NOT NULL,type_Fantasy int(1) NOT NULL,type_Horror int(1) NOT NULL,
type_Independent int(1) NOT NULL,type_Musical int(1) NOT NULL,type_Mystery int(1) NOT NULL,type_Romance int(1) NOT NULL,
type_ScienceFiction int(1) NOT NULL,type_Thriller int(1) NOT NULL,type_War int(1) NOT NULL,type_Western int(1) NOT NULL,type_Holiday int(1) NOT NULL,
rating varchar(2) NOT NULL,book varchar(50) NOT NULL,Add_Date varchar(15) NOT NULL,PRIMARY KEY (id),UNIQUE id (id))";
mysql_query($query);
mysql_close();
print("<center><h1>Done Creating the Table</h1></center>");
?>
Not sure what is going on. I have also tried $movie_name=$_POST['movie_name'];

Re: Php post to a mysql database

Posted: Thu Feb 02, 2006 1:23 am
by josh
tombstone wrote:Not sure what is going on
Me neither, what was the question?


Also this code is redundant:

Code: Select all

$movie_name=$movie_name;
$web_address=$web_address;
$type_Action=$type_Action;
$type_Adventure=$type_Adventure;
$type_Animation=$type_Animation;
$type_Family=$type_Family;
$type_Comedy=$type_Comedy;
$type_Crime=$type_Crime;
$type_Documentary=$type_Documentary;
$type_Drama=$type_Drama;
$type_Fantasy=$type_Fantasy;
$type_Horror=$type_Horror;
$type_Independent=$type_Independent;
$type_Musical=$type_Musical;
$type_Mystery=$type_Mystery;
$type_Romance=$type_Romance;
$type_ScienceFiction=$type_ScienceFiction;
$type_Thriller=$type_Thriller;
$type_War=$type_War;
$type_Western=$type_Western;
$type_Holiday=$type_Holiday;
$rating=$rating;
$book=$book;

Posted: Thu Feb 02, 2006 1:24 am
by m3mn0n
A great function for MySQL debugging is mysql_error(). Adding it to your die() error handler will output the exact MySQL error from the server, it's similar to the PHP error reporting system so you'll will know exactly what to do and where to fix the issue.

Posted: Thu Feb 02, 2006 1:31 am
by feyd
$query is created in the first snippet, but never used against mysql.

Re: Php post to a mysql database

Posted: Thu Feb 02, 2006 1:34 am
by tombstone
Basicly it is not updating the table at all.
Yeah i thought th code was pointless but i tried it with and without

Code: Select all

<?php
$user="root";
$pass="password";
$db="movielist";
mysql_connect(localhost,$user,$pass);
mysql_select_db($db) or die( "Unable to select database, Please contact your administrator");
$query="INSERT INTO movie_list VALUES ('','$movie_name','$web_address','$type_Action','$type_Adventure','$type_Animation','$type_Family','$type_Comedy','$type_Crime','$type_Documentary','$type_Drama','$type_Fantasy','$type_Horror','$type_Independent','$type_Musical','$type_Mystery','$type_Romance','$type_ScienceFiction','$type_Thriller','$type_War','$type_Western','$type_Holiday','$rating','$book')";

echo mysql_error();

echo "<p>done";
?>

After i ran it with this it just displays 'Done'


[quote="jshpro2"]

Me neither, what was the question?


[/quote]

Posted: Thu Feb 02, 2006 1:38 am
by tombstone
feyd wrote:$query is created in the first snippet, but never used against mysql.

Code: Select all

<?php
$user="root";
$pass="password";
$db="movielist";
mysql_connect(localhost,$user,$pass);
mysql_select_db($db) or die( "Unable to select database, Please contact your administrator");
$query="INSERT INTO movie_list VALUES ('','$movie_name','$web_address','$type_Action','$type_Adventure','$type_Animation','$type_Family','$type_Comedy','$type_Crime','$type_Documentary','$type_Drama','$type_Fantasy','$type_Horror','$type_Independent','$type_Musical','$type_Mystery','$type_Romance','$type_ScienceFiction','$type_Thriller','$type_War','$type_Western','$type_Holiday','$rating','$book')";
mysql_query($query); 
echo mysql_error();

echo "<p>done";
?>
Now i get this:

Column count doesn't match value count at row 1
done

Posted: Thu Feb 02, 2006 1:46 am
by tombstone
sorry guys im looking at old code. I forgot i added a date integer into the mix which means i am missing one...

Posted: Thu Feb 02, 2006 1:53 am
by tombstone
Oh and thanxs for pointing out that i had done nothign with the $query i totally missed that *slaps head*

Posted: Thu Feb 02, 2006 1:55 am
by m3mn0n
Here is a couple example usages of it:

Code: Select all

<?php
mysql_select_db($db) or die( "Unable to select database, Please contact your administrator<br />". mysql_error()); 
?>
and without any text:

Code: Select all

<?php
mysql_select_db($db) or die(mysql_error()); 
?>