PhdJB Posted June 6, 2007 Share Posted June 6, 2007 Okay well my php code works...but when i check my mysql database nothing has changed....??? Quote Link to comment https://forums.phpfreaks.com/topic/54505-problem-with-submission/ Share on other sites More sharing options...
papaface Posted June 6, 2007 Share Posted June 6, 2007 That isnt very helpful! Provide some code. Quote Link to comment https://forums.phpfreaks.com/topic/54505-problem-with-submission/#findComment-269585 Share on other sites More sharing options...
PhdJB Posted June 6, 2007 Author Share Posted June 6, 2007 <? // run query 1-16 $result = mysql_query($query); // run query 17 $result = mysql_query($query17); // run query 18 $result = mysql_query($query18); // run query 19 $result = mysql_query($query19); // run query 20 $result = mysql_query($query20); // run query 21 $result = mysql_query($query21); // run query 22 $result = mysql_query($query22); // run query 23 $result = mysql_query($query23); // run query 24 $result = mysql_query($query24); // run query 25 $result = mysql_query($query25); // connect to database // $dbh = mysql_connect($host, $username, $password, $db); if (!$dbh) { die('Could not connect: ' . mysql_error()); } // close transaction // mysql_close(); ?> and than my variables Quote Link to comment https://forums.phpfreaks.com/topic/54505-problem-with-submission/#findComment-269594 Share on other sites More sharing options...
papaface Posted June 6, 2007 Share Posted June 6, 2007 You arent actually running any queries you are just storing the SQL in a variable, in this case $result. Also each time $result is being overwritten by the next instance of $result. Quote Link to comment https://forums.phpfreaks.com/topic/54505-problem-with-submission/#findComment-269597 Share on other sites More sharing options...
PhdJB Posted June 6, 2007 Author Share Posted June 6, 2007 Here is my actual code now: <? mysql_query($query); mysql_query($query17); mysql_query($query18); mysql_query($query19); mysql_query($query20); mysql_query($query21); mysql_query($query22); mysql_query($query23); mysql_query($query24); mysql_query($query25); mysql_connect($host, $username, $password, $db); mysql_close() ?> Quote Link to comment https://forums.phpfreaks.com/topic/54505-problem-with-submission/#findComment-269606 Share on other sites More sharing options...
Dragen Posted June 6, 2007 Share Posted June 6, 2007 your code doesn't seem to make any sense to me.. maybe I'm just being tired and stupid, but how is the mysql_query suppossed to take place before you've connected to the database? also listing the queries like you have doesn't seem to be doing anything either. Quote Link to comment https://forums.phpfreaks.com/topic/54505-problem-with-submission/#findComment-269607 Share on other sites More sharing options...
PhdJB Posted June 7, 2007 Author Share Posted June 7, 2007 this is about the second day that ive done php so i really have no idea, so anything would help. Quote Link to comment https://forums.phpfreaks.com/topic/54505-problem-with-submission/#findComment-269609 Share on other sites More sharing options...
Dragen Posted June 7, 2007 Share Posted June 7, 2007 a mysql query along with the connection should look something like this: <?php mysql_connect($host, $username, $password, $db); //this connects to thte database $sql = "INSERT INTO TABLENAME (`CELL1`, `CELL2`, `CELL3`, `CELL4`) VALUES ('VALUE1', 'VALUE2', 'VALUE3', 'VALUE3') WHERE `CELL1` = 'VALUE' LIMIT 1"; //this inserts data if($result = mysql_query($sql)){ //this checks if the insert worked, if so echos to say so echo "mysql query successfull"; }else{ echo "Query failed<br />\n".mysql_error()."\n"; //otherwise it throws up an error } mysql_close() //this closes thte connection ?> you need to change TABLENAME to the name of the table and CELL1, CELL2 etc to thte corresp[onding cel names in thte table for the values. I hope that helps. What are you actually trying to do? add to a database or remove? or even just read from it? Quote Link to comment https://forums.phpfreaks.com/topic/54505-problem-with-submission/#findComment-269612 Share on other sites More sharing options...
PhdJB Posted June 7, 2007 Author Share Posted June 7, 2007 what if i need to do multiple queries? Quote Link to comment https://forums.phpfreaks.com/topic/54505-problem-with-submission/#findComment-269614 Share on other sites More sharing options...
Wireless102 Posted June 7, 2007 Share Posted June 7, 2007 setup your querys as an array $querys[0] = "INSERT INTO table (id) VALUES (null)"; $querys[1] = "INSERT INTO table (id) VALUES (null)"; $querys[2] = "INSERT INTO table (id) VALUES (null)"; $querys[3] = "INSERT INTO table (id) VALUES (null)"; foreach($querys as $query => $structure){ mysql_query($structure) or die(mysql_error()); } that off the top of my head but i think it will work Quote Link to comment https://forums.phpfreaks.com/topic/54505-problem-with-submission/#findComment-269617 Share on other sites More sharing options...
Dragen Posted June 7, 2007 Share Posted June 7, 2007 yeah, that should work.. Just a slight edit, to how I'd prefer to do it <?php mysql_connect($host, $username, $password, $db); //this connects to the database $querys[0] = "INSERT INTO table (id) VALUES (null)"; $querys[1] = "INSERT INTO table (id) VALUES (null)"; $querys[2] = "INSERT INTO table (id) VALUES (null)"; $querys[3] = "INSERT INTO table (id) VALUES (null)"; foreach($querys as $query => $structure){ if($result = mysql_query($structure)){ //this checks if the insert worked, if so echos to say so echo "mysql query successfull"; }else{ echo "Query failed<br />\n".mysql_error()."\n"; //otherwise it throws up an error } } mysql_close() //this closes thte connection Quote Link to comment https://forums.phpfreaks.com/topic/54505-problem-with-submission/#findComment-269620 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.