Jump to content

Recommended Posts

MySQL 5.1.52

I made a table for "Register" and I have 2 fields for "City/State/Zip". The database doesn't allow duplicates so I made two different field names instead. I then used this site ( http://teamtutorials.com/web-development-tutorials/php-tutorials/inserting-data-into-a-mysql-database-using-php ) and made a form and a updater. I did the script so it calls the two database names and uses it with City/State/Zip in the PHP so it works. Instead I get this:

 

Error updating database

 

Code:

 

<?php
$CZip = $_POST['CZip'];
$CZip = $_POST['CZip'];

mysql_connect ("localhost", "dbuser", "dbpass") or die ('Error:  

'  . mysql_error());
mysql_select_db ("dbname");




$query="INSERT INTO Register (ID, CZip, CZip, PHON)VALUES ('NULL', '".

$CZip."', '".$CZip"', '".$PHON."')";

mysql_query($query) or die ('Error updating database');

echo "Database Updated With: " .$CZip. " ".$CZip." ".$PHON ;

?>

 

Censored the database information.

 

Links : http://evaluationetwork.com/update.php

http://evaluationetwork.com/form.php

 

We attempted to use php to access MySQL and update some tables with it.

 

I'm not sure if this link would help : http://codepad.org/BR1If1zC

 

 

Link to comment
https://forums.phpfreaks.com/topic/220990-error-updating-database/
Share on other sites

I dont really understand why you have 2 fields named the same that both will be storing the same data?

Can you explain this in a little more detail?

 

Can you also show us the actual table structure of 'Register'?

And last but not least..Change this

mysql_query($query) or die ('Error updating database');

to

mysql_query($query) or die ('Error updating database because: '.mysql_error());

I dont really understand why you have 2 fields named the same that both will be storing the same data?

Can you explain this in a little more detail?

 

Can you also show us the actual table structure of 'Register'?

And last but not least..Change this

mysql_query($query) or die ('Error updating database');

to

mysql_query($query) or die ('Error updating database because: '.mysql_error());

 

There is a registration page. It requires City/State/Zip for Physical Address and Payment information. The database doesn't allow duplicates, so I named it two different names.

 

Here is the table structure:

 

http://img834.imageshack.us/img834/7186/screenshot1190.png

 

Pay city and Phys_city is part of City/Zip/State. As you I mentioned before for Physical Address and Payment information.

 

I changed the code as you said, now I got this:

 

Error updating database because: 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 '[Register] (ID, CZip, CZip, PHON)VALUES ('NULL', '..', '.', '..')' at line 1

Ok. Apart from your field names being very complicated (Consider reading up on database construction and their field types)

The issue is, you are trying to insert data into fields that do no exist..

 

Here is an example of how you should enter the values into the database

$sql = "INSERT INTO `Register` (`Pay_city`,`Phy_city`) VALUES ('".$CZip."','".$CZip."')";

 

The first bracket set lists the field names in the table and the second set are the values..

Also consider to protect your sql queries by escaping your input code using mysql_real_escape_string()

I just got this error:

 

Error updating database because: 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 ''Register' (ID, Pay_city, Phy_city, PHON)VALUES ('NULL', '..', '.', '..')' at line 1

 

After I did as what you said to do.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.