LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Backend problem in bash!! (https://www.linuxquestions.org/questions/programming-9/backend-problem-in-bash-311979/)

Alexander.s 04-11-2005 07:43 AM

Backend problem in bash!!
 
Currently using:
MySQL
Bash
Apache

Im creating a script wich is intented for my website. It records what your typing
and throws it out on your screen, if it exists.

My humble question is what have i done wrong?
The "else" and "fi" commands are marked red thats Vim's way saying iv done wrong
but i dont know exactly what i have done wrong?

Thanks!

edit: The script still wont do anything, when i search for something nothing happens :(


Regards / Alexander / Sweden




------------------------------------------------------------------------------------------------------
#!/bin/bash/


TITEL=$(echo $QUERY_STRING | cut -d\& -f1 | cut -d= -f2)
DATUM=$(echo $QUERY_STRING | cut -d\& -f2 | cut -d= -f2)
TEXT=$(echo $QUERY_STRING | cut -d\& -f3 | cut -d= -f2)
KOLL=$(echo "SELECT count(titel) FROM TEXTER WHERE titel='$TEXTER';"| mysql -N -u root TEXTER)

#skriv en HTTP-Header
echo "content-type: text/html"
echo

#Skriv en HTML-Header
echo "<HTML><HEAD><TITLE>Resultat</TITLE></HEAD><BODY>

if [ $KOLL -ne 0 ]; then
echo "<h4 style=\"color: #fff\">Titeln $TITEL finns redan!.</h4>"

else

echo "INSERT INTO TEXTER(titel,datum,text) VALUES ('$TEXTER','$DATUM','$TEXT');"| mysql -u root -N TEXTER
echo "Titeln till texten är tillagd"
fi

echo "SELECT titel FROM TEXTER;" | mysql -N -u root TEXTER > /tmp/sqlsvar
IFS=$'\n'
echo "<P>Dessa Titlar finns i tabellen</P>"
echo "<ul>"
for i in $(cat /tmp/sqlsvar); do
echo "<li>$i</li>"
done
echo "</ul>"

# skriv HTML-slutet
echo "</body></html>
-----------------------------------------------------------------------------------------------------

bigearsbilly 04-11-2005 07:57 AM

vim is not the arbiter of correctness.
it's an editor,

If the script runs OK then vim is wrong.
It's only doing syntax highlighting.

Alexander.s 04-11-2005 09:17 AM

Iv corrected the syntax but the script still wont work :(

bigearsbilly 04-11-2005 09:56 AM

what does it say in your apache error log
when you access the page?

(have you considered using perl CGI?)

Alexander.s 04-11-2005 04:47 PM

i only know bash:(

Did you get what im after here on my webpage? i want to search in my database and make the results
end up in the webbrowser.

Could you guys give me a hint on what i should do?
maybe show me a script in perl that can do what im trying to do in bash?

My first script is for inserting data into the database and this one was supposed to take it out.


Thanks!


Regards / Alexander / Sweden


All times are GMT -5. The time now is 01:08 PM.