Jump to content

Recommended Posts

So i have a main.html page with HTML

 

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

Event Name: <input type="text" name="Event" />

<br>

Genre: <input type="text" name="Genre" />

<br>

Date: <input type="text" name="Date" />

<br>

Price: <input type="text" name="Price" />

<br>

Tickets: <input type="text" name="Tickets" />

<br>

<input type="submit" />

</form>

 

I believe this is a simple form for just inputing data but i really do have poor knowledge!

 

I then have a php page called insert.php and that page looks like so ;

 

 

<?php

$con = mysql_connect("localhost","myusername","mypassword");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("Events", $con);

 

$sql="INSERT INTO Events (Event, Genre, Date, Price, Tickets)

VALUES

('$_POST[Events]','$_POST[Genre]','$_POST[Date]')('$_POST[Price]','$_POST[Tickets]')";

 

if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

echo "1 record added";

 

mysql_close($con)

?>

 

 

 

 

And my database looks as shown below

mysqltable.png

 

 

This was meant to be a simple script to allow me to add information to the table but....i carnt get it to work despite playing around with it for ageessss could anyone help? or suggest a fresh code? its frustrating me to no end !

 

 

Thanks!

Rob

Link to comment
https://forums.phpfreaks.com/topic/190360-simple-insert-into-table-help/
Share on other sites

You have a syntax error in your query

$sql="INSERT INTO Events (Event, Genre, Date, Price, Tickets)

VALUES

('$_POST[Events]','$_POST[Genre]','$_POST[Date]')('$_POST[Price]','$_POST[Tickets]')";

The characters in red should be a comma.

 

Also you should never place raw _POST data straight into an SQL query. You should always sanitize user input.

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.