ueon Posted May 10, 2008 Share Posted May 10, 2008 Hello Everyone for some reason, when insert the character data into in the database table, it becomes integers (0,0,0,0,0,0) is there anything wrong with my code, which converts my character data to integers? all the integers retrieved are VARCHARS <?php include "connect.php"; //get user variables $web_namex = $_POST['web_name']; $folderx = $_POST['folder']; $image_folx = $_POST['image_fol']; $css_filex = $_POST['css_file']; $js_filex = $_POST['js_file']; $divx = $_POST['div']; //input user vars $preset_table = mysql_query(" INSERT INTO stageone ( `web_name` , `folder` , `image_fol` , `css_file` , `js_file` , `div` ) VALUES (`web_name` = '$web_namex', `folder` = '$folderx', `image_fol` = '$image_folx', `css_file` = '$css_filex', `js_file` = '$js_filex', `div` = '$divx')"); //testing input (presets) if ($preset_table) { if($div = "yes") { header("Location: http://www.webstood.com/webgen/stagetwo1.php"); } if($div = "no") { header("Location: http://www.webstood.com/webgen/stagetwo2.php"); } else { echo "Redirection failed."; } } //testing not successful else { echo "Input Error with user Vars."; } //close connection ?> Quote Link to comment https://forums.phpfreaks.com/topic/105077-inserting-characters-into-databases/ Share on other sites More sharing options...
p2grace Posted May 10, 2008 Share Posted May 10, 2008 The database is probably set to int, it needs to be set to varchar in the db Quote Link to comment https://forums.phpfreaks.com/topic/105077-inserting-characters-into-databases/#findComment-537899 Share on other sites More sharing options...
Fadion Posted May 10, 2008 Share Posted May 10, 2008 Im not sure that query works as the correct syntax of the insert statement should be: INSERT INTO stageone (web_name, folder, image_fo, css_file, js_file, div) VALUES ('$web_namex', '$folderx', '$image_folx', '$css_filex', '$js_filex', '$divx') Never tried it that way as maybe it works, but just wanted to mention it out. Quote Link to comment https://forums.phpfreaks.com/topic/105077-inserting-characters-into-databases/#findComment-537902 Share on other sites More sharing options...
ueon Posted May 12, 2008 Author Share Posted May 12, 2008 Thank you for your support - it seems that I am still having the same problem over and over again. Please look over why the data keeps on changing to integers when they're characters, thank you. HTML file <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Webgen 2.0</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <center> <b>Webgen 2.0</b><br> [stage 1] <form name="Stage One" method="post" action="stageone2.php"> <p> <input name="web_name" type="text" id="web_name" value="Website Name"> </p> <p> <input name="folder" type="text" id="folder" value="Folder Name"> </p> <p> <input name="image_fol" type="text" id="image_fol" value="Image Location"> </p> <p> <label>CSS file <select name="css_file" id="select"> <option value="0">Yes</option> <option value="1">No</option> </select> </label> </p> <p>JS File <label> <select name="js_file" id="select2"> <option value="0">Yes</option> <option value="1">No</option> </select> </label> </p> <p>Divided Layout <label> <select name="div" id="select3"> <option value="0">Yes</option> <option value="1">No</option> </select> </label> </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form> </center> </body> </html> PHP file <?php include "connect.php"; //get user variables $web_namex = $_POST['web_name']; $folderx = $_POST['folder']; $image_folx = $_POST['image_fol']; $css_filex = $_POST['css_file']; $js_filex = $_POST['js_file']; $divx = $_POST['div']; //input user vars $preset_table = mysql_query(" INSERT INTO stageone ( `web_name` , `folder` , `image_fol` , `css_file` , `js_file` , `div` ) VALUES (`web_name` = '$web_namex', `folder` = '$folderx', `image_fol` = '$image_folx', `css_file` = '$css_filex', `js_file` = '$js_filex', `div` = '$divx')"); //testing input (presets) if ($preset_table) { if($div = "yes") { header("Location: http://www.webstood.com/webgen/stagetwo1.php"); } if($div = "no") { header("Location: http://www.webstood.com/webgen/stagetwo2.php"); } else { echo "Redirection failed."; } } //testing not successful else { echo "Input Error with user Vars."; } //close connection ?> Quote Link to comment https://forums.phpfreaks.com/topic/105077-inserting-characters-into-databases/#findComment-538930 Share on other sites More sharing options...
BlueSkyIS Posted May 12, 2008 Share Posted May 12, 2008 Im not sure that query works as the correct syntax of the insert statement should be: INSERT INTO stageone (web_name, folder, image_fo, css_file, js_file, div) VALUES ('$web_namex', '$folderx', '$image_folx', '$css_filex', '$js_filex', '$divx') Never tried it that way as maybe it works, but just wanted to mention it out. Quote Link to comment https://forums.phpfreaks.com/topic/105077-inserting-characters-into-databases/#findComment-539000 Share on other sites More sharing options...
Fadion Posted May 12, 2008 Share Posted May 12, 2008 Just to be sure, i made a test with the way u wrote the query and its happening the exact thing its happening to u. Im getting 0 in varchar(10) fields. Write your query as i suggested in my previous post: $preset_table = mysql_query("INSERT INTO stageone (web_name, folder, image_fol, css_file, js_file, div) VALUES ('$web_namex', '$folderx', '$image_folx', '$css_filex', '$js_filex', '$divx')"); U dont need to respecify the columns in VALUES(). Take this example: INSERT INTO table (col1, col2, col2) VALUES (col1value, col2value, col3value) col1value corresponds to col1, col2value corresponds to col2 and so on. Quote Link to comment https://forums.phpfreaks.com/topic/105077-inserting-characters-into-databases/#findComment-539003 Share on other sites More sharing options...
ueon Posted May 12, 2008 Author Share Posted May 12, 2008 thank you, I've tried the latest suggestion that you gave but returns an input error :-\ does it work for you? Quote Link to comment https://forums.phpfreaks.com/topic/105077-inserting-characters-into-databases/#findComment-539053 Share on other sites More sharing options...
revraz Posted May 12, 2008 Share Posted May 12, 2008 Post the error and the new code. Quote Link to comment https://forums.phpfreaks.com/topic/105077-inserting-characters-into-databases/#findComment-539063 Share on other sites More sharing options...
ueon Posted May 12, 2008 Author Share Posted May 12, 2008 http://www.webstood.com/webgen/stageone1.html As you can see, it's returning an error. [stageone2.php] <?php include "connect.php"; //get user variables $web_namex = $_POST['web_name']; $folderx = $_POST['folder']; $image_folx = $_POST['image_fol']; $css_filex = $_POST['css_file']; $js_filex = $_POST['js_file']; $divx = $_POST['div']; //input user vars $preset_table = mysql_query("INSERT INTO stageone (web_name, folder, image_fol, css_file, js_file, div) VALUES ('$web_namex', '$folderx', '$image_folx', '$css_filex', '$js_filex', '$divx')"); //testing input (presets) if ($preset_table) { if($div = "yes") { header("Location: http://www.webstood.com/webgen/stagetwo1.php"); } if($div = "no") { header("Location: http://www.webstood.com/webgen/stagetwo2.php"); } else { echo "Redirection failed."; } } //testing not successful else { echo "Input Error with user Vars."; } //close connection ?> Quote Link to comment https://forums.phpfreaks.com/topic/105077-inserting-characters-into-databases/#findComment-539474 Share on other sites More sharing options...
revraz Posted May 12, 2008 Share Posted May 12, 2008 Again, post the error. Most of us won't go to your site because we troll the forums from work. http://www.webstood.com/webgen/stageone1.html As you can see, it's returning an error. Quote Link to comment https://forums.phpfreaks.com/topic/105077-inserting-characters-into-databases/#findComment-539479 Share on other sites More sharing options...
mbeals Posted May 12, 2008 Share Posted May 12, 2008 try: $preset_table = mysql_query("INSERT INTO stageone (`web_name`, `folder`, `image_fol`, `css_file`, `js_file`, `div`) VALUES ('$web_namex', '$folderx', '$image_folx', '$css_filex', '$js_filex', '$divx')"); If that fails, pull the query out of the mysql_query block and echo it out to see exactly what the query is (after the variables are parsed). Post this result. It could an unsanitary sql string (stray ; or ' in one of the variables. $query = "INSERT INTO stageone (`web_name`, `folder`, `image_fol`, `css_file`, `js_file`, `div`) VALUES ('$web_namex', '$folderx', '$image_folx', '$css_filex', '$js_filex', '$divx')"; echo $query; $preset_table = mysql_query($query); Since you are using phpmyadmin, try to generate the query like in the second block, then copy paste it into the "sql" tab in phpmyadmin. It usually does a good job of pointing out the syntax errors. Quote Link to comment https://forums.phpfreaks.com/topic/105077-inserting-characters-into-databases/#findComment-539503 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.