Status
Not open for further replies.

EnCiPh3r

Banned
Banned
2,499
2009
244
0
PHP:
<?php
$con = mysql_connect("localhost","MYSQL USERNAME","MYSQL PASS");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("seedvps_whm", $con);

$sql="INSERT INTO tblcustomaddon location, status, username, password, ip);
VALUES
('$_POST[location]','$_POST[status]','$_POST[username]','$_POST[password]','$_POST[ip]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con)
?>

Post
Code:
<html>

<body>



<form action="insert.php" method="post">

Location: <input type="text" name="location" />

Status: <input type="text" name="status" />

Username: <input type="text" name="username" />

Password: <input type="text" name="password" />

IP: <input type="text" name="ip" />

<input type="submit" />

</form>



</body>

</html>
Error
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 'location, status, username, password, ip) VALUES ('fr','jaja','BigBoSs','kaka'' at line 1
 
9 comments
try this out :)

PHP:
<?php
$con = mysql_connect("localhost","MYSQL USERNAME","MYSQL PASS");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("seedvps_whm", $con);

$sql="INSERT INTO tblcustomaddon (location, status, username, password, ip) VALUES ('$_POST[location]','$_POST[status]','$_POST[username]','$_POST[password]','$_POST[ip]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con)
?>
 
You just missed a '(' before location and you shouldn't add ';' before VALUES where the query is not ending yet.

Thanks man btw is there any way i can do the same script without adding my mysql user and pass information because those are already present in configuration.php (WHMCS)
 
You can use require too -> To make sure that the file is included. Else the script throws errors (in case you have them enabled). ;)
 
Status
Not open for further replies.
Back
Top