Lamez Posted February 24, 2008 Share Posted February 24, 2008 The script below is suppose to see if there is any data in the MySQL table, and if there is it uses the MySQL update function, if not then it is suppose to add the new data. It does not update or add, what am I doing wrong here? <?php include ("../../style/include/session.php"); include ("../../style/include/cons/head_2.php"); if($session->isAdmin()){ print '<div class="box"><h2>Point Value Settings</h2>'; ?> <SCRIPT TYPE="text/javascript"> function numbersonly(myfield, e, dec) { var key; var keychar; if (window.event) key = window.event.keyCode; else if (e) key = e.which; else return true; keychar = String.fromCharCode(key); // control keys if ((key==null) || (key==0) || (key== || (key==9) || (key==13) || (key==27) ) return true; // numbers else if ((("0123456789").indexOf(keychar) > -1)) return true; // decimal point jump else if (dec && (keychar == ".")) { myfield.form.elements[dec].focus(); return false; } else return false; } //--> </SCRIPT> <?php $getlink = $_GET["action"]; $link = md5("addpointstodb"); if ($getlink == $link) { if(isset ($_POST['Submit'])){ $a = $_POST['1']; $b = $_POST['2']; $c = $_POST['3']; $d = $_POST['4']; $e = $_POST['5']; $f = $_POST['6']; $q = "Select count(*) as row_count from `points`"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0){ $q = "UPDATE `points` SET `1`=$a WHERE `1`='$a', '$b', '$c'"; mysql_query($q)or die(mysql_error()); echo "Updated Points to Database"; echo '<br><br><a href="pinval.php">View Points</a>'; }else{ $q = "INSERT INTO `points` VALUES ('$a', '$b', '$c', '$d', '$e', '$f', '$g')"; mysql_query($q)or die(mysql_error()); echo "Added points to Database"; echo '<br><br><a href="pinval.php">View Points</a>'; } }else{ echo "No data to enter"; echo '<br><br><a href="pinval.php">Try Again</a>'; } }else{ $paid = "select * from points"; $q = mysql_query($paid) or die('Error: ' . mysql_error()); $rs=mysql_fetch_array($q); ?> <form name="updatepoints" method="post" action="?action=<?php echo $link; ?>"> <table width="387" height="198" border="0"> <tr> <td width="136"><strong>Round Name </strong></td> <td width="124"><strong>Point Value </strong></td> <td width="113"> </td> </tr> <tr> <td>1st Round </td> <td align="center"><input name="2" type="text" id="2" onkeypress="return numbersonly(this, event)" size="10" value="<?php echo $rs['2']; ?>" /></td> <td> </td> </tr> <tr> <td>2nd Round </td> <td align="center"><input name="3" type="text" id="3" onkeypress="return numbersonly(this, event)" size="10" value="<?php echo $rs['3']; ?>" /></td> <td> </td> </tr> <tr> <td>Sweet 16 </td> <td align="center"><input name="4" type="text" id="4" onkeypress="return numbersonly(this, event)" size="10" value="<?php echo $rs['4']; ?>" /></td> <td> </td> </tr> <tr> <td>Elite Eight </td> <td align="center"><input name="5" type="text" id="5" onkeypress="return numbersonly(this, event)" size="10" value="<?php echo $rs['5']; ?>" /></td> <td> </td> </tr> <tr> <td>Final Four </td> <td align="center"><input name="6" type="text" id="6" onkeypress="return numbersonly(this, event)" size="10" value="<?php echo $rs['6']; ?>" /></td> <td> </td> </tr> <tr> <td>Championship</td> <td align="center"><input name="7" type="text" id="7" onkeypress="return numbersonly(this, event)" size="10" value="<?php echo $rs['7']; ?>" /></td> <td> </td> </tr> <tr> <td> </td> <td align="left"><input type="submit" name="Submit" value="Submit" /> <input name="Reset" type="reset" id="Reset" value="Reset" /></td> <td align="left"><label></label></td> </tr> </table> </form> <p> </p> <?php } }else{ header("Location: ../../index.php"); } print '</div>'; include ("../../style/include/cons/foot.php"); ?> Quote Link to comment Share on other sites More sharing options...
themistral Posted February 24, 2008 Share Posted February 24, 2008 I may be missing something here, but where is your connection to the database? Quote Link to comment Share on other sites More sharing options...
drisate Posted February 24, 2008 Share Posted February 24, 2008 can you add this and tel me what you get echo "$getlink is really = to $link"; put it before if ($getlink == $link) { Quote Link to comment Share on other sites More sharing options...
Lamez Posted February 24, 2008 Author Share Posted February 24, 2008 add what? and to connect to the db is in session.php which is included on line 1 or 2 Quote Link to comment Share on other sites More sharing options...
drisate Posted February 24, 2008 Share Posted February 24, 2008 this echo "$getlink is really = to $link"; befor this if ($getlink == $link) { A possible problems could be that $getlink is not = to $link so the update never happens. It's hard to find resons of what can cause your problem since all you told us is it's not working ... Quote Link to comment Share on other sites More sharing options...
Lamez Posted February 24, 2008 Author Share Posted February 24, 2008 I get this: is really = to bb1dd8ff5cfa7a62010a1f586d0dfa27 Quote Link to comment Share on other sites More sharing options...
ucffool Posted February 24, 2008 Share Posted February 24, 2008 That means that your expression: if ($getlink == $link) { is not evaluating as TRUE, because per your output, $getlink is empty or "", and $link = bb1dd8ff5cfa7a62010a1f586d0dfa27 So you need to evaluate where $getlink is going wrong. Quote Link to comment Share on other sites More sharing options...
Lamez Posted February 24, 2008 Author Share Posted February 24, 2008 no that is not the problem, it is the mysql query, that part works great. Quote Link to comment Share on other sites More sharing options...
Lamez Posted February 24, 2008 Author Share Posted February 24, 2008 this is my mysql error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `1`='', '546', '985'' at line 1 Quote Link to comment Share on other sites More sharing options...
Lamez Posted February 24, 2008 Author Share Posted February 24, 2008 how do I do more than one value in a Update Query? Quote Link to comment Share on other sites More sharing options...
themistral Posted February 24, 2008 Share Posted February 24, 2008 List the fields to update and separate with commas. UPDATE table SET field1 = "item1", field2 = "item2" WHERE clause here 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.