Inserting Value in SQL

Started on the old forum in April 2009 · view the original in the archive · old links redirect here

7 replies · 493 views · started 17 years ago · 1 min read

5 participants
modfiles Developer · 200 posts #1

My head is spinning again coz im thinking why i cant insert in mySQL the input value in text box. Can anyone help me with this. If I change

<form method="get" action="index.php">

to

<form method="post" action="index.php">

the input will save in sql but it will not return any search result. Heres the code:

<form method="get" action="index.php">
    <div>
    <input type="text" name="search"/>
    <input type="submit" value="<?=$lang[Search]?>"/>
    <input type="hidden" name="source" value="some_value"/>
    </div>
    </form>
    <div>
    <b>Some Project</b><br/>
    <?php
    $search=$_POST["search"];
    $spaces = str_replace(" ","",$search);
    if($spaces != "" && $search != "") {
    $spacez = str_replace(" ","",$search);
    $kill = str_replace("'","",$search);
    if(strlen($search) < 26) {
    if($spacez != "" && $search != "") 
      {
        $check = mysql_num_rows(mysql_query("SELECT * FROM search WHERE query = '$kill'"));
        if($check < 1) 
      {
        mysql_query("INSERT INTO search VALUES('','$search','0')");
        } else {
        mysql_query("UPDATE search SET searches = searches+1 WHERE query = '$search'");
        }
    }
  }
}
Guest #2

try this

shouldnt the insert query look like "INSERT INTO SEARCH (FIELDNAME1,FIELDNAME2,FIELDNAME3) VALUES(VALUE1,VALUE2,VAKLUE3)"

iam just guessing !hope it works

modfiles Developer · 200 posts #4

^ your post yesterday was deleted by mods cause it was no help/nonsense/spam and you posted another one again. lol.

nahsorhseda, that code is working fine. im just having problem with GET and POST.

Guest #5

replace

$search=$_POST["search"];

with

$search=$_REQUEST["search"];

Loony Senior · 258 posts #6

modfiles wrote:

<form method="post" action="index.php">
<form method="post" action="index.php">
    <div>
    <input type="text" name="search"/>
    <input type="submit" value="<?=$lang[Search]?>"/>
    <input type="hidden" name="source" value="some_value"/>
    </div>
    </form>
    <div>
    <b>Some Project</b><br/>
    <?php
    $search=$_POST["search"];
    $spaces = str_replace(" ","",$search);
    if($spaces != "" && $search != "") {
    $spacez = str_replace(" ","",$search);
    $kill = str_replace("'","",$search);
    if(strlen($search) < 26) {
    if($spacez != "" && $search != "") 
      {
        $check = mysql_num_rows(mysql_query("SELECT * FROM search WHERE query = '$kill'"));
        if($check < 1) 
      {
        mysql_query("INSERT INTO search VALUES('','$search','0')");
        } else {
        mysql_query("UPDATE search SET searches = searches+1 WHERE query = '$search'");
        }
    }
  }
}

i edited your post in the quote try that try not to use get or request its not as secure

Creator of Epix.Mobi

Keep an Eye on us Big things coming soon!!!! Need something for your site hit me up here http://coding-talk.com/forum/main-forums/marketplace/153110-free-features-for-your-wapsite

syrus Junior · 44 posts #7
 

        $check = mysql_query("SELECT * FROM search WHERE query LIKE '%$kill%'"); 
while($sresults = mysql_fetch_array($check))
{ echo "$sresults[0] <br />"; }
       
djlee Developer · 224 posts #8

are you insane id suggest

  mysql_query("INSERT INTO search VALUES('','".mysql_real_escape_string($search)."','0')"); 

before someone drops ur tables

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close