soltek Posted October 8, 2011 Share Posted October 8, 2011 Hey! I've spent an hour and a haldf - lulz indeed - trying to figure out what's wrong with my code, but I couldnt. Could you take a look? <? include("db.php"); session_start(); if(!session_is_registered(myusername)){ header("location:main_login.php"); } $id = (int)$_GET['id']; $res = "SELECT * FROM tvshows WHERE id = '$id'"; $result = mysql_query($res) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $show = $row[show]; $episode = $row[episode]; $title = $row[title]; $airdate = $row[airdate]; $numero = $row[id]; } ?> </head> <body> <div style="background-color: #b1b2b2;width:300px;float:left;"> <h1>Adding entries:</h1> <div id="preview"></div> <div id="formbox"> <form name="form" id="form" action="submit-edit.php" method="post"> <ul id="ngothastyle3"> <li> <label>Show</label> <input type="hidden" name="numero" class="" value="<? echo $numero; ?>" maxlength="40" /> <input type="text" name="show" class="" value="<? echo $show; ?>" maxlength="40" /> </li> <li> <label>Episode</label> <input type="text" name="episode" class="" value="<? echo $episode; ?>" maxlength="40" /> </li> <li> <label>Title</label> <input type="text" name="title" class="" value="<? echo $title; ?>" maxlength="40" /> </li> <li> <label>Airdate</label> <input type="text" name="airdate" class="" value="<? echo $airdate; ?>" maxlength="40" /> </li> <li> <label> </label> <input type="submit" value="Submit"> </li> </ul> </form> </div> </div> <div style="clear:both;"></div> </body> </html> Edit file: <?php include("db.php"); if($_SERVER["REQUEST_METHOD"] == "POST") { $numero= (int)$_POST['numero']; $show=mysql_real_escape_string($_POST['show']); $episode=mysql_real_escape_string($_POST['episode']); $title=mysql_real_escape_string($_POST['title']); $airdate=mysql_real_escape_string($_POST['airdate']); if(strlen($episode)>0) { ///THIS PART /// $sql = "UPDATE tvshows SET id = '" . $numero . "', show = '" . $show . "', episode = '" . $episode . "', title = '" . $title . "', airdate = '" . $airdate . "' WHERE id = '" . $numero . "'"; ///// echo "<h2>Thank You !</h2>"; echo "Job done"; }else{ echo "hmmm... something is wrong."; } } ?> I've been messing around and I think the problem is somewhere in the query in red, the bold part. If you could give me a hand, I'll drink for you Link to comment https://forums.phpfreaks.com/topic/248671-whats-wrong-with-this-query/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 8, 2011 Share Posted October 8, 2011 show is a reserved mysql keyword. You either need to rename your column or you must enclose `show` in back-ticks every time you use it as a column name in your queries. Link to comment https://forums.phpfreaks.com/topic/248671-whats-wrong-with-this-query/#findComment-1277138 Share on other sites More sharing options...
soltek Posted October 8, 2011 Author Share Posted October 8, 2011 You are right, thanks! Link to comment https://forums.phpfreaks.com/topic/248671-whats-wrong-with-this-query/#findComment-1277222 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.