Welcome to WebmasterWorld Guest from 54.162.239.134

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Mysql Insert.

     
12:15 pm on Jul 10, 2007 (gmt 0)

10+ Year Member



This is the code I am having a problem with.

As you can see I have added the values to the database insert but for some reason it still wont insert.

Anyone know?

$root = "http://$_SERVER[HTTP_HOST]" . ereg_replace('/$', '', dirname($_SERVER['PHP_SELF'])) . '/';
$action = $_GET['action']? $_GET['action'] : ($_POST['action']? $_POST['action'] : '');
$connection = @mysql_connect(mysql_hostname, mysql_username, mysql_password) && @mysql_select_db(mysql_database) die('<code>' . mysql_error() . '</code>');
switch ($action) {
case 'generate_url':
$parsed = @parse_url($_POST['url']);
if ($parsed && strlen($_POST['url']) && ereg('\.', $_POST['url'])) {
if (eregi('^[a-z0-9-]+$', $_POST['tag'])) {
$tag = $_POST['tag'];
$sql = "SELECT * FROM `urls` WHERE `url_tag` = '$tag' OR `url_id` = '$tag'";
$q = mysql_query($sql);
$n = mysql_fetch_assoc($q);
if ($n) {
$cancel = true;
}
}
if (!$cancel) {
$url = ($parsed['scheme']? '' : 'http://') . (get_magic_quotes_gpc()? mysql_real_escape_string(stripslashes($_POST['url'])) : mysql_real_escape_string($_POST['url']));
$sql = "INSERT INTO `urls` (`url_location`, `url_tag`, `ad_link`, `link_display`) VALUES ('$url', '$_POST[tag]', '$_POST[adlink]', '$_POST[linkdisplay]')";
$q = mysql_query($sql);
$id = mysql_insert_id();
if (!$tag) {
$result = '<font size=3>Here is your <strong>new URL!</strong>: <a href="' . $root . $id . '/" target=_blank">' . $root . $id . '</a></font>'.$_POST[adlink].'';
} else {
$result = 'Here is your <strong>new URL!</strong>: <a href="' . $root . $tag . '/" target=_blank">' . $root . $tag . '</a> <strong> Copy and Paste:</strong> ' . $root . $tag . '';
}
} else {
if (ereg('^[0-9]+$', $_POST['tag'])) {
$result = 'That tag is reserved for the system!';
} else {
$result = 'Tag unavailable!';
}
}
} else {
$result = 'Put in a <strong>real URL</strong> please!';
}
if ((bool) $_POST['javascript']) {
header('Content-Type: text/plain');
die($result);
}
break;

12:20 pm on Jul 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> $sql = "INSERT INTO `urls` (`url_location`, `url_tag`, `ad_link`, `link_display`) VALUES ('$url', '$_POST[tag]', '$_POST[adlink]', '$_POST[linkdisplay]')";

Try changing it to the following:

$sql = "INSERT INTO urls (url_location, url_tag, ad_link, link_display) VALUES ('". $url ."', '". $_POST[tag] ."', '". $_POST[adlink] ."', '". $_POST[linkdisplay] ."')";

If this doesn't work, please post if you are getting any errors.

Habtom

2:28 pm on Jul 10, 2007 (gmt 0)

10+ Year Member



Try changing it to the following:
$sql = "INSERT INTO urls .....

... and then add a
echo $sql;
just to have a look and being sure that your input makes sense (are all input variables filled?).

Kind regards,
R.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month