Jump to content

[SOLVED] Syntax Problems


Lee-Bartlett

Recommended Posts

Ok for some reasson, not sure why, these are basically copied from my user side of my site are messing up, the files are in the correct place and the error message im getting is, 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 'type) VALUES ('111sf','[email protected]','dsfsdf','sdfsafsad','fasdf' at line 1. But i dont know why, please help. everything is set up correct, db wise, db connection.php is fine etc

 

$sql="INSERT INTO tblbasicform (name, email, buissnes_name, location,  longitude, latitude, type)
VALUES
('$_POST[name]','$_POST[email]','$_POST[buissnes_name]','$_POST[location]','$_POST[longitude]','$_POST[latitude]','$_POST[type]')";

if (!mysql_query($sql,$connect))
  {
  die('Error: ' . mysql_error());
  }

 

<?php  require_once("includes/db_connection.php");  ?>
<?php

$sql="INSERT INTO tblbasicform (name, email, buissnes_name, location,  longitude, latitude, type)
VALUES
('$_POST[name]','$_POST[email]','$_POST[buissnes_name]','$_POST[location]','$_POST[longitude]','$_POST[latitude]','$_POST[type]')";

if (!mysql_query($sql,$connect))
  {
  die('Error: ' . mysql_error());
  }
?>

<a href="du.php">Take me back to Database.</a>

Link to comment
https://forums.phpfreaks.com/topic/128220-solved-syntax-problems/
Share on other sites

The correct syntax for putting arrays in a double-quoted string is to either do this:

echo "some string blah blah {$_POST['somevalue']} blah blah...";

or:

echo "some string blah blah ".$_POST['somevalue']." blah blah...";

 

NOT:

echo "some string blah blah $_POST[somevalue] blah blah...";

 

That was strange, must copied wrong code, the top piece of code should look like this

 

<?php


//db connection
require_once("includes/db_connection.php"); 
//end of db connection 

?>
<html>
<head>
<script type="text/javascript">
function validate_required(name,alerttxt)
{
        with (name)
        {
                if (value=="")
                {
                        alert(alerttxt);
                        return false;
                }
                else
                {
                        return true;
                }
        }
} 


function validate_required(buissnes_name,alerttxt)
{
        with (buissnes_name)
        {
                if (value=="")
                {
                        alert(alerttxt);
                        return false;
                }
                else
                {
                        return true;
                }
        }
}
function validate_required(location,alerttxt)
{
        with (location)
        {
                if (value=="")
                {
                        alert(alerttxt);
                        return false;
                }
                else
                {
                        return true;
                }
        }
}

function validate_email(email,alerttxt)
{
        with (email)
        {
                apos=value.indexOf("@");
                dotpos=value.lastIndexOf(".");
                if (apos<1||dotpos-apos<2)
                {
                        alert(alerttxt);
                        return false;
                }
                else
                {
                        return true;
                }
        }
}

function validate_form(thisform)
{
        with (thisform)
        {
                if (validate_required(email,"Email is a required field")==false)
                {
                        email.focus();
                        return false;
                }
                else if (validate_email(email,"Not a valid e-mail address!")==false)
                {
                        email.focus();
                        return false;
                }
                else if (validate_required(name,"Name is a required field")==false)
                {
                        email.focus();
                        return false;
                }
			    else if (validate_required(location,"Location is a required field")==false)
                {
                        email.focus();
                        return false;
                }
			    else if (validate_required(buissnes_name,"Buisness Name is a required field")==false)
                {
                        email.focus();
                        return false;
                }
        }
return true;
} 
function my_simple_validation (email)
{
        if (email.value == '')
        {
                alert('You must fill in required fields!');
        return false; // This is where you tell the form not to submit
        }

return true; // if we pass, submit the form
}

function valbutton(thisform) {

myOption = -1;
for (i=thisform.type.length-1; i > -1; i--) {
if (thisform.type[i].checked) {
myOption = i; i = -1;
}
}
if (myOption == -1) {
alert("You must select a radio button");
return false;
}

alert("You selected button number " + myOption
+ " which has a value of "
+ thisform.type[myOption].value);

// place any other field validations that you require here
thisform.submit(); // this line submits the form after validation
}

</script>
<?php


  
// db table connection
include("form.php"); 
//end of db table connection 
?>

</head>

<body>
<form name="form" method="post" action="includes/form.php" onSubmit="return validate_form(this);"> 


<table width="617" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#000000">
  <tr>
    <td colspan="2" bgcolor="#0099FF"><p> </p>
    <p align="center" class="style1">Nexodom.com</p>      
    <p> </p></td>
  </tr>
  <tr>
    <td width="129" height="318" align="left" valign="top"><p><a href="index.html">Home</a><br>
        <a href="wifi.php">WIFI Hot Spots</a></p>
    </td>
    <td width="482" align="left" valign="top"><p align="center">Welcome to nexodom.com</p>
    


  
  <input type="hidden" name="redirect" value="home.php"> 
  <table width="418" align="left" cellpadding="0" cellspacing="0">
    <tr>
      <td width="222"> Name:</td>
      <td width="194"><label for="name"></label>
      <input type="text" name="name" id="name"></td>
    </tr>
    <tr>
      <td>Email:</td>
      <td><label for="email"></label>
      <input type="text" name="email" id="email"></td>
    </tr>
    <tr>
      <td>WiFi Business Name:</td>
      <td><label for="buissnes_name"></label>
      <input type="text" name="buissnes_name" id="buissnes_name"></td>
    </tr>
    <tr>
      <td>WiFi Location:</td>
      <td><label for="textfield"></label>
      <input type="text" name="location" id="location"></td>
    </tr>
  <tr>
      <td>Longitude:</td>
      <td><label for="textfield"></label>
      <input type="text" name="longitude" id="longitude"></td>
    </tr>
  <tr>
      <td>Latitude:</td>
      <td><label for="textfield"></label>
      <input type="text" name="latitude" id="latitude"></td>
    </tr>
    <tr>
      <td>Free or Paid:</td>
      <td>Free<input type="radio" name="type" id="type" value="free">
      <label for="radio"></label>
      Paid<input type="radio" name="type" id="type" value="paid">
      <label for="radio2"></label></td>
    </tr>
    <tr>
      <td> </td>
      <td><label for="button"></label>
      <input type="submit" name="button" id="button" value="Submit">
      <label for="button2"></label>
      <input type="reset" name="button2" id="button2" value="Reset">       
      <label for="sub"></label></td>
    </tr>
  </table>






    
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p></td>
  </tr>
  <tr>
    <td height="20" colspan="2" bgcolor="#0099FF"> </td>
  </tr>
</table>
</form>
</body>
</html>

<?php mysql_close ?> 

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.