Jump to content

Renlok has more problems ^-^ *SOLVED*


Renlok

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
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
Link to comment
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());
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.