HoTDaWg Posted January 5, 2007 Share Posted January 5, 2007 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]<?phpfunction 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 Quote Link to comment Share on other sites More sharing options...
papaface Posted January 5, 2007 Share Posted January 5, 2007 In dreamweaver press the tab key to indent. Its much easier to read. Quote Link to comment Share on other sites More sharing options...
HoTDaWg Posted January 5, 2007 Author Share Posted January 5, 2007 thanks. Quote Link to comment Share on other sites More sharing options...
HoTDaWg Posted January 5, 2007 Author Share Posted January 5, 2007 hey made it more clear for the naked eye.[code]<?phpfunction 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] Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 5, 2007 Share Posted January 5, 2007 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 Link to comment Share on other sites More sharing options...
HoTDaWg Posted January 5, 2007 Author Share Posted January 5, 2007 [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? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 5, 2007 Share Posted January 5, 2007 See Example 17-3 at this link - http://www.php.net/manual/en/language.functions.php#functions.user-defined Quote Link to comment Share on other sites More sharing options...
HoTDaWg Posted January 5, 2007 Author Share Posted January 5, 2007 i have made many advances in the code over this time, but have still not figured it out. i will most likely create a new topic explaining the situation if i need help later. thanks to all. topic locked. Quote Link to comment 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.