Jump to content

sql problems...


Sobbs

Recommended Posts

$con = mysql_connect("xxxxxxxxxxx","xxxxxxxx","xxxxxxxxxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }else{
echo "Connected to DB";
}


$sql = "INSERT INTO `b33_3176976_lunadb`.`DB_Guides` (`gid`, `uname`, `gname`, `icon`, `desc`, `cat`, `body`, `score`) VALUES (NULL, \'$_POST['name']\', \'$_POST['guidename']\', \'$_POST['icon']\', \'$_POST['description']\', \'$_POST['cat']\', \'$_POST['body']\', \'0\');";

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

mysql_close($con);

This is supposed to add the info requested from a form but for somereason non of the info ever gets put into the database. The code doesnt even seem to work since it should say I was connected to the database but I always get a blank screen. Whats going wrong?

Link to comment
Share on other sites

ive noticed an extra semicolumn after the insert query

 

"INSERT INTO `b33_3176976_lunadb`.`DB_Guides` (`gid`, `uname`, `gname`, `icon`, `desc`, `cat`, `body`, `score`) VALUES (NULL, \'$_POST['name']\', \'$_POST['guidename']\', \'$_POST['icon']\', \'$_POST['description']\', \'$_POST['cat']\', \'$_POST['body']\', \'0\');";

 

try this

 

$con = mysql_connect("xxxxxxxxxxx","xxxxxxxx","xxxxxxxxxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }else{
echo "Connected to DB";
}


$sql = "INSERT INTO `b33_3176976_lunadb`.`DB_Guides` (`gid`, `uname`, `gname`, `icon`, `desc`, `cat`, `body`, `score`) VALUES (NULL, \'$_POST['name']\', \'$_POST['guidename']\', \'$_POST['icon']\', \'$_POST['description']\', \'$_POST['cat']\', \'$_POST['body']\', \'0\')";

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

mysql_close($con);

 

Link to comment
Share on other sites

I added that and its still not enetering anything into the database.

Ive re written the code without any post data.

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);

$con = mysql_connect("--","--","--");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }else{
echo "Connected to DB";
}

$db = mysql_select_db("b33_3176976_lunadb", $con);
if (!$db)
  {
  die('Could not connect: ' . mysql_error());
  }else{
echo "DB selected";
}

mysql_query("INSERT INTO DB_Guide (uname, gname, icon, desc, cat, body, score) 
VALUES ('test', 'test', 'test', 'test', 'test', '0')");



?>

It still doesn apear to work.

Link to comment
Share on other sites

desc is a reserved word, either change the field identifier (recommended) or surround it with `backticks`.

 

if (!mysql_query("INSERT INTO DB_Guide (uname, gname, icon, `desc`, cat, body, score) VALUES ('test', 'test', 'test', 'test', 'test', '0')")) {
  echo mysql_error();
}

Link to comment
Share on other sites

That makes little sense. Try this....

 

if (!mysql_query("INSERT INTO DB_Guide (uname, gname, icon, dsc, cat, body, score) VALUES ('test', 'test', 'test', '1', 'test', '0')")) {
  echo mysql_error();
} else {
  echo "success";
}

 

Do you get any output?

Link to comment
Share on other sites

That makes little sense. Try this....

 

if (!mysql_query("INSERT INTO DB_Guide (uname, gname, icon, dsc, cat, body, score) VALUES ('test', 'test', 'test', '1', 'test', '0')")) {
  echo mysql_error();
} else {
  echo "success";
}

 

Do you get any output?

None.

if (!mysql_query("INSERT INTO DB_Guide (uname, gname, icon, dsc, cat, body, score) VALUES ('test', 'test', 'test', 'test', '1', 'test', '0')")) {
  echo mysql_error();
} else {
  echo "success";
}

Link to comment
Share on other sites

I have just told you what one of the problems where.

The number of fields you have does not equal the number of values you are trying to put in.

You listed 7 fields and you are only filling out 6 values. It will not allow that to go through. You need to

put down one more value to match the number of fields you are entering or drop off one of the fields (either one).

Link to comment
Share on other sites

I have just told you what one of the problems where.

The number of fields you have does not equal the number of values you are trying to put in.

You listed 7 fields and you are only filling out 6 values. It will not allow that to go through. You need to

put down one more value to match the number of fields you are entering or drop off one of the fields (either one).

If you looked at my updated code, I did change it.

Link to comment
Share on other sites

It sounds like your server/ini have error reporting and outputing disabled.

Use the following url: http://us.php.net/error_reporting and cut on the error reporting temporarily (at the top of your code).

 

Afterwards verify the Database name in your code is the same as your database name on the server.

 

Also your connection information...make sure it's the same as your web host. Not all hosts allow you to connect using "localhost" what webhost are you using right now?

Link to comment
Share on other sites

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.