Jump to content


Photo

Renlok has more problems ^-^ *SOLVED*


  • Please log in to reply
12 replies to this topic

#1 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 29 September 2006 - 09:50 PM

This one runs a program which surposedly uploads the entries to the database...yet it doesnt
<?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();
?>

thanks for any feedback

mod edited to conceal database access details.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,022 posts

Posted 29 September 2006 - 11:29 PM

Try changing

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

to

$result = $db->query($query) or die ($db->error);
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 29 September 2006 - 11:32 PM

Try specifying the column names....

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


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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#4 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 30 September 2006 - 09:00 AM

Try changing

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

to

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

ive done what you said which seems to make a difference but it still dosnt work.


#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,022 posts

Posted 30 September 2006 - 09:03 AM

I didn't expect it to, but I was hoping it might give an error message saying what was wrong.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 intrik

intrik
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 30 September 2006 - 09:49 AM

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....

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,022 posts

Posted 30 September 2006 - 10:02 AM

"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 ;)
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 marknt

marknt
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts
  • LocationPhilippines

Posted 30 September 2006 - 10:05 AM

Try changing

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

to

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

ive done what you said which seems to make a difference but it still dosnt work.

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

#9 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 30 September 2006 - 10:07 AM

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


#10 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,022 posts

Posted 30 September 2006 - 10:09 AM

In which case, did you try HuggieBear's recomendation and specify the column names?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#11 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 30 September 2006 - 10:11 AM

i tryed that then it posts
Unknown column 'description' in 'field list'

#12 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,022 posts

Posted 30 September 2006 - 10:14 AM

What are you column names then? Use those, we can only guess.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#13 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 30 September 2006 - 10:19 AM

oh lol yes that work theres a spelling error in my database =]] thanks for all the help




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users