Q695 Posted May 1, 2013 Share Posted May 1, 2013 I heed help with a logic/basic scripting check that allows people to change data if it's not being pulled: if( empty($_GET['____________'])){insert statement } else if( isset($_GET['___________'])){ update statement }it's going to the insert statement when it should be going to the update statement. Quote Link to comment Share on other sites More sharing options...
requinix Posted May 1, 2013 Share Posted May 1, 2013 Then that thing in $_GET is empty(). No way around that. Could be missing, 0, or an empty string. Quote Link to comment Share on other sites More sharing options...
Q695 Posted May 1, 2013 Author Share Posted May 1, 2013 there isn't a variable in it, so I need to see if the get variable is there, or not. Quote Link to comment Share on other sites More sharing options...
requinix Posted May 1, 2013 Share Posted May 1, 2013 And the code you have now will do that... as long as you've actually filled in those ___s. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted May 1, 2013 Share Posted May 1, 2013 Could you provide a little more information about what you're trying to do? Quote Link to comment Share on other sites More sharing options...
Q695 Posted May 1, 2013 Author Share Posted May 1, 2013 (edited) I'm thinking I should try rewriting it from step 1, because many things are working, but some seem screwed up. Below is the code, but now it's not naming the image, or uploading it after I tried fixing it: image uploader <?php //$path folder of location being uploaded to on recieving page //$path full path of image //$table_name name of table being checked //$var_check name of variable in table //$path_rand image path in directory //$user primary criteria //$id criteria item //$limitor secondary criteria //$item secondary criteria item //$picture picture item name if ($_FILES['creature_image']['error']=0){ // loads image variables $name = $_FILES['creature_image']['name']; $temp = $_FILES['creature_image']['tmp_name']; $type = $_FILES['creature_image']['type']; $size = $_FILES['creature_image']['size']; //size of uploaded image $img_size = getimagesize( $temp ); $width= $img_size[0]; $height= $img_size[1]; //requirements $maxwidth = 1280; $maxheight = 1280; $maxsize= 1048576; $allowed = array('image/jpeg' , 'image/png' , 'image/gif'); //revisions $new_width=300; $new_height=300; if (in_array($type, $allowed)){ if ( empty($_GET['creature']) ){ $m=0; while ($m <= 100) { //random charicter generator $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $randomString = ''; for ($i = 0; $i < 64; $i++) { $randomString .= $characters[rand(0, strlen($characters) - 1)]; } $path_rand = $randomString; $sql_img_test= "SELECT * FROM $table_name WHERE $var_check='$path_rand' limit 1"; $result_img = mysql_query($sql_img_test, $con) or die ("can not generate result " . mysql_error()); $row_img = mysql_fetch_assoc($result_img); if (!$row_img){ $m=101; } else { $m++; } //end of new entry } } else { $sql_img_test= "SELECT * FROM $table_name WHERE $user='$id' && $limitor=$item limit 1"; $result_img = mysql_query($sql_img_test, $con) or die ("can not generate result " . mysql_error()); $row_img = mysql_fetch_assoc($result_img); $path_rand=$row_img[$picture]; echo "image updated"; } } //image load path $path= "$path$path_rand.jpg"; //echo $path; // uploading file, and create database entry move_uploaded_file($temp,$path); //places image in file location } else { echo "Image not uploaded."; } ?> the database inserter: <?php $path="images/new_creatures/ "; $table_name="creature_create"; $var_check= "picture"; $user = 'user'; //$id = '$id'; $limitor = 'creature_id'; $picture='picture'; if (isset($_GET['creature'])){ $item = $_GET['creature']; } if ( isset($_POST['creature_name']) && isset($_FILES['creature_image']) && isset($_POST['def_rate']) && isset($_POST['def_rate_range']) && isset($_POST['att_rate']) && isset($_POST['att_rate_range']) && isset($_POST['def']) && isset($_POST['def_range']) && isset($_POST['att']) && isset($_POST['att_range']) && isset($_POST['health']) && isset($_POST['health_range']) ){ include "image_upload.php"; $name = $_POST['creature_name']; //$image = $path_rand; $def_rate = $_POST['def_rate']; $def_rate_range=$_POST['def_rate_range']; $att_rate=$_POST['att_rate']; $att_rate_range=$_POST['att_rate_range']; $def=$_POST['def']; $def_range=$_POST['def_range']; $att=$_POST['att']; $att_range=$_POST['att_range']; $health=$_POST['health']; $health_range=$_POST['health_range']; if( empty($_GET['creture'])){ echo "empty"; $sql_new_creature="INSERT INTO creature_create (`user`, `name`, `def_rate`, `def_rate_dif`, `att_rate`, `att_rate_dif`, `def`, `def_dif`, `att`, `att_dif`, `health`, `health_dif`) VALUES ('$id', '$name', '$def_rate', '$def_rate_range', '$att_rate', '$att_rate_range', '$def', '$def_range', '$att', '$att_range', '$health', '$health_range');"; //echo $sql_new_creature; $sql_creature = "SELECT * FROM `creature_create` WHERE user=$id LIMIT 1"; $result_creature = mysql_query($sql_creature, $con) or die ("can not generate result " . mysql_error()); $row_creature = mysql_fetch_assoc($result_creature); $path_rand=$row_creature['picture']; } else if( isset($_GET['creture'])){ // echo "set"; $creature=$_GET['creture']; $sql_new_creature=" UPDATE creature_create SET `name` = '$name', `def_rate` = '$def_rate', `def_rate_dif` = '$def_rate_range', `att_rate` = '$att_rate', `att_rate_dif` = '$att_rate_range', `def` = '$def', `def_dif` = '$def_range', `att` = '$att', `att_dif` = '$att_range', `health` = '$health', `health_dif` = '$health_range' WHERE `creature_id` = '$creature'; "; /*$sql_creature = "SELECT * FROM `creature_create` WHERE user=$id LIMIT 1"; $result_creature = mysql_query($sql_creature, $con) or die ("can not generate result " . mysql_error()); $row_creature = mysql_fetch_assoc($result_creature); */ $path_rand=$row_creature['picture']; //echo $sql_new_creature; } } else { echo "error"; $sql_creature = "SELECT * FROM `creature_create` WHERE user=$id LIMIT 1"; $result_creature = mysql_query($sql_creature, $con) or die ("can not generate result " . mysql_error()); $row_creature = mysql_fetch_assoc($result_creature); $path_rand=$row_creature['picture']; } $result = mysql_query($sql_new_creature, $con) or die ("can not generate result " . mysql_error()); $def_rate_max=$def_rate+$def_rate_range; $att_rate_max=$att_rate+$att_rate_range; $def_max=$def+$def_range; $att_max=$att+$att_range; echo" <table width='100%' border='1' cellspacing='0' cellpadding='0'> <tr> <td align='center' colspan='2'> <h1>$name</h1> <br> <img src='images/new_creatures/ $path_rand.jpg' width='200' height='200'> </td> </tr> <tr> <td>Attack Rate: $att_rate - $att_rate_max</td> <td>Defense Rate: $def_rate - $def_rate_max</td> </tr> <tr> <td>Attack: $att - $att_max</td> <td>Defense: $def - $def_max</td> </tr> </table> "; ?> It will upload/rewrite an image/content for user added content before a submission for a suggested addition to a game. Edited May 1, 2013 by Q695 Quote Link to comment Share on other sites More sharing options...
DavidAM Posted May 1, 2013 Share Posted May 1, 2013 1) A single equals-sign is ASSIGNMENT, it takes two to COMPARE: if ($_FILES['creature_image']['error']=0){ 2) It looks like you spelled the GET variable wrong: if (isset($_GET['creature'])){ $item = $_GET['creature']; } ... if( empty($_GET['creture'])){ echo "empty"; $sql_new_creature="INSERT INTO creature_create Quote Link to comment Share on other sites More sharing options...
Solution Q695 Posted May 1, 2013 Author Solution Share Posted May 1, 2013 I always copy my get variable from my print_r ($_GET); 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.