Jump to content

My MYSQL add data to MYSQL table script


winmastergames

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/89673-my-mysql-add-data-to-mysql-table-script/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.