webtuto Posted January 10, 2008 Share Posted January 10, 2008 hi i dont knowwhy this douesnt succeed <?php include("config.php"); if($_POST['send']){ $query="select * from tuto"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { $id=$row[id]; } $sql="insert into coms set `com`='$_POST[com]' , `tuto_id`='$id'"; $res=mysql_query($sql); } it gives the wrong tuto_id numbe Quote Link to comment https://forums.phpfreaks.com/topic/85278-an-error-plz-help-out-here/ Share on other sites More sharing options...
kratsg Posted January 10, 2008 Share Posted January 10, 2008 Do you want it to get each ID number and run a query based on that ID number? Quote Link to comment https://forums.phpfreaks.com/topic/85278-an-error-plz-help-out-here/#findComment-435093 Share on other sites More sharing options...
revraz Posted January 10, 2008 Share Posted January 10, 2008 I doubt it gives the wrong one, it probably only does the last one. Quote Link to comment https://forums.phpfreaks.com/topic/85278-an-error-plz-help-out-here/#findComment-435094 Share on other sites More sharing options...
webtuto Posted January 10, 2008 Author Share Posted January 10, 2008 yeah it gaves the last one but i want it to give the number of the current page Quote Link to comment https://forums.phpfreaks.com/topic/85278-an-error-plz-help-out-here/#findComment-435097 Share on other sites More sharing options...
revraz Posted January 10, 2008 Share Posted January 10, 2008 Look at the order of your code This executes a loop in the { } brackets while($row=mysql_fetch_array($result)) { $id=$row[id]; } So all it does is load $id with a $row[id], then repeats. So when it gets to the last one it exits the loop then does the rest of your code. Write down your logic on paper. I want to do this, this and this. Then apply that logic to code. Quote Link to comment https://forums.phpfreaks.com/topic/85278-an-error-plz-help-out-here/#findComment-435098 Share on other sites More sharing options...
webtuto Posted January 10, 2008 Author Share Posted January 10, 2008 ok im gonna try Quote Link to comment https://forums.phpfreaks.com/topic/85278-an-error-plz-help-out-here/#findComment-435100 Share on other sites More sharing options...
Ken2k7 Posted January 10, 2008 Share Posted January 10, 2008 Your code will bomb out if there are no results and this would cause $id to be not defined. Also you have the wrong syntax. Are you inserting or updating. I commented on that part in the code. You should look into that. <?php include("config.php"); if($_POST['send']){ $query="select * from tuto"; $result=mysql_query($query) or die(mysql_error()); while($row=mysql_fetch_array($result)) { $id=$row['id']; } // WRONG SYNTAX FOR INSERT. DO YOU MEAN UPDATE? // $sql="update coms set com='{$_POST['com']}' , tuto_id='$id'"; $res=mysql_query($sql) or die(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/85278-an-error-plz-help-out-here/#findComment-435160 Share on other sites More sharing options...
trq Posted January 10, 2008 Share Posted January 10, 2008 Also you have the wrong syntax. Are you inserting or updating. I commented on that part in the code. You should look into that. Both styles are valid sql for an INSERT. Quote Link to comment https://forums.phpfreaks.com/topic/85278-an-error-plz-help-out-here/#findComment-435164 Share on other sites More sharing options...
Ken2k7 Posted January 10, 2008 Share Posted January 10, 2008 Also you have the wrong syntax. Are you inserting or updating. I commented on that part in the code. You should look into that. Both styles are valid sql for an INSERT. Really? Do you have a manual where it says that? Link me Quote Link to comment https://forums.phpfreaks.com/topic/85278-an-error-plz-help-out-here/#findComment-435167 Share on other sites More sharing options...
revraz Posted January 10, 2008 Share Posted January 10, 2008 Look up INSERT on MySQL, you can use SET. Quote Link to comment https://forums.phpfreaks.com/topic/85278-an-error-plz-help-out-here/#findComment-435171 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.