Jump to content

Archived

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

Renlok

Renlok has more problems ^-^ *SOLVED*

Recommended Posts

This one runs a program which surposedly uploads the entries to the database...yet it doesnt
[code]<?php
  // create short variable names
  $url=$_POST['url'];
  $siteName=$_POST['siteName'];
  $keywords=$_POST['keywords'];
  $description=$_POST['description'];
  $dateAdded=$_POST['dateAdded'];

  if (!$url || !$siteName || !$keywords || !$description)
  {
    echo 'You have not entered all the required details.<br />'
          .'Please go back and try again.';
    exit;
  }
  if (!get_magic_quotes_gpc())
  {
    $siteName = addslashes($siteName);
    $url = addslashes($url);
    $description = addslashes($description);
    $keywords = addslashes($keywords);
  }

  @ $db = new mysqli('***', '***', '***', '***'); // not the real values

  if (mysqli_connect_errno())
  {
    echo 'Error: Could not connect to database.  Please try again later.';
    exit;
  }

  $query = "insert into link values
            ('".$siteName."', '".$url."', '".$description."', '".$keywords."')";
  $result = $db->query($query);
  if ($result)
      echo  $db->affected_rows.' site inserted into database.';

  $db->close();
?>[/code]

thanks for any feedback

mod edited to conceal database access details.

Share this post


Link to post
Share on other sites
Try changing

$result = $db->query($query);

to

$result = $db->query($query) or die ($db->error);

Share this post


Link to post
Share on other sites
Try specifying the column names....

[code]
$query = "INSERT INTO link (name, address, description, keywords) VALUES ('$siteName', '$url', '$description', '$keywords')";

[/code]

Obviously I've made the column names up, but should help.  Also, notice how I haven't escaped the variables at all?  That's because you don't need to, when dealing with simple variables between double quotes " ", php reads the value of the variable, not the literal string.

Regards
Huggie

Share this post


Link to post
Share on other sites
[quote]Try changing

$result = $db->query($query);

to

$result = $db->query($query) or die ($db->error);[/quote]
ive done what you said which seems to make a difference but it still dosnt work.

Share this post


Link to post
Share on other sites
I didn't expect it to, but I was hoping it might give an error message saying what was wrong.

Share this post


Link to post
Share on other sites
That seems like a bit of a round-a-bout way of doing what it is you're trying to do. Is it not?

Are you just grabbing post var's and inserting them into the database? There is a way that's much much easier....

Share this post


Link to post
Share on other sites
"Your not trying to solve the world's energy crisis by producing nuclear fission that way, are you? There's a way that's a lot easier..."

May be true, but somehow I don't think that alone will win me the Nobel Physics Prize ;)

Share this post


Link to post
Share on other sites
[quote author=Renlok link=topic=110017.msg444154#msg444154 date=1159606858]
[quote]Try changing

$result = $db->query($query);

to

$result = $db->query($query) or die ($db->error);[/quote]
ive done what you said which seems to make a difference but it still dosnt work.

[/quote]
Umm try to do it the hard coded way for testing purposes only. Like this one ---> or die(mysql_error());

Share this post


Link to post
Share on other sites
yes im just trying to grab post var's and inserting them into the database


ok you wanted the error message its shows as:
Column count doesn't match value count at row 1

Share this post


Link to post
Share on other sites
In which case, did you try HuggieBear's recomendation and specify the column names?

Share this post


Link to post
Share on other sites
i tryed that then it posts
Unknown column 'description' in 'field list'

Share this post


Link to post
Share on other sites
oh lol yes that work theres a spelling error in my database =]] thanks for all the help

Share this post


Link to post
Share on other sites

×

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.