Jump to content

Fixed 1 Problem And Came Another


Joey46

Recommended Posts

this is the error i am getting now as i deleted the postal address Not Working! Unknown column 'PostalAddress' in 'field list' this is now the script i have $ID =$_POST['ID'];$Name =$_POST['Name'];$Password =$_POST['Password'];$Email =$_POST['Email'];$PhoneNumber =$_POST['PhoneNumber'];$sql = "INSERT into students (ID, Name, Password, Email, PhoneNumber ) values ('$ID', '$Name', '$Password', '$Email', '$PhoneNumber')"; if(mysql_query($sql, $conn)){ echo "<h4> Student Added! </h4>"; } else { echo "<h4> Not Working! </h4>"; echo mysql_error(); }

Link to comment
Share on other sites

You sure that is the script? That error says that you are referencing the column `PostalAddress` in the SQL query without there actually being one, but you aren't.

Link to comment
Share on other sites

You sure that is the script? That error says that you are referencing the column `PostalAddress` in the SQL query without there actually being one, but you aren't.
This is the message i get back This is the script$conn = mysql_connect($host, $user, $pswd);@mysql_select_db($myDB, $conn) or die ("Problem BUGGA");$ID =$_POST['ID'];$Name =$_POST['Name'];$Password =$_POST['Password'];$Email =$_POST['Email'];$PhoneNumber =$_POST['PhoneNumber'];$sql = "INSERT into students (ID, Name, Password, Email, PhoneNumber ) values ('$ID', '$Name', '$Password', '$Email', '$PhoneNumber')"; if(mysql_query($sql, $conn)){ echo "<h4> Student Added! </h4>"; } else { echo "<h4> Not Working! </h4>"; echo mysql_error(); } ?>I took Postal Address out
Link to comment
Share on other sites

That error message doesn't go with that code. Obviously there's not a column in the list called 'PostalAddress', so there's no reason why it would generate that error. The mysql_error function gets the last error that happened, so it's possible that you're seeing an error from another problem.You also might want to print out the query and run it using phpMyAdmin to see if it works. You're not escaping any quotes or anything, so the values could be messing up the query.

Link to comment
Share on other sites

That error message doesn't go with that code. Obviously there's not a column in the list called 'PostalAddress', so there's no reason why it would generate that error. The mysql_error function gets the last error that happened, so it's possible that you're seeing an error from another problem.You also might want to print out the query and run it using phpMyAdmin to see if it works. You're not escaping any quotes or anything, so the values could be messing up the query.
I took the Postal Address out of my Database then this error came up after i removed the Postal Address mateDead You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '')' at line 1
Link to comment
Share on other sites

Print out the query that's causing that error.
Sorry i took so long getting back to you but this is the problem that the query said it was after i did what you suggested$student = $_POST[ 'student'];I have gone thru the manual and can not find anything else i could replace it with do you have any suggestions mate please
Link to comment
Share on other sites

I'm not sure I understand your question, you were getting a SQL error and I told you to print out the query so that we can figure out where the error is, I'm not sure what that has to do with the line you pasted.

Link to comment
Share on other sites

