Jump to content

Another horrible script


HoTDaWg

Recommended Posts

hey guys, IM BACK!

and this time, with an even more terrible script! Guaranteed at least 10 syntax errors! ;D I know, i tried so hard to figure this all out myself, but its just not working out. Basically what i want to do is too take the songs posted from a form on another page and first, check if the song already exists in the db, followed by inserting the song and artist into the db. the final step is checking if a user has a session, and if he does inserting the users ip into the database followed by how many times he has requested a song (the maximum number of requests is three). Now, im going to continue tryign to figure this mess out  ??? and my deadline is sadly on saturday and i still have to make the layout and create the classes and everything. so any help would greatly be appreciated. thanks.

[code]
<?php

function insertuser(){
include "config.php";
$ip = $_SERVER["REMOTE_ADDR"];
session_start();
if(session_is_registered('firstime')){
$voted=1;
$insertsong = "INSERT INTO users (`id`, `ip`, `voted`) VALUES (0,'".$ip."','".$voted."')";
$insertquery=mysql_query($insertsong, $conn);
if($insertquery=mysql_query($insertsong)){
echo "You can request or vote for two more songs";
}else{
echo "An error has occurred. An administrator has been notified. thanks";
}
}

function request(){
$songname = $_REQUEST['songname'];
$songartist = $_REQUEST['songartist'];
$songname = strtolower($songname);
$songartist = strtolower($songartist);

$songname=str_replace(" ","",$songname);
$songartist=str_replace(" ","",$songartist);

$songname=str_replace("%20","",$songname);
$songartist=str_replace("%20","",$songartist);

$songname=addslashes($songname);
$songartist=addslashes($songartist);


if (!get_magic_quotes_gpc()) {
  foreach ($_REQUEST as $el) {
        $el = mysql_real_escape_string($el);
  }
}

include "config.php";

    $sql = "SELECT * FROM songs WHERE songname=$songname AND songartist=$songartist";
$result=mysql_query($sql);
    if ($result=mysql_query($sql)) {
      if (mysql_num_rows($result) > 0) {
        $row = mysql_fetch_assoc($result);
        if ($row['songname']=$songname) {
$query="UPDATE songs SET votes=votes+1 WHERE songname='$songname' AND songartist='$songartist'";
mysql_query($query);
echo "This song has already been requested, therefore, its vote has been increased by one";

if($query = mysql_query($query)){
echo "Your request was submitted succesfully";
}else{
echo "An error occured, your request was not successful";
}
}
}

}else{
$songvotes=0;
$insertsong = "INSERT INTO songs (`songid`, `songname`, `songartist`, `songvotes`) VALUES (0,'".$songname."','".$songartist."','".$songvotes."')";
$insertquery=mysql_query($insertsong, $conn);
insertuser();
if($insertquery=mysql_query($insertsong)){
echo "The song was requested successfully";
}else{
echo "There was an error. The song was not requested successfully";
}
}
}







function doit(){
global $songartist, $songname;
  error_reporting(E_ALL);
  define('inStereo',true);
  $ip = $_SERVER["REMOTE_ADDR"];
  include "config.php";

if(!empty ($songname) && ($songartist)){

request();
mysql_close();

}else{
echo "A field was left blank";
}
}
}


doit();

?>
[/code]

and also, is it possible to automatically indent code for if/else statements in dreamweaver? cuz right now its looking really confusing  :-\ thanks. btw, the problem is very simple before it showed nothing, and then i started tampering with a few things and then it showed this error:
[code]
Fatal error: Call to undefined function: doit() in /home/idanc48d/public_html/index2.php on line 98
[/code]

HOTDaWg
Link to comment
Share on other sites

hey made it more clear for the naked eye.
[code]
<?php

function insertuser(){
include "config.php";
$ip = $_SERVER["REMOTE_ADDR"];
session_start();
if(session_is_registered('firstime')){
$voted=1;
$insertsong = "INSERT INTO users (`id`, `ip`, `voted`) VALUES (0,'".$ip."','".$voted."')";
$insertquery=mysql_query($insertsong, $conn);
if($insertquery=mysql_query($insertsong)){
echo "You can request or vote for two more songs";
}else{
echo "An error has occurred. An administrator has been notified. thanks";
}
}

function request(){
$songname = $_REQUEST['songname'];
$songartist = $_REQUEST['songartist'];
$songname = strtolower($songname);
$songartist = strtolower($songartist);

$songname=str_replace(" ","",$songname);
$songartist=str_replace(" ","",$songartist);

$songname=str_replace("%20","",$songname);
$songartist=str_replace("%20","",$songartist);

$songname=addslashes($songname);
$songartist=addslashes($songartist);


if (!get_magic_quotes_gpc()) {
  foreach ($_REQUEST as $el) {
        $el = mysql_real_escape_string($el);
  }
}

include "config.php";

$sql = "SELECT * FROM songs WHERE songname=$songname AND songartist=$songartist";
$result=mysql_query($sql);
if ($result=mysql_query($sql)) {
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
if ($row['songname']=$songname) {
$query="UPDATE songs SET votes=votes+1 WHERE songname='$songname' AND   songartist='$songartist'";
mysql_query($query);
echo "This song has already been requested, therefore, its vote has been increased by one";

if($query = mysql_query($query)){
echo "Your request was submitted succesfully";
}else{
echo "An error occured, your request was not successful";
}
}
}

}else{
$songvotes=0;
$insertsong = "INSERT INTO songs (`songid`, `songname`, `songartist`, `songvotes`) VALUES (0,'".$songname."','".$songartist."','".$songvotes."')";
$insertquery=mysql_query($insertsong, $conn);
insertuser();
if($insertquery=mysql_query($insertsong)){
echo "The song was requested successfully";
}else{
echo "There was an error. The song was not requested successfully";
}
}
}







function doit(){
global $songartist, $songname;
  error_reporting(E_ALL);
  define('inStereo',true);
  $ip = $_SERVER["REMOTE_ADDR"];
  include "config.php";

if(!empty ($songname) && ($songartist)){

request();
mysql_close();

}else{
echo "A field was left blank";
}
}
}


doit();

?>
[/code]
Link to comment
Share on other sites

[quote author=PFMaBiSmAd link=topic=121063.msg497188#msg497188 date=1167964053]
In case you have not found this yet, the function definition of doit() is contained within the definition of insertuser().

Once you call insertuser(), the function doit() will exist.
[/quote]
i dont follow :S could you please explain again?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.