Renlok Posted September 29, 2006 Share Posted September 29, 2006 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 feedbackmod edited to conceal database access details. Quote Link to comment https://forums.phpfreaks.com/topic/22543-renlok-has-more-problems-solved/ Share on other sites More sharing options...
Barand Posted September 29, 2006 Share Posted September 29, 2006 Try changing$result = $db->query($query);to$result = $db->query($query) or die ($db->error); Quote Link to comment https://forums.phpfreaks.com/topic/22543-renlok-has-more-problems-solved/#findComment-101182 Share on other sites More sharing options...
HuggieBear Posted September 29, 2006 Share Posted September 29, 2006 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.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/22543-renlok-has-more-problems-solved/#findComment-101184 Share on other sites More sharing options...
Renlok Posted September 30, 2006 Author Share Posted September 30, 2006 [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 Link to comment https://forums.phpfreaks.com/topic/22543-renlok-has-more-problems-solved/#findComment-101300 Share on other sites More sharing options...
Barand Posted September 30, 2006 Share Posted September 30, 2006 I didn't expect it to, but I was hoping it might give an error message saying what was wrong. Quote Link to comment https://forums.phpfreaks.com/topic/22543-renlok-has-more-problems-solved/#findComment-101301 Share on other sites More sharing options...
intrik Posted September 30, 2006 Share Posted September 30, 2006 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.... Quote Link to comment https://forums.phpfreaks.com/topic/22543-renlok-has-more-problems-solved/#findComment-101307 Share on other sites More sharing options...
Barand Posted September 30, 2006 Share Posted September 30, 2006 "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 Link to comment https://forums.phpfreaks.com/topic/22543-renlok-has-more-problems-solved/#findComment-101309 Share on other sites More sharing options...
marknt Posted September 30, 2006 Share Posted September 30, 2006 [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()); Quote Link to comment https://forums.phpfreaks.com/topic/22543-renlok-has-more-problems-solved/#findComment-101310 Share on other sites More sharing options...
Renlok Posted September 30, 2006 Author Share Posted September 30, 2006 yes im just trying to grab post var's and inserting them into the databaseok you wanted the error message its shows as:Column count doesn't match value count at row 1 Quote Link to comment https://forums.phpfreaks.com/topic/22543-renlok-has-more-problems-solved/#findComment-101311 Share on other sites More sharing options...
Barand Posted September 30, 2006 Share Posted September 30, 2006 In which case, did you try HuggieBear's recomendation and specify the column names? Quote Link to comment https://forums.phpfreaks.com/topic/22543-renlok-has-more-problems-solved/#findComment-101312 Share on other sites More sharing options...
Renlok Posted September 30, 2006 Author Share Posted September 30, 2006 i tryed that then it posts Unknown column 'description' in 'field list' Quote Link to comment https://forums.phpfreaks.com/topic/22543-renlok-has-more-problems-solved/#findComment-101313 Share on other sites More sharing options...
Barand Posted September 30, 2006 Share Posted September 30, 2006 What are you column names then? Use those, we can only guess. Quote Link to comment https://forums.phpfreaks.com/topic/22543-renlok-has-more-problems-solved/#findComment-101314 Share on other sites More sharing options...
Renlok Posted September 30, 2006 Author Share Posted September 30, 2006 oh lol yes that work theres a spelling error in my database =]] thanks for all the help Quote Link to comment https://forums.phpfreaks.com/topic/22543-renlok-has-more-problems-solved/#findComment-101316 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.