I'm not sure I understand your question, you were getting a SQL error and I told you to print out the query so that we can figure out where the error is, I'm not sure what that has to do with the line you pasted.
Its ok mate i went to Tafe yesterday and even my teacher does not understand the mistake so i will paste all of my code for you to look at and see if you can work out why this is not working it does not even add the data to my database for some reason either as my teacher tried to add data to my database and nothing went into it so here is all of my code."<?php$host = 'db.kwilliams.cessnock-ict.net';$user = 'kgillis';$pswd = '********';$myDB = 'kgillisdb';$conn = mysql_connect($host, $user, $pswd);@mysql_select_db($myDB, $conn) or die ("Houston We Have A Problem");$ID =$_POST['ID'];$Name =$_POST['Name'];$Password =$_POST['Password'];$Email =$_POST['Email'];$PhoneNumber =$_POST['PhoneNumber'];$sql = "INSERT into students (ID, Name, Password, Email, PhoneNumber ) values ('$ID', '$Name','Password', '$Email' '$PhoneNumber)"; if(mysql_query($sql, $conn)){ echo "<h4> Student Added! </h4>"; } else { echo "<h4> Dead </h4>"; echo mysql_error(); } ?>
Link to comment
Share on other sites

Right, so if the query isn't working then the logical step is to print the query to figure out what the problem is. Add this somewhere after you create $sql:echo $sql;Offhand it looks like you're missing a single quote after the phone number.

Link to comment
Share on other sites

Right, so if the query isn't working then the logical step is to print the query to figure out what the problem is. Add this somewhere after you create $sql:echo $sql;Offhand it looks like you're missing a single quote after the phone number.
This is the myphpadmin error now mate for that same codeThere seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problemERROR: Unknown Punctuation String @ 1STR: <?SQL: <?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';<?php$host = 'db.kwilliams.cessnock-ict.net';SQL query: <?php $host = 'db.kwilliams.cessnock-ict.net'; MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<?php$host = 'db.kwilliams.cessnock-ict.net'' at line 1
Link to comment
Share on other sites

I'm not sure what you did, did you just paste the PHP code into phpMyAdmin? Because phpMyAdmin only runs SQL code, not PHP code. Again, I think all you need to do is add another quote after the phone number in the query.

Link to comment
Share on other sites

I'm not sure what you did, did you just paste the PHP code into phpMyAdmin? Because phpMyAdmin only runs SQL code, not PHP code. Again, I think all you need to do is add another quote after the phone number in the query.
I pasted my code into mysql query for that answer i gave you i have added the extra ' after PhoneNumber plus i added a $ that was left out on the same line and i still get an error mate.this is now my code$conn = mysql_connect($host, $user, $pswd);@mysql_select_db($myDB, $conn) or die ("Houston We Have A Problem");echo $sql;$ID =$_POST['ID'];$Name =$_POST['Name'];$Password =$_POST['Password'];$Email =$_POST['Email'];$PhoneNumber =$_POST['PhoneNumber'];$sql ="INSERT into students(ID, Name, Password, Email, PhoneNumber ) values ('$ID', '$Name', '$Password', '$Email', '$PhoneNumber')"; echo $sql;if(mysql_query($sql, $conn)){ echo "<h4> Student Added! </h4>"; } else { echo "<h4> Dead </h4>"; echo mysql_error(); }
Link to comment
Share on other sites

What is the echo $sql line printing? Also, it would be helpful to see the structure of the students table. To get that in phpMyAdmin, you can click Export, then select the students table, keep Structure checked and uncheck Data, then click Go.

Link to comment
Share on other sites

What is the echo $sql line printing? Also, it would be helpful to see the structure of the students table. To get that in phpMyAdmin, you can click Export, then select the students table, keep Structure checked and uncheck Data, then click Go.
This is the PHPMy admin when i clicked exportView dump (schema) of tableExport CSV CSV for MS Excel Microsoft Excel 2000 Microsoft Word 2000 LaTeX Open Document Spreadsheet Open Document Text PDF SQL XML YAML OptionsFields terminated byFields enclosed byFields escaped byLines terminated byReplace NULL byPut fields names in the first row OptionsReplace NULL byPut fields names in the first rowExcel editionWindowsExcel 2003 / Macintosh OptionsReplace NULL byPut fields names in the first row OptionsStructureDataReplace NULL byPut fields names in the first row OptionsInclude table captionStructureTable captionContinued table captionLabel keyComments DataPut fields names in the first rowTable captionContinued table captionLabel keyReplace NULL by OptionsReplace NULL byPut fields names in the first row OptionsStructureComments DataPut fields names in the first rowReplace NULL by Options(Generates a report containing the data of a single table)Report title OptionsAdd custom comment into header (\n splits lines)Enclose export in a transactionDisable foreign key checksSQL compatibility modeNONEANSIDB2MAXDBMYSQL323MYSQL40MSSQLORACLETRADITIONAL StructureAdd DROP TABLEAdd IF NOT EXISTSAdd AUTO_INCREMENT valueEnclose table and field names with backquotesAdd CREATE PROCEDURE / FUNCTIONAdd into commentsCreation/Update/Check dates DataComplete insertsExtended insertsMaximal length of created queryUse delayed insertsUse ignore insertsUse hexadecimal for BLOBExport typeINSERTUPDATEREPLACE Options This format has no optionsOptions This format has no options Dump row(s) starting at record # . Save as file File name template (1): ( remember template ) Compression: None "zipped" "gzipped" (1) This value is interpreted using strftime, so you can use time formatting strings. Additionally the following transformations will happen: __SERVER__/server name, __DB__/database name, __TABLE__/table name. Other text will be kept as is.
Link to comment
Share on other sites

Right, those are the options. Make sure the students table is selected, and the Structure checkbox is checked, and click the Go button to have it export the table structure as SQL code.
when i did what you said this is what i got back mateView dump (schema) of tableExport CSV CSV for MS Excel Microsoft Excel 2000 Microsoft Word 2000 LaTeX Open Document Spreadsheet Open Document Text PDF SQL XML YAML OptionsFields terminated byFields enclosed byFields escaped byLines terminated byReplace NULL byPut fields names in the first row OptionsReplace NULL byPut fields names in the first rowExcel editionWindowsExcel 2003 / Macintosh OptionsReplace NULL byPut fields names in the first row OptionsStructureDataReplace NULL byPut fields names in the first row OptionsInclude table captionStructureTable captionContinued table captionLabel keyComments DataPut fields names in the first rowTable captionContinued table captionLabel keyReplace NULL by OptionsReplace NULL byPut fields names in the first row OptionsStructureComments DataPut fields names in the first rowReplace NULL by Options(Generates a report containing the data of a single table)Report title OptionsAdd custom comment into header (\n splits lines)Enclose export in a transactionDisable foreign key checksSQL compatibility modeNONEANSIDB2MAXDBMYSQL323MYSQL40MSSQLORACLETRADITIONAL StructureAdd DROP TABLEAdd IF NOT EXISTSAdd AUTO_INCREMENT valueEnclose table and field names with backquotesAdd CREATE PROCEDURE / FUNCTIONAdd into commentsCreation/Update/Check dates DataComplete insertsExtended insertsMaximal length of created queryUse delayed insertsUse ignore insertsUse hexadecimal for BLOBExport typeINSERTUPDATEREPLACE Options This format has no optionsOptions This format has no options Dump row(s) starting at record # . Save as file File name template (1): ( remember template ) Compression: None "zipped" "gzipped"
Link to comment
Share on other sites

What you're pasting there is the export options page of phpMyAdmin. I'm looking for the actual export, not the options page used to create it, I already know what that looks like. There's a button marked "Go" on the bottom of that options page that actually does the export. It will produce something that looks similar to this:

CREATE TABLE IF NOT EXISTS `users` (  `id` int(10) unsigned NOT NULL auto_increment,  `username` varchar(50) collate utf8_unicode_ci NOT NULL,  `password` varchar(40) collate utf8_unicode_ci NOT NULL,  `fname` varchar(255) collate utf8_unicode_ci default NULL,  `lname` varchar(255) collate utf8_unicode_ci default NULL,  `email` varchar(255) collate utf8_unicode_ci default NULL,  `active` tinyint(1) unsigned NOT NULL,  `date_registered` int(10) unsigned NOT NULL,  `last_login` int(10) unsigned NOT NULL,  `last_ip` varchar(15) collate utf8_unicode_ci default NULL,  PRIMARY KEY  (`id`),  KEY `username` (`username`)) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=9;

Link to comment
Share on other sites

What you're pasting there is the export options page of phpMyAdmin. I'm looking for the actual export, not the options page used to create it, I already know what that looks like. There's a button marked "Go" on the bottom of that options page that actually does the export. It will produce something that looks similar to this:
CREATE TABLE IF NOT EXISTS `users` (  `id` int(10) unsigned NOT NULL auto_increment,  `username` varchar(50) collate utf8_unicode_ci NOT NULL,  `password` varchar(40) collate utf8_unicode_ci NOT NULL,  `fname` varchar(255) collate utf8_unicode_ci default NULL,  `lname` varchar(255) collate utf8_unicode_ci default NULL,  `email` varchar(255) collate utf8_unicode_ci default NULL,  `active` tinyint(1) unsigned NOT NULL,  `date_registered` int(10) unsigned NOT NULL,  `last_login` int(10) unsigned NOT NULL,  `last_ip` varchar(15) collate utf8_unicode_ci default NULL,  PRIMARY KEY  (`id`),  KEY `username` (`username`)) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=9;

this is what i got -- phpMyAdmin SQL Dump-- version 2.11.9.3-- http://www.phpmyadmin.net---- Host: db.kwilliams.cessnock-ict.net-- Generation Time: Mar 13, 2009 at 05:38 PM-- Server version: 5.0.67-- PHP Version: 5.2.6SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";---- Database: `kgillisdb`---- ------------------------------------------------------------ Table structure for table `students`--CREATE TABLE IF NOT EXISTS `students` ( `ID` mediumint(9) NOT NULL, `Name` varchar(50) NOT NULL, `Password` varchar(30) NOT NULL, `Email` varchar(60) NOT NULL, `PhoneNumber` int(10) NOT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `name` (`Name`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;---- Dumping data for table `students`--INSERT INTO `students` (`ID`, `Name`, `Password`, `Email`, `PhoneNumber`) VALUES(0, '', 'password', '', 0);

Link to comment
Share on other sites

The error is probably because the PhoneNumber field is an int. Make that a varchar instead, or do some additional processing on the submitted phone number to remove any characters that are not a digit.
No mate that did not work i got this message"Dead Duplicate entry '0' for key 1 "
Link to comment
Share on other sites

Well, that did fix the error you were having, this is a new error. You have this field defined in your table:`ID` mediumint(9) NOT NULL,That field is the primary key for the table:PRIMARY KEY (`ID`),Primary keys have to be unique. That error is because you're trying to insert a record with an ID that already exists (an ID of 0). It looks like you're getting the ID from $_POST, so if you want to use an ID that was submitted by the user then you'll need to add another query where you look up an existing record with that ID and give the user an error if it already exists. If you want to have the database keep track of the IDs, and just use the next number available, then you need to make the ID column in the table an auto_increment column, and remove the ID field from the insert query. If you did that, then the database will automatically assign the next available ID when you insert a new record.

Link to comment
Share on other sites

Well, that did fix the error you were having, this is a new error. You have this field defined in your table:`ID` mediumint(9) NOT NULL,That field is the primary key for the table:PRIMARY KEY (`ID`),Primary keys have to be unique. That error is because you're trying to insert a record with an ID that already exists (an ID of 0). It looks like you're getting the ID from $_POST, so if you want to use an ID that was submitted by the user then you'll need to add another query where you look up an existing record with that ID and give the user an error if it already exists. If you want to have the database keep track of the IDs, and just use the next number available, then you need to make the ID column in the table an auto_increment column, and remove the ID field from the insert query. If you did that, then the database will automatically assign the next available ID when you insert a new record.
Now i am getting this error mateDead Duplicate entry '' for key 2
Link to comment
Share on other sites

This is key 2:UNIQUE KEY `name` (`Name`)So you're also requiring that all names be unique, and it looks like you're trying to insert a duplicate empty name. I'm not sure how you want to fix that, there are several ways, but that's the error.

Link to comment
Share on other sites

This is key 2:UNIQUE KEY `name` (`Name`)So you're also requiring that all names be unique, and it looks like you're trying to insert a duplicate empty name. I'm not sure how you want to fix that, there are several ways, but that's the error.
Wow! you are a miracle worker that worked Thank you ever so much JustSomeGuy that has made me feel better by far :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...