Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/22543-renlok-has-more-problems-solved/
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
"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 ;)
[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());
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.