flickman Posted November 17, 2010 Share Posted November 17, 2010 PHP code: <? //login variable $username = $_POST ['username']; $password = $_POST ['password']; $database = $_POST ['database']; //table variable $table = $_POST ['table']; //stats variables $name = $_POST ['name']; $force = $_POST ['force']; $armor = $_POST ['armor']; $strength = $_POST ['strength']; $value = $_POST ['value']; mysql_connect ("localhost","$username","$password"); @mysql_select_db ($database) or die ("no database name"); $query = "INSERT INTO `$database`.`$table` ('name', 'force', 'armor', 'strength', 'value') VALUES ('$name', '$force', '$armor', '$strength', '$value')"; mysql_query ($query); if (mysql_query($query)) { die('Error: ' . mysql_error()); } echo "1 record added<br>"; echo "<br>variable $name test"; echo "<br>variable $force test"; echo "<br>variable $armor test"; echo "<br>variable $strength test"; echo "<br>variable $value test"; mysql_close(); ?> HTML files code: <form action = "datainput.php" method = "post"> <div align="center">Item Submission Form</div><br><br> <br> <div align="center"><input type="text" name="table" value="head neck back or chest" size="32" maxlength="32"></div> <br> <br> <div align="center"><input type="text" name="name" value="Type Name Here" size="32" maxlength="32"></div> <br> <br> <div align="center"><input type="text" name="force" value="Type force number" size="32" maxlength="32"></div> <br> <br> <div align="center"><input type="text" name="armor" value="Type armor value" size="32" maxlength="32"></div> <br> <br> <div align="center"><input type="text" name="strength" value="Type strength value" size="32" maxlength="32"></div> <br> <br> <div align="center"><input type="text" name="value" value="Type cost Here" size="32" maxlength="32"></div> <br> <br> <br> <div align="center"><input type="text" name="username" value="username here" size="32" maxlength="32"></div> <br> <div align="center"><input type="text" name="password" value="password here" size="32" maxlength="32"></div> <br> <div align="center"><input type="text" name="database" value="database Here" size="32" maxlength="32"></div> <br> <div align="center"><input type="submit" name="Submit_button" value="Submit"></div> </form> What is funky is the page seems to work, it says it writes a record but the record never appears in the database. I did verify MIME types were correct for HTML to be allowed to write as php if needed, any idea why it wouldn't create a record? Link to comment https://forums.phpfreaks.com/topic/219015-creating-a-test-script-and-htm-page-not-writing-to-table/ Share on other sites More sharing options...
Psycho Posted November 17, 2010 Share Posted November 17, 2010 Two problems: One you are running the query twice. Once before the condition test and once inside the IF condition test mysql_query ($query); if (mysql_query($query)) { die('Error: ' . mysql_error()); } Second, your IF condition is backwards. The way you have, it there will only be an error message if the query successfully completes! Use this: //mysql_query ($query); if (!mysql_query($query)) { die('Error: ' . mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/219015-creating-a-test-script-and-htm-page-not-writing-to-table/#findComment-1135837 Share on other sites More sharing options...
flickman Posted November 18, 2010 Author Share Posted November 18, 2010 thanks for the response! if (!mysql_query($query)) { die('Error: ' . mysql_error()); } is the fix Link to comment https://forums.phpfreaks.com/topic/219015-creating-a-test-script-and-htm-page-not-writing-to-table/#findComment-1136047 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.