Jump to content

Recommended Posts

Ok same code different problem.  When i submit the form that corresponds to this code the auto number goes up and all zeros show up in the respective interger fields but no information is entered into the database other than the autonumber. 

 

<?php

include "clientconnect.php";
include "newclient.html";

mysql_select_db('greencut_customercenter', $con);

$client_id = mysql_real_escape_string($_POST['client_id']);
$client_fname = mysql_real_escape_string($_POST['client_fname']);
$client_lname = mysql_real_escape_string($_POST['client_lname']);
$client_address = mysql_real_escape_string($_POST['client_address']);
$client_city = mysql_real_escape_string($_POST['client_city']);
$client_state = mysql_real_escape_string($_POST['client_state']);
$client_zipcode = mysql_real_escape_string($_POST['client_zipcode']);
$client_phone = mysql_real_escape_string($_POST['client_phone']);
$client_cphone = mysql_real_escape_string($_POST['client_cphone']);
$client_email = mysql_real_escape_string($_POST['client_email']);
$client_website = mysql_real_escape_string($_POST['client_website']);
$client_notes = mysql_real_escape_string($_POST['client_notes']);

$sql = "insert into clients values ('$client_id', '$client_fname', '$client_lname', '$client_address', '$client_city', '$client_state', '$client_zipcode', '$client_phone', '$client_cphone', '$client_email', '$client_website', '$client_notes')";


if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";
mysql_close($con);
?>

Link to comment
https://forums.phpfreaks.com/topic/116522-getting-no-value-inputs-in-database/
Share on other sites

also are you supplyinmg the correct number of fields for values. You said you had an auto incremental key so there should be:

values ('', '".$field1."'

 

It is much better writing:

 

SET name='".$name."', address='".$address."' etc

Remove the single quotes around your php variables!

Usually that'd be a good idea but not here. $sql is actually in double quotes which allow variables to be used inside them. Without the single quotes, $sql would look like:

$sql = "insert into clients values (1, Firstname, Lastname, etc....

Which would result in a mySQL error as the values need to be denoted by single quotes.

 

Just a style preference I have

values ('".$client_id."', '".$client_fname."'

 

I hate this sort of query using the "VALUE" syntax, especially if you modify the structure of your table and forget about queries written like this. SET is much more efficient as the order of fields makes no difference.

My code sinppets are not complete and wont work. They are just examples to get you on the right track.

 

If you have a duplicate key then get rid of the bad value and make sure that you definately have an auto incremental field for your primary key an no other uniques indexes on fields taht may product the error.

 

If there are values in your variables. I assume that you have tested this then this code will work (I have assumed the names of your database fields so make sure that you change them in the following SQL):

 

$sql = "INSERT INTO clients SET client_id='".$client_id."', client_fname='".$client_fname."', client_lname='".$client_lname."', client_address='".$client_address."', client_city='".$client_city."', client_state='".$client_state."', client_zipcode='".$client_zipcode."', client_phone='".$client_phone."', client_cphone='".$client_cphone."', client_email='".$client_email."', client_website='".$client_website."', client_notes='".$client_notes."')";

My code sinppets are not complete and wont work. They are just examples to get you on the right track.

 

If you have a duplicate key then get rid of the bad value and make sure that you definately have an auto incremental field for your primary key an no other uniques indexes on fields taht may product the error.

 

If there are values in your variables. I assume that you have tested this then this code will work (I have assumed the names of your database fields so make sure that you change them in the following SQL):

 

$sql = "INSERT INTO clients SET client_id='".$client_id."', client_fname='".$client_fname."', client_lname='".$client_lname."', client_address='".$client_address."', client_city='".$client_city."', client_state='".$client_state."', client_zipcode='".$client_zipcode."', client_phone='".$client_phone."', client_cphone='".$client_cphone."', client_email='".$client_email."', client_website='".$client_website."', client_notes='".$client_notes."')";

 

no matter how i change the format around, mess with the db it says duplicate entry for key 2

any ideas still?

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.