<h1>Test 3: mysql</h1> <?bash USER="root" PASS="12345678" DB="mod_bash" function escape { echo -n $1 | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' } function save { A="`mysql -u "$USER" -p"$PASS" -e "show databases" | grep "$DB"`" if [ "$A" = "" ]; then mysql -u "$USER" -p"$PASS" -e "create database $DB" || return 1 mysql -u "$USER" -p"$PASS" "$DB" -e " create table friends ( id integer not null primary key auto_increment, firstname char(255), secondname char(255) )" || return 1 fi mysql -u "$USER" -p"$PASS" "$DB" -e "insert into friends values(NULL, \"`escape "$firstname"`\", \"`escape "$secondname"`\");" || return 1 } function remove { mysql -u "$USER" -p"$PASS" "$DB" -e "delete from friends where id=`escape "$1"`" } if [ "$firstname" != "" ] && [ "$secondname" != "" ]; then save "$firstname" "$secondname" fi if [ "$remove" != "" ]; then remove "$remove" fi ?> <html> <form action="mysql.bash" method="get"> First name: <input type="text" name="firstname" /><br /> Second name: <input type="text" name="secondname" /><br /> <input type="submit" value="Save!" /> </form> <pre>Remove contantcs:<br /><br /><?bash RESULTS="`mysql -u "$USER" -p"$PASS" "$DB" -e "select * from friends"`" NLINES="`echo "$RESULTS" | wc -l`" for i in `seq 2 $NLINES`; do LINE="`echo "$RESULTS" | head -n $i | tail -n 1`" ID="`echo $LINE | awk '{print $1}'`" ?><a href="mysql.bash?remove=<?bash echo -n $ID ?>"><?bash echo -n $ID ?></a> - <?bash echo "$LINE" | awk '{print $2,$3}' done ?> </pre> </html>