homepage Welcome to WebmasterWorld Guest from 54.226.136.179
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Mysql Insert.
dkin

10+ Year Member



 
Msg#: 3390492 posted 12:15 pm on Jul 10, 2007 (gmt 0)

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;

 

Habtom

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3390492 posted 12:20 pm on Jul 10, 2007 (gmt 0)

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

Romeo

10+ Year Member



 
Msg#: 3390492 posted 2:28 pm on Jul 10, 2007 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved