DeathStar Posted March 22, 2007 Share Posted March 22, 2007 Hi there. I made something(simple) and it not inserting info to the db: here is the code: <?php session_start(); require "spamhead.php"; print "<body bgcolor=black><center><h4><font color=white>Report someone</font></h4><br />"; if (!$_GET['action']){ echo "<form action='insertspam.php?action=do' name='insert' method='post'> <font color=white>Name: <input type='text' name='name'><br> Reson: <textarea name='reson'></textarea><br> Status: <select name='status'> <option value='1'>Abuser </option><option value='2'>Beware </option><option value='3'>Ban </option><option value='0' selected='selected'>None </option></select><br> Email: <input type='text' name='email'><br> IP: <input type='text' name='ip'><br> Whois: <textarea name='whois'></textarea><br> Date: <input type='text' name='date'><br> About: <textarea name='about'></textarea><br> Affected: <input type='text' name='affected'><br> <input type='reset' value=' Reset '><input type='submit' value=' Insert '></form>"; } elseif ($_GET['action'] == "do"){ $name1 = $_POST['name']; $name = mysql_real_escape_string($name1); $reson1 = $_POST['reson']; $reson = mysql_real_escape_string($reson1); $status1 = $_POST['status']; $status = mysql_real_escape_string($status1); $email1 = $_POST['email']; $email = mysql_real_escape_string($email1); $ip1 = $_POST['ip']; $ip = mysql_real_escape_string($ip1); $whois1 = $_POST['whois']; $whois = mysql_real_escape_string($whois1); $date1 = $_POST['date']; $date = mysql_real_escape_string($date1); $about1 = $_POST['about']; $about = mysql_real_escape_string($about1); $affected1 = $_POST['affected']; $affected = mysql_real_escape_string($affected1); mysql_query("INSERT INTO `spammers` ( `sid` , `name` , `reson` , `status` , `email` , `ip` , `date` , `other` , `about` , `whois` , `affected` ) VALUES ( NULL , $name, $reson, $status, $email, $ip, $date, $other, $about, $whois, $affexted)"); echo "<font color=red><center>Thanks for Inserting him/her to the database!";} ?> Quote Link to comment https://forums.phpfreaks.com/topic/43888-solved-data-not-inserting/ Share on other sites More sharing options...
Kerblam Posted March 22, 2007 Share Posted March 22, 2007 You mistyped $affected in the query, it says $affexted. Quote Link to comment https://forums.phpfreaks.com/topic/43888-solved-data-not-inserting/#findComment-213051 Share on other sites More sharing options...
DeathStar Posted March 22, 2007 Author Share Posted March 22, 2007 That would jsut give a blank coulom. Quote Link to comment https://forums.phpfreaks.com/topic/43888-solved-data-not-inserting/#findComment-213077 Share on other sites More sharing options...
per1os Posted March 22, 2007 Share Posted March 22, 2007 mysql_query("INSERT INTO `spammers` ( `sid` , `name` , `reson` , `status` , `email` , `ip` , `date` , `other` , `about` , `whois` , `affected` ) VALUES ( NULL , $name, $reson, $status, $email, $ip, $date, $other, $about, $whois, $affexted)") OR DIE(mysql_error()); Report the error you are getting. Chances are it is because you do not have single quotes around any of your inputted data. Quote Link to comment https://forums.phpfreaks.com/topic/43888-solved-data-not-inserting/#findComment-213078 Share on other sites More sharing options...
Kerblam Posted March 22, 2007 Share Posted March 22, 2007 Perhaps its not the php itself then? Instead of this: <form action='insertspam.php?action=do' name='insert' method='post'> Do this: <form action=insertspam.php name=insert method=post> <input type=hidden name=action value=do /> And then change the PHP to reflect this: if ($_POST['action'] == do) { etc. Quote Link to comment https://forums.phpfreaks.com/topic/43888-solved-data-not-inserting/#findComment-213081 Share on other sites More sharing options...
DeathStar Posted March 22, 2007 Author Share Posted March 22, 2007 How do you mean wiht: And then change the PHP to reflect this: Code: if ($_POST['action'] == do) { etc. Quote Link to comment https://forums.phpfreaks.com/topic/43888-solved-data-not-inserting/#findComment-213086 Share on other sites More sharing options...
per1os Posted March 22, 2007 Share Posted March 22, 2007 The problem lies within the lack of single quotes around values you are trying to insert into the DB. mysql_query("INSERT INTO `spammers` ( `sid` , `name` , `reson` , `status` , `email` , `ip` , `date` , `other` , `about` , `whois` , `affected` ) VALUES ( NULL , '$name', '$reson', '$status', '$email', '$ip', '$date', '$other', '$about', '$whois', '$affected')") OR DIE(mysql_error()); Fix that and you should be alright. And a note, I would check the reson column, make sure it is spelled the same because it should be "reason". Quote Link to comment https://forums.phpfreaks.com/topic/43888-solved-data-not-inserting/#findComment-213091 Share on other sites More sharing options...
Kerblam Posted March 22, 2007 Share Posted March 22, 2007 How do you mean wiht: And then change the PHP to reflect this: Code: if ($_POST['action'] == do) { etc. Replace: elseif ($_GET['action'] == "do"){ with: if ($_POST['action'] == do) { Quote Link to comment https://forums.phpfreaks.com/topic/43888-solved-data-not-inserting/#findComment-213101 Share on other sites More sharing options...
per1os Posted March 22, 2007 Share Posted March 22, 2007 To Kerblam: $_GET is correct because he is calling it as a get string: <form action='insertspam.php?action=do' Adding it to the action your like that sends it as a $_GET data even if you hit submit. It is still sending the action=do as get. The code is correct except for the sql query. Quote Link to comment https://forums.phpfreaks.com/topic/43888-solved-data-not-inserting/#findComment-213131 Share on other sites More sharing options...
Kerblam Posted March 23, 2007 Share Posted March 23, 2007 To Kerblam: $_GET is correct because he is calling it as a get string: <form action='insertspam.php?action=do' Adding it to the action your like that sends it as a $_GET data even if you hit submit. It is still sending the action=do as get. The code is correct except for the sql query. Read my post above that one. I suggested that being part of the problem, and using a hidden field to store action=do instead. Quote Link to comment https://forums.phpfreaks.com/topic/43888-solved-data-not-inserting/#findComment-213149 Share on other sites More sharing options...
Barand Posted March 23, 2007 Share Posted March 23, 2007 I agree with Kerblam. If the method is POST, then post the data. Quote Link to comment https://forums.phpfreaks.com/topic/43888-solved-data-not-inserting/#findComment-213155 Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 Yea, either way works to POST or to GET as long as he is calling it right. But yea that shouldn't be the problem at all =) I still say it is the single quotes, but without the original author to test the solutions suggested oh well =) Quote Link to comment https://forums.phpfreaks.com/topic/43888-solved-data-not-inserting/#findComment-213158 Share on other sites More sharing options...
Barand Posted March 23, 2007 Share Posted March 23, 2007 None of those column names suggest numeric data types, so again I agree, quotes are mandatory. Quote Link to comment https://forums.phpfreaks.com/topic/43888-solved-data-not-inserting/#findComment-213161 Share on other sites More sharing options...
DeathStar Posted March 23, 2007 Author Share Posted March 23, 2007 Now why did'nt a see that :\. Put in the quotes and now it works.. Thanks.. Quote Link to comment https://forums.phpfreaks.com/topic/43888-solved-data-not-inserting/#findComment-213336 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.