my code <?php if(isset($_POST['submit'])){ $Title = $_POST['Title']; $Weburl = $_POST['Weburl']; $Category = $_POST['Category']; $UserIp = $_SERVER['REMOTE_ADDR']; $AddDate = date('Y-m-d'); $Add = "1"; if ($Title != "Title?" && $Title != " " && $Weburl != "http://" && $Category != "0") { $query = "INSERT INTO web_url1 (Title,Weburl,Category,UserIp,AddDate) VALUES ('$Title', '$Weburl', '$Category', '$UserIp', '$AddDate')"; $query = "INSERT INTO web_url2 (Weburl,UserIp) VALUES ('$Weburl', '$UserIp')"; mysql_query($query); $addlink_msg = "Success! Your Video has been added!"; } else { $addlink_msg = "You Mistake Someting!"; } } ?> PHP: this part is not working $query = "INSERT INTO web_url1 (Title,Weburl,Category,UserIp,AddDate) VALUES ('$Title', '$Weburl', '$Category', '$UserIp', '$AddDate')"; $query = "INSERT INTO web_url2 (Weburl,UserIp) VALUES ('$Weburl', '$UserIp')"; mysql_query($query); PHP: how i can add 2 query INSERT ? thanks for any help
U are modifying $query just after it is declared. In this way, the first query isnt of any use. Try this $query = "INSERT INTO `web_url1` (Title,Weburl,Category,UserIp,AddDate) VALUES ('$Title', '$Weburl', '$Category', '$UserIp', '$AddDate');"; $another_query = "INSERT INTO `web_url2` (Weburl,UserIp) VALUES ('$Weburl', '$UserIp');"; mysql_query($query); mysql_query($another_query); PHP:
you have written in wrong manner .search on net to find correct way ryt is like$ querry="your query" . $query=$query." next query";
you can use any mysql pharser to do that easly http://www.jooria.com/projects/view?project=927 http://www.jooria.com/projects/view?project=946 http://www.jooria.com/projects/view?project=927 but it optional just for make it easly
i try like this $querry = "INSERT INTO " . $dbtable . " (Title,Weburl,Category,UserIp,AddDate) VALUES ('$Title', '$Weburl', '$Category', '$UserIp', '$AddDate')"; $query = $query . "INSERT INTO web_url (Weburl,UserIp) VALUES ('$Add', '$UserIp')"; mysql_query($query); PHP: and like this $querry = "INSERT INTO " . $dbtable . " (Title,Weburl,Category,UserIp,AddDate) VALUES ('$Title', '$Weburl', '$Category', '$UserIp', '$AddDate')"; $query = $querry . "INSERT INTO web_url (Weburl,UserIp) VALUES ('$Add', '$UserIp')"; mysql_query($query); PHP: the first is working just $query and the last is not working nothing ... hope someone can help me ..
Try this one: <pre> $querry = "INSERT INTO " . $dbtable . " (Title,Weburl,Category,UserIp,AddDate) VALUES ('$Title', '$Weburl', '$Category', '$UserIp', '$AddDate')"; $query = $querry . "INSERT INTO web_url (Weburl,UserIp) VALUES ('$Add', '$UserIp')"; $first_query = mysql_query($query); if($first_query == 1) { mysql_query($querry); } </pre>
use shubhamjain's $query = "INSERT INTO `web_url1` (Title,Weburl,Category,UserIp,AddDate) VALUES ('$Title', '$Weburl', '$Category', '$UserIp', '$AddDate');"; $another_query = "INSERT INTO `web_url2` (Weburl,UserIp) VALUES ('$Weburl', '$UserIp');"; mysql_query($query); mysql_query($another_query); PHP: or this $query = "INSERT INTO `web_url1` (Title,Weburl,Category,UserIp,AddDate) VALUES ('$Title', '$Weburl', '$Category', '$UserIp', '$AddDate');"; mysql_query($query); $query = "INSERT INTO `web_url2` (Weburl,UserIp) VALUES ('$Weburl', '$UserIp');"; mysql_query($query); PHP:
Also just a FYI for future refrences, be careful when using a ' or a ", the ' does not look for variables inside of it (use this when you dont have any variables in the string, like an echo to speed up your scripts slightly).