Jump to content

Another Error


ajicles

Recommended Posts

Sorry to bug you guys again but I have another 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 'like, ip_address) VALUES ('','66.79.239.225')' at line 1

 

I am trying to make a rating system for a website and I am having a very hard time trying to understand why it is not working. I have set the database column to varchar which should store the ip address and keeps returning an error.

 

Source:

<?php
$IP = $_SERVER['REMOTE_ADDR'];
$LIKE = @$_GET['like_vid'] ;

echo $IP;
echo $LIKE;


$con = mysql_connect("****","****","****");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("ajilmf_likebook");

$sql="INSERT INTO lgu(like, ip_address) VALUES ('$LIKE','$IP')";

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

?>

 

And another problem is where I am trying to use a menu to post data to another column (like). And it is not echoing back to me on the PHP side of it. And I have no idea why the html form is not working..

 

HTML Form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<form action="lgu.php" method="post">
Like This Video: 

<select name="like" size="2" id="like">
  <option value="yes" selected="selected">yes</option>
  <option value="no">no</option>
</select>

<input name="submit" type="submit" id="submit" value="Submit" />

<label for="like"></label>
</form>


</body>
</html>

 

lgu.php is the php source above.

 

All I am trying to do is record either yes or no and the ip address. I could of used a Boolean for true or false but I don't wanna get myself confused lol.

 

Thanks

    ~ AJ  :)

Link to comment
Share on other sites

For the sql error, Im thinking it could be 1 of these:

1: there should be a space between your table and your rows

2: like is a reserveed keywork, you should use quotes

 

Try

INSERT INTO lgu (`like`, `ip_address`) VALUES ('$LIKE','$IP')

 

For the form, you dont use the same vaiable name, and you have specified post in the form. Try

$LIKE = $_POST['like'];

Link to comment
Share on other sites

Thanks alot it worked :)

 

 Full Texts  	 like_video  	 ip_address	Edit 	Delete 	yes 	66.79.239.225

 

Works perfectly. Now I just go make it make a new table for each video that is posted. So its going to be a huge database, I'd say about 200-300 tables with about 2000 rows each at the most. Most likely be less than that.

 

Thanks

    ~AJ

Link to comment
Share on other sites

Well there is going to be a lot of videos in the data base and having to log each ip for each video so people can't vote more than once per video. So I though I could have a master table called video_index and the video viewing page will have a id on the end of the url like: http://mywebsite.com/video.php?id=1 and it adds the under to a variable with video_ before the number so its: video_1 and video_1 is a table and video_1 would have logged the ips of people who voted for that video.

 

~ AJ

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.