winmastergames Posted February 6, 2008 Share Posted February 6, 2008 Your Probely Wondering why im posting alot of threads well ive got heaps of new stuff in PHP and ill make a very big website script So thats why im here Ok well online i found a way to add Data into MYSQL tables but ive edited to what i need but it doesnt work so yea here it is It just doesnt put any data into the table you need to goto script.php?user=tablenamehere for it to work <?php $swduser = $_GET["user"]; $titleadd = $_POST["titleadd"]; $sloganadd = $_POST["sloganadd"]; $con = mysql_connect("localhost","root","mypass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("swd-dbweb", $con); mysql_query("INSERT INTO $swduser (title, slogan) VALUES ('$titleadd', 'sloganadd')"); mysql_close($con); ?> <p><a href="enable.php?user=<?php echo $_GET["user"]; ?>">Enable Website Making</a> <p><a href="disable.php?user=<?php echo $_GET["user"]; ?>">Disable Website Making</a> </p> <form action="makewebsite.php" method="post"> <p>Title: <input type="text" name="titleadd" id="titleadd" /> </p> <p>Slogan: <input type="text" name="sloganadd" id="sloganadd" /> </p> <input type="submit" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/89673-my-mysql-add-data-to-mysql-table-script/ Share on other sites More sharing options...
Stooney Posted February 6, 2008 Share Posted February 6, 2008 forgot a $ mysql_query("INSERT INTO $swduser (title, slogan) VALUES ('$titleadd', '$sloganadd')"); Quote Link to comment https://forums.phpfreaks.com/topic/89673-my-mysql-add-data-to-mysql-table-script/#findComment-459506 Share on other sites More sharing options...
winmastergames Posted February 6, 2008 Author Share Posted February 6, 2008 Fixed that still doesnt work it doesnt come up with a error like T_STRING Or cannot connect to database it just doesnt put the data in there Quote Link to comment https://forums.phpfreaks.com/topic/89673-my-mysql-add-data-to-mysql-table-script/#findComment-459509 Share on other sites More sharing options...
mmarif4u Posted February 6, 2008 Share Posted February 6, 2008 Add this line: $query="INSERT INTO $swduser (title, slogan) VALUES ('$titleadd', '$sloganadd')"; $run=mysql_query($query) or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/89673-my-mysql-add-data-to-mysql-table-script/#findComment-459512 Share on other sites More sharing options...
winmastergames Posted February 6, 2008 Author Share Posted February 6, 2008 Well im not to sure how and where to add it heres the script with the code that mmarif4u said to add <?php $swduser = $_GET["user"]; $titleadd = $_POST["titleadd"]; $sloganadd = $_POST["sloganadd"]; $con = mysql_connect("localhost","root","com12345"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("swd-dbweb", $con); $query="INSERT INTO $swduser (title, slogan) VALUES ('$titleadd', '$sloganadd')"; $run=mysql_query($query) or die (mysql_error()); mysql_close($con); ?> <p><a href="enable.php?user=<?php echo $_GET["user"]; ?>">Enable Website Making</a> <p><a href="disable.php?user=<?php echo $_GET["user"]; ?>">Disable Website Making</a> </p> <form action="makewebsite.php" method="post"> <p>Title: <input type="text" name="titleadd" id="titleadd" /> </p> <p>Slogan: <input type="text" name="sloganadd" id="sloganadd" /> </p> <input type="submit" /> </form> And i get this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(title, slogan) VALUES ('ttt', 'sss')' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/89673-my-mysql-add-data-to-mysql-table-script/#findComment-459521 Share on other sites More sharing options...
Stooney Posted February 6, 2008 Share Posted February 6, 2008 echo the contents of $swduser and see if it's empty Quote Link to comment https://forums.phpfreaks.com/topic/89673-my-mysql-add-data-to-mysql-table-script/#findComment-459524 Share on other sites More sharing options...
mmarif4u Posted February 6, 2008 Share Posted February 6, 2008 R u sure $swduser is a valid table name. Quote Link to comment https://forums.phpfreaks.com/topic/89673-my-mysql-add-data-to-mysql-table-script/#findComment-459526 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